Tomodachi94

bankdoor

Jul 24th, 2026 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 bank.
  5. os.loadAPI("ocs/apis/sensor")
  6.  
  7. if not fs.exists("config") then
  8.     shell.run("pastebin", "get", "wRSpqPqJ", "config")
  9.     error("Configure the system by running 'edit config', then restart.")
  10. end
  11. local config = dofile("config")
  12.  
  13. local proximity_sensor = sensor.wrap(config.sensor_side)
  14.  
  15. os.setComputerLabel(config.hostname)
  16.  
  17. -- Prevent Ctrl+T, but save the old pullEvent to restore it in debug mode
  18. local old_pullEvent = os.pullEvent
  19. os.pullEvent = os.pullEventRaw
  20.  
  21. while true do
  22.     term.setCursorPos(1, 1)
  23.  
  24.     config.welcomeMessage()
  25.    
  26.     local do_unlock = false
  27.     for _, v in pairs(proximity_sensor.getTargets()) do
  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.  
Advertisement
Add Comment
Please, Sign In to add comment