Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- floor = 11
- rednet.open("back")
- serverID = 78
- floortable = {[1]="2", [2]="1", [3]="0", [4]="-1", [5]="-2", [6]="-3", [7]="-4", [8]="-5", [9]="-6", [10]="-7", [11]="-8"}
- banana = true
- function gui()
- local w,h = term.getSize()
- local function printCentered(str, ypos)
- term.setCursorPos(w/2 - #str/2, ypos)
- term.write(str)
- end
- local function printRight(str, ypos)
- term.setCursorPos(w - #str, ypos)
- term.write(str)
- end
- function drawHeader()
- printCentered("ELEVATOR CONTROL", 1)
- printCentered(string.rep("-", w), 2)
- term.setCursorPos(1, 3)
- term.write("Current floor: ")
- term.write(floor)
- end
- function drawMain()
- term.setCursorPos(1,4)
- term.write("| 2 : balcony")
- term.setCursorPos(1,5)
- term.write("| 1 : 1st floor")
- term.setCursorPos(1,6)
- term.write("| 0 : lobby")
- term.setCursorPos(1,7)
- term.write("| -1: ")
- term.setCursorPos(1,8)
- term.write("| -2: ")
- term.setCursorPos(1,9)
- term.write("| -3: ")
- term.setCursorPos(26,4)
- term.write("| -4: ")
- term.setCursorPos(26,5)
- term.write("| -5: Train station")
- term.setCursorPos(26,6)
- term.write("| -6: ")
- term.setCursorPos(26,7)
- term.write("| -7: ")
- term.setCursorPos(26,8)
- term.write("| -8: ")
- term.setCursorPos(4,11)
- term.write("Please enter destination floor: ")
- end
- drawHeader()
- drawMain()
- term.setCursorPos(42,11)
- end
- function listen()
- while true do
- local sendID, obj, distance = rednet.receive()
- if sendID == serverID then
- if obj >= floor then
- rs.setOutput("bottom", true)
- else
- rs.setOutput("bottom", false)
- end
- end
- end
- end
- function call()
- while true do
- if rs.getInput("left") == true then
- rednet.send(serverID, "call")
- end
- end
- end
- function input()
- while true do
- local input = read()
- if input == "quit" then
- banana = false
- shell.quit()
- end
- for k,v in pairs(floortable) do
- if v == input then
- rednet.send(serverID, k)
- else
- term.setCursorPos(4,12)
- term.write("Invalid floor number")
- end
- end
- end
- end
- function finish()
- if rs.getInput("right") == true then
- shell.exit()
- end
- end
- while banana == true do
- gui()
- parallel.waitForAny(listen, call, input, finish)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement