Guest User

doorcontrol

a guest
Nov 1st, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local entranceHatchOpen=colors.blue
  4. local entranceHatchClose=colors.red
  5. local exitHatchOpen=colors.green
  6. local exitHatchClose=colors.yellow
  7.  
  8. local controlDoor = function(op)
  9.   for i=1,2 do
  10.     redstone.setBundledOutput("top", op)
  11.     sleep(0.100)
  12.     redstone.setBundledOutput("top", 0)
  13.     sleep(0.900)
  14.   end
  15. end
  16.  
  17. local openEntranceHatch = function()
  18.   if redstone.testBundledInput("top", entranceHatchClose) then
  19.     controlDoor(entranceHatchOpen)
  20.   else
  21.     print("Entrance Hatch already opened!")
  22.   end
  23. end
  24.  
  25. local closeEntranceHatch = function()
  26.   if redstone.testBundledInput("top", entranceHatchClose) ~= true then
  27.     controlDoor(entranceHatchClose)
  28.   else
  29.     print("Entrance Hatch already closed!")
  30.   end
  31. end
  32.  
  33. local openExitHatch = function()
  34.   if redstone.testBundledInput("top", exitHatchClose) then
  35.     controlDoor(exitHatchOpen)
  36.   else
  37.     print("Entrance Hatch already opened!")
  38.   end
  39. end
  40.  
  41. local closeExitHatch = function()
  42.   if redstone.testBundledInput("top", exitHatchClose) ~= true then
  43.     controlDoor(exitHatchClose)
  44.   else
  45.     print("Entrance Hatch already closed!")
  46.   end
  47. end
  48.  
  49.  
  50. local checkArguments = function()
  51.   local action = tArgs[1]
  52.   local doorType = tArgs[2]
  53.  
  54.   if action == "open" then
  55.     if doorType == "entrance" then
  56.       print("Opening Entrance Hatch")
  57.       openEntranceHatch()
  58.     elseif doorType == "exit" then
  59.       print("Opening Exit Hatch")
  60.       openExitHatch()
  61.     end
  62.   elseif action == "close" then
  63.     if doorType == "entrance" then
  64.       print("Closing Entrance Hatch")
  65.       closeEntranceHatch()
  66.     elseif doorType == "exit" then
  67.       print("Closing Exit Hatch")
  68.       closeExitHatch()
  69.     end
  70.   end
  71. end
  72.  
  73. -- check arguments
  74.  
  75. if #tArgs > 1 then
  76.   checkArguments()
  77. else
  78.   print("doorcontrol [open/close] [entrance/exit]")
  79. end
Advertisement
Add Comment
Please, Sign In to add comment