Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local thisFloor = os.getComputerLabel()
- local elevatorSide = "right"
- local elevatorIsAt = nil
- local m = peripheral.find "monitor"
- rednet.open "back"
- local floors = {
- "Botania",
- "Entry Room",
- "Floor 0",
- "Floor 1",
- "Floor 2",
- "Floor 3",
- "Powergen",
- "Floor 5",
- "ME Core",
- "Floor 7",
- "Floor 8",
- "Floor 9",
- "Floor 10",
- "Floor 11",
- "Floor 12",
- "Floor 12+1",
- "Viewing Deck"
- }
- function call(floor)
- rednet.broadcast(floor, "elevator_goto")
- end
- function listenRednet()
- while true do
- local _, msg = rednet.receive "elevator_goto"
- if msg == thisFloor then
- --pulse(elevatorSide) -- this calls the elevator
- print "Calling elevator here!"
- redstone.setOutput(elevatorSide, true)
- else
- print("Elevator called to", msg)
- redstone.setOutput(elevatorSide, false) -- when elevator is called somewhere else, stop redstone
- end
- elevatorIsAt = msg
- os.queueEvent "refresh"
- end
- end
- function writeBG(term, txt, bg)
- local w = term.getSize()
- term.setBackgroundColor(bg)
- term.write(txt .. string.rep(" ", w - #txt))
- end
- function display()
- while true do
- m.setCursorPos(1, 1)
- m.setTextColor(colors.black)
- m.setBackgroundColor(colors.black)
- m.setTextScale(0.75)
- m.clear()
- -- Write out all the floor names
- for n, floorName in pairs(floors) do
- m.setCursorPos(1, n)
- local col = colors.white
- -- Give this floor a lime background
- if floorName == thisFloor then
- col = colors.lime
- end
- -- Highlight elevator's current floor
- if floorName == elevatorIsAt then
- col = colors.lightBlue
- end
- writeBG(m, floorName, col)
- end
- os.pullEvent "refresh"
- end
- end
- function listenMonitorTouch()
- while true do
- local _, side, x, y = os.pullEvent "monitor_touch"
- print(x, y)
- local floor = floors[y]
- if floor then
- print(floor)
- call(floor)
- elevatorIsAt = floor
- os.queueEvent "refresh"
- end
- end
- end
- function listenReboot()
- while true do
- local _, msg = rednet.receive "elevator_command"
- if msg == "reboot" then
- os.reboot()
- end
- end
- end
- parallel.waitForAll(display, listenRednet, listenMonitorTouch, listenReboot)
Add Comment
Please, Sign In to add comment