ashtons

CC:Tweaked/Create Elevator Control

May 19th, 2021 (edited)
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. -- Elevator Control Program
  2. -- Meant to be used in Minecraft with the ComputerCraft and Create mods
  3.  
  4. locationLighthouse = false  -- If true, the elevator is in the lighthouse.
  5. locationLobby = false       -- If true, the elevator is in the lobby.
  6. locationMoving = false      -- If true, the elevator is moving.
  7.  
  8. -- Top:     In-Elevator Toggle Button (Redstone Link)
  9. -- Bottom:  Gearshift
  10. -- Left:    Lighthouse Call Button (Redstone Link)
  11. -- Right:   Lobby Call Button (Redstone Link)
  12. -- Front:   Lighthouse Redstone Contact (Redstone Link)
  13. -- Back:    Lobby Redstone Contact (Redstone Link)
  14.  
  15. print("ELEVATOR CONTROL PROGRAM")
  16.  
  17. while true do
  18.    
  19.     local event = os.pullEventRaw()
  20.  
  21.     if event == "terminate" then
  22.         print("Alrighty, going into maintenance mode!")
  23.         reboot()
  24.     elseif event == "redstone" then
  25.         print("Caught redstone event!")
  26.     else
  27.         os.pullEvent("redstone") -- wait until we get a redstone event
  28.     end
  29.  
  30.     if locationMoving == true then
  31.         if rs.getInput("front") == true then
  32.             sleep(30)   -- Ensure that all elevator passengers have time to exit the elevator
  33.             locationMoving = false
  34.             locationLighthouse = true
  35.         elseif rs.getInput("back") == true then
  36.             sleep(30)   -- Ensure that all elevator passengers have time to exit the elevator
  37.             locationMoving = false
  38.             locationLobby = true
  39.         end
  40.     else
  41.         if rs.getInput("left") == true then
  42.             if locationLobby == true then
  43.                 locationMoving = true
  44.                 locationLobby = false
  45.                 rs.setOutput("bottom", not rs.getOutput("bottom"))
  46.             end
  47.         elseif rs.getInput("right") == true then
  48.             if locationLighthouse == true then
  49.                 locationMoving = true
  50.                 locationLighthouse = false
  51.                 rs.setOutput("bottom", not rs.getOutput("bottom"))
  52.             end
  53.         elseif rs.getInput("top") == true then
  54.             if locationLighthouse == true then
  55.                 locationMoving = true
  56.                 locationLighthouse = false
  57.             elseif locationLobby == true then
  58.                 locationMoving = true
  59.                 locationLobby = false
  60.             end
  61.             rs.setOutput("bottom", not rs.getOutput("bottom"))
  62.         end
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment