SHOW:
|
|
- or go back to the newest paste.
| 1 | local mon = peripheral.find("monitor")
| |
| 2 | local xMax, yMax = mon.getSize() | |
| 3 | ||
| 4 | os.loadAPI("radar")
| |
| 5 | os.loadAPI("button")
| |
| 6 | rednet.open("top")
| |
| 7 | local roomLeft = "2" | |
| 8 | local roomRight = "4" | |
| 9 | ||
| 10 | local roomData = {[roomLeft] = "",
| |
| 11 | [roomRight] = ""} | |
| 12 | local bundleSide = "right" | |
| 13 | ||
| 14 | function fillButtons() | |
| 15 | button.setTable(roomLeft, openLeftDoor, 1, 1, 2, 2) | |
| 16 | button.setTable(roomRight, openRightDoor, xMax, xMax, 2, 2) | |
| 17 | end | |
| 18 | ||
| 19 | function load() | |
| 20 | if not fs.exists("roomdata") then
| |
| 21 | return | |
| 22 | end | |
| 23 | local file = fs.open("roomdata", "r")
| |
| 24 | local data = textutils.unserialize(file.readAll()) | |
| 25 | roomData = data | |
| 26 | file.close() | |
| 27 | print("loading room data")
| |
| 28 | end | |
| 29 | ||
| 30 | function save() | |
| 31 | local file = fs.open("roomdata", "w")
| |
| 32 | file.write(textutils.serialize(roomData)) | |
| 33 | file.close() | |
| 34 | print("save data")
| |
| 35 | end | |
| 36 | ||
| 37 | function waitForInstruction() | |
| 38 | id, msg = rednet.receive("hotel")
| |
| 39 | print(msg["room"] .. " " .. msg["player"]) | |
| 40 | ||
| 41 | if msg["room"] == roomLeft then | |
| 42 | if msg["command"] == "checkin" then | |
| 43 | roomData[roomLeft] = msg["player"] | |
| 44 | elseif msg["command"] == "checkout" then | |
| 45 | roomData[roomLeft] = "" | |
| 46 | end | |
| 47 | save() | |
| 48 | end | |
| 49 | ||
| 50 | if msg["room"] == roomRight then | |
| 51 | if msg["command"] == "checkin" then | |
| 52 | roomData[roomRight] = msg["player"] | |
| 53 | elseif msg["command"] == "checkout" then | |
| 54 | roomData[roomRight] = "" | |
| 55 | end | |
| 56 | save() | |
| 57 | end | |
| 58 | ||
| 59 | waitForInstruction() | |
| 60 | end | |
| 61 | ||
| 62 | function openRightDoor() | |
| 63 | if radar.findClosest() == roomData[roomRight] then | |
| 64 | redstone.setBundledOutput(bundleSide, colors.blue) | |
| 65 | sleep(3) | |
| 66 | redstone.setBundledOutput(bundleSide, 0) | |
| 67 | end | |
| 68 | end | |
| 69 | ||
| 70 | function openLeftDoor() | |
| 71 | if radar.findClosest() == roomData[roomLeft] then | |
| 72 | redstone.setBundledOutput(bundleSide, colors.white) | |
| 73 | sleep(3) | |
| 74 | redstone.setBundledOutput(bundleSide, 0) | |
| 75 | end | |
| 76 | end | |
| 77 | ||
| 78 | function checkClick() | |
| 79 | event, side, x, y = os.pullEvent("monitor_touch")
| |
| 80 | button.checkxy(x,y) | |
| 81 | end | |
| 82 | ||
| 83 | --button.heading("ROOMS")
| |
| 84 | ||
| 85 | load() | |
| 86 | rednet.open("top")
| |
| 87 | ||
| 88 | mon.clear() | |
| 89 | mon.setCursorPos(1, 1) | |
| 90 | ||
| 91 | button.heading("ROOMS")
| |
| 92 | fillButtons() | |
| 93 | button.screen() | |
| 94 | ||
| 95 | function run() | |
| 96 | while true do | |
| 97 | checkClick() | |
| 98 | end | |
| 99 | end | |
| 100 | --waitForInstruction() | |
| 101 | parallel.waitForAll(run, waitForInstruction) |