dlord

/cc/doorcontrol

Nov 1st, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --   Copyright 2012 John Paul Alcala
  2. --
  3. --   Licensed under the Apache License, Version 2.0 (the "License");
  4. --   you may not use this file except in compliance with the License.
  5. --   You may obtain a copy of the License at
  6. --
  7. --       http://www.apache.org/licenses/LICENSE-2.0
  8. --
  9. --   Unless required by applicable law or agreed to in writing, software
  10. --   distributed under the License is distributed on an "AS IS" BASIS,
  11. --   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. --   See the License for the specific language governing permissions and
  13. --   limitations under the License.
  14.  
  15. local args = { ... }
  16.  
  17. local entranceHatchOpen=colors.blue
  18. local entranceHatchClose=colors.red
  19. local exitHatchOpen=colors.green
  20. local exitHatchClose=colors.yellow
  21.  
  22. local controlDoor = function(op)
  23.   for i=1,2 do
  24.     redstone.setBundledOutput("top", op)
  25.     sleep(0.100)
  26.     redstone.setBundledOutput("top", 0)
  27.     sleep(0.900)
  28.   end
  29. end
  30.  
  31. local openEntranceHatch = function()
  32.   if redstone.testBundledInput("top", entranceHatchClose) then
  33.     controlDoor(entranceHatchOpen)
  34.   else
  35.     print("Entrance Hatch already opened!")
  36.   end
  37. end
  38.  
  39. local closeEntranceHatch = function()
  40.   if redstone.testBundledInput("top", entranceHatchClose) ~= true then
  41.     controlDoor(entranceHatchClose)
  42.   else
  43.     print("Entrance Hatch already closed!")
  44.   end
  45. end
  46.  
  47. local openExitHatch = function()
  48.   if redstone.testBundledInput("top", exitHatchClose) then
  49.     controlDoor(exitHatchOpen)
  50.   else
  51.     print("Entrance Hatch already opened!")
  52.   end
  53. end
  54.  
  55. local closeExitHatch = function()
  56.   if redstone.testBundledInput("top", exitHatchClose) ~= true then
  57.     controlDoor(exitHatchClose)
  58.   else
  59.     print("Entrance Hatch already closed!")
  60.   end
  61. end
  62.  
  63.  
  64. local checkArguments = function()
  65.   local action = args[1]
  66.   local doorType = args[2]
  67.  
  68.   if action == "open" then
  69.     if doorType == "entrance" then
  70.       print("Opening Entrance Hatch")
  71.       openEntranceHatch()
  72.     elseif doorType == "exit" then
  73.       print("Opening Exit Hatch")
  74.       openExitHatch()
  75.     end
  76.   elseif action == "close" then
  77.     if doorType == "entrance" then
  78.       print("Closing Entrance Hatch")
  79.       closeEntranceHatch()
  80.     elseif doorType == "exit" then
  81.       print("Closing Exit Hatch")
  82.       closeExitHatch()
  83.     end
  84.   end
  85. end
  86.  
  87. -- check arguments
  88.  
  89. if #args > 1 then
  90.   checkArguments()
  91. else
  92.   print("doorcontrol [open/close] [entrance/exit]")
  93. end
Advertisement
Add Comment
Please, Sign In to add comment