Advertisement
osmarks

Radoor

Nov 9th, 2019
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local authorized = {"gollark", "Sascha_T", "Ale32bit"}
  2. local door = "left"
  3. local radar = peripheral.find "radar"
  4. local monitor = peripheral.find "monitor"
  5. local scan_distance, open_distance = 12, 3
  6. monitor.setTextScale(0.5)
  7.  
  8. local auth_map = {}
  9. for _, v in pairs(authorized) do auth_map[v] = true end
  10.  
  11. term.redirect(monitor)
  12. local was_open = false
  13.  
  14. local function timestamp()
  15.     return os.date "!%X"
  16. end
  17.  
  18. while true do
  19.     local players = radar.getPlayers(scan_distance)
  20.     local open, player, others = false, nil, {}
  21.     for _, p in pairs(players) do
  22.         if not player and auth_map[p.name] and p.distance < open_distance then
  23.             open = true
  24.             player = p.name
  25.         else
  26.             table.insert(others, p.name)
  27.         end
  28.     end
  29.     local others = table.concat(others, " ")
  30.     if open and not was_open then
  31.         local extra_text = ""
  32.         if others ~= "" then
  33.             extra_text = "+ " .. others
  34.         end
  35.         print(timestamp(), player, extra_text)
  36.     end
  37.     rs.setOutput(door, open)
  38.     was_open = open
  39.     sleep(0.2)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement