Guest User

call

a guest
Jun 25th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. elevatorLeft = "left"
  2. elevatorRight = "right"
  3.  
  4. function checkElevators()
  5.   toCall = ""
  6.   --Left Elevator Check
  7.   orange,lime,lightBlue = 0,0,0
  8.   for i=0,2,1 do
  9.     if rs.testBundledInput(elevatorLeft, colors.orange) then
  10.       orange = orange + 1
  11.     elseif rs.testBundledInput(elevatorLeft, colors.lightBlue) then
  12.       lightBlue = lightBlue + 1
  13.     elseif rs.testBundledInput(elevatorLeft, colors.lime) then
  14.       lime = lime + 1
  15.     end
  16.     sleep(0.5)
  17.   end
  18.   if lime == 3 or lightBlue == 3 or orange == 3 then
  19.     toCall = "left"
  20.   end
  21.   --Right Elevator Check
  22.   orange,lime,lightBlue = 0,0,0
  23.   for i=0,2,1 do
  24.     if rs.testBundledInput(elevatorRight, colors.orange) then
  25.       orange = orange + 1
  26.     elseif rs.testBundledInput(elevatorRight, colors.lightBlue) then
  27.       lightBlue = lightBlue + 1
  28.     elseif rs.testBundledInput(elevatorRight, colors.lime) then
  29.       lime = lime + 1
  30.     end
  31.     sleep(0.5)
  32.   end
  33.   if lime == 3 or lightBlue == 3 or orange == 3 then
  34.     toCall = "right"
  35.   end
  36.   return toCall
  37. end
  38.  
  39. function callElevator()
  40.   if rs.testBundledInput("top", colors.white) then
  41.     print("Elevator Called to Ground Floor!")
  42.     toCall = checkElevators()
  43.     if toCall == "left" then
  44.       rs.setBundledOutput(elevatorLeft, 0)
  45.       rs.setBundledOutput(elevatorLeft, colors.white)
  46.     elseif toCall == "right" then
  47.       rs.setBundledOutput(elevatorRight, 0)
  48.       rs.setBundledOutput(elevatorRight, colors.white)
  49.     end          
  50.   elseif rs.testBundledInput("top", colors.magenta) then
  51.     print("Elevator Called to 1st Floor!")
  52.     toCall = checkElevators()
  53.     if toCall == "left" then
  54.       rs.setBundledOutput(elevatorLeft, 0)
  55.       rs.setBundledOutput(elevatorLeft, colors.magenta)
  56.     elseif toCall == "right" then
  57.       rs.setBundledOutput(elevatorRight, 0)
  58.       rs.setBundledOutput(elevatorRight, colors.magenta)
  59.     end    
  60.   elseif rs.testBundledInput("top", colors.yellow) then
  61.     print("Elevator Called to 2nd Floor!")
  62.     toCall = checkElevators()
  63.     if toCall == "left" then
  64.       rs.setBundledOutput(elevatorLeft, 0)
  65.       rs.setBundledOutput(elevatorLeft, colors.yellow)
  66.     elseif toCall == "right" then
  67.       rs.setBundledOutput(elevatorRight, 0)
  68.       rs.setBundledOutput(elevatorRight, colors.yellow)
  69.     end
  70.   end
  71. end
  72.  
  73. --Run Above
  74. while true do
  75.   local event = {os.pullEvent()}
  76.   if event[1] == "redstone" then
  77.     callElevator()
  78.   end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment