csmit195

Untitled

Jul 6th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. local radars = {'radar_0', 'radar_2'}
  2. local currentSecond = 0
  3. local rsDoorSide = 'back'
  4. local allowedVisitors = { 'csmit195', 'YorickNL', 'blackfiredesigns' }
  5.  
  6. function initiate()
  7.     local newRadars = {}
  8.     for _, radar in ipairs(radars) do
  9.         newRadars[_] = peripheral.wrap(radar)
  10.     end
  11.     radars = newRadars
  12.     while true do
  13.         loop()
  14.         currentSecond = currentSecond + 1
  15.         sleep(1)
  16.     end
  17. end
  18.  
  19. function loop()
  20.     -- Every 2 Seconds to reduce amount of sensor calls and potentially limit lag
  21.     if ( currentSecond % 2 == 0 ) then
  22.         -- Probe Sensors
  23.         local isVerified
  24.         for _, radar in ipairs(radars) do
  25.             for index, player in ipairs(radar.getPlayers()) do
  26.                 for __, whitelistedPlayer in ipairs(allowedVisitors) do
  27.                     if ( player.name == whitelistedPlayer ) then
  28.                         setDoorState(true)
  29.                         isVerified = true
  30.                     end
  31.                 end
  32.             end
  33.         end
  34.         if ( not isVerified ) then
  35.             setDoorState(false)
  36.         end
  37.     end
  38. end
  39.  
  40. function setDoorState(state)
  41.     rs.setOutput(rsDoorSide, state)
  42. end
  43.  
  44. initiate()
Advertisement
Add Comment
Please, Sign In to add comment