Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor")
- local xMax, yMax = mon.getSize()
- os.loadAPI("radar")
- os.loadAPI("button")
- rednet.open("top")
- local roomLeft = "2"
- local roomRight = "4"
- local roomData = {[roomLeft] = "",
- [roomRight] = ""}
- local bundleSide = "right"
- function fillButtons()
- button.setTable(roomLeft, openLeftDoor, 1, 1, 2, 2)
- button.setTable(roomRight, openRightDoor, xMax, xMax, 2, 2)
- end
- function load()
- if not fs.exists("roomdata") then
- return
- end
- local file = fs.open("roomdata", "r")
- local data = textutils.unserialize(file.readAll())
- roomData = data
- file.close()
- print("loading room data")
- end
- function save()
- local file = fs.open("roomdata", "w")
- file.write(textutils.serialize(roomData))
- file.close()
- print("save data")
- end
- function waitForInstruction()
- id, msg = rednet.receive("hotel")
- print(msg["room"] .. " " .. msg["player"])
- if msg["room"] == roomLeft then
- if msg["command"] == "checkin" then
- roomData[roomLeft] = msg["player"]
- elseif msg["command"] == "checkout" then
- roomData[roomLeft] = ""
- end
- save()
- end
- if msg["room"] == roomRight then
- if msg["command"] == "checkin" then
- roomData[roomRight] = msg["player"]
- elseif msg["command"] == "checkout" then
- roomData[roomRight] = ""
- end
- save()
- end
- waitForInstruction()
- end
- function openRightDoor()
- if radar.findClosest() == roomData[roomRight] then
- redstone.setBundledOutput(bundleSide, colors.blue)
- sleep(3)
- redstone.setBundledOutput(bundleSide, 0)
- end
- end
- function openLeftDoor()
- if radar.findClosest() == roomData[roomLeft] then
- redstone.setBundledOutput(bundleSide, colors.white)
- sleep(3)
- redstone.setBundledOutput(bundleSide, 0)
- end
- end
- function checkClick()
- event, side, x, y = os.pullEvent("monitor_touch")
- button.checkxy(x,y)
- end
- --button.heading("ROOMS")
- load()
- rednet.open("top")
- mon.clear()
- mon.setCursorPos(1, 1)
- button.heading("ROOMS")
- fillButtons()
- button.screen()
- function run()
- while true do
- checkClick()
- end
- end
- --waitForInstruction()
- parallel.waitForAll(run, waitForInstruction)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement