SHOW:
|
|
- or go back to the newest paste.
| 1 | -- SPDX-FileCopyrightText: 2026 Tomodachi94 | |
| 2 | -- SPDX-License-Identifier: MIT | |
| 3 | -- A door that unlocks when an authorized user is nearby. | |
| 4 | - | -- Contains messages specific to the Stargazer Lounge. |
| 4 | + | -- Contains messages specific to the bank. |
| 5 | os.loadAPI("ocs/apis/sensor")
| |
| 6 | - | local proximity_sensor = sensor.wrap("bottom")
|
| 6 | + | |
| 7 | if not fs.exists("config") then
| |
| 8 | - | local config = {}
|
| 8 | + | shell.run("pastebin", "get", "wRSpqPqJ", "config")
|
| 9 | error("Configure the system by running 'edit config', then restart.")
| |
| 10 | - | config.authorized = {}
|
| 10 | + | |
| 11 | - | config.authorized["Tomodachi94"] = true |
| 11 | + | local config = dofile("config")
|
| 12 | - | config.authorized["Rolcam"] = true |
| 12 | + | |
| 13 | - | config.authorized["GleefulLasahs"] = true |
| 13 | + | local proximity_sensor = sensor.wrap(config.sensor_side) |
| 14 | ||
| 15 | - | config.unlock_side = "right" |
| 15 | + | os.setComputerLabel(config.hostname) |
| 16 | - | config.debug_side = "back" |
| 16 | + | |
| 17 | - | config.sensor_side = "bottom" |
| 17 | + | -- Prevent Ctrl+T, but save the old pullEvent to restore it in debug mode |
| 18 | - | config.hostname = "stargazerstaffdoor" |
| 18 | + | local old_pullEvent = os.pullEvent |
| 19 | os.pullEvent = os.pullEventRaw | |
| 20 | - | function config.welcomeMessage() |
| 20 | + | |
| 21 | while true do | |
| 22 | - | term.setTextColor(colors.purple) |
| 22 | + | |
| 23 | - | term.write("Stargazer Lounge")
|
| 23 | + | |
| 24 | - | term.setTextColor(colors.red) |
| 24 | + | config.welcomeMessage() |
| 25 | - | term.write(" staff only beyond this point.")
|
| 25 | + | |
| 26 | local do_unlock = false | |
| 27 | for _, v in pairs(proximity_sensor.getTargets()) do | |
| 28 | - | return config |
| 28 | + | if |
| 29 | config.authorized[v.Username] | |
| 30 | -- Use math.abs to check if the user is in a specific radius | |
| 31 | and math.abs(v.Position.X) <= 3 | |
| 32 | and math.abs(v.Position.Z) <= 3 | |
| 33 | and math.abs(v.Position.Y) <= 2 | |
| 34 | then | |
| 35 | do_unlock = true | |
| 36 | end | |
| 37 | ||
| 38 | if do_unlock then | |
| 39 | term.setCursorPos(1, 10) | |
| 40 | term.setTextColor(colors.green) | |
| 41 | term.write("Welcome, " .. v.Username)
| |
| 42 | redstone.setOutput(config.unlock_side, true) | |
| 43 | sleep(3) | |
| 44 | else | |
| 45 | redstone.setOutput(config.unlock_side, false) | |
| 46 | end | |
| 47 | local _, terminal_height = term.getSize() | |
| 48 | for i = 2, terminal_height do | |
| 49 | term.setCursorPos(1, i) | |
| 50 | term.clearLine() | |
| 51 | end | |
| 52 | end | |
| 53 | -- Debug mode | |
| 54 | if redstone.getInput(config.debug_side) then | |
| 55 | term.setCursorPos(1, 10) | |
| 56 | print("Entering debug mode, exiting...")
| |
| 57 | os.pullEvent = old_pullEvent | |
| 58 | break | |
| 59 | end | |
| 60 | end | |
| 61 |