Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SPDX-FileCopyrightText: 2026 Tomodachi94
- -- SPDX-License-Identifier: MIT
- -- A door that unlocks when an authorized user is nearby.
- -- Contains messages specific to the bank.
- os.loadAPI("ocs/apis/sensor")
- if not fs.exists("config") then
- shell.run("pastebin", "get", "wRSpqPqJ", "config")
- error("Configure the system by running 'edit config', then restart.")
- end
- local config = dofile("config")
- local proximity_sensor = sensor.wrap(config.sensor_side)
- os.setComputerLabel(config.hostname)
- -- Prevent Ctrl+T, but save the old pullEvent to restore it in debug mode
- local old_pullEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- while true do
- term.setCursorPos(1, 1)
- config.welcomeMessage()
- local do_unlock = false
- for _, v in pairs(proximity_sensor.getTargets()) do
- if
- config.authorized[v.Username]
- -- Use math.abs to check if the user is in a specific radius
- and math.abs(v.Position.X) <= 3
- and math.abs(v.Position.Z) <= 3
- and math.abs(v.Position.Y) <= 2
- then
- do_unlock = true
- end
- if do_unlock then
- term.setCursorPos(1, 10)
- term.setTextColor(colors.green)
- term.write("Welcome, " .. v.Username)
- redstone.setOutput(config.unlock_side, true)
- sleep(3)
- else
- redstone.setOutput(config.unlock_side, false)
- end
- local _, terminal_height = term.getSize()
- for i = 2, terminal_height do
- term.setCursorPos(1, i)
- term.clearLine()
- end
- end
- -- Debug mode
- if redstone.getInput(config.debug_side) then
- term.setCursorPos(1, 10)
- print("Entering debug mode, exiting...")
- os.pullEvent = old_pullEvent
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment