pandorrama

Stargate_shield

Mar 14th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local component = require("component")
  2. local radar = component.radar
  3.  
  4. local ShieldStatus = true
  5. local whitelist = {"pandorrama","kat3nemar"}
  6. local distance = 5
  7.  
  8. local function detectPlayer()
  9.   local scan = radar.getPlayers()
  10.   if not scan[1] then
  11.     return("nobodyThere")
  12.   else
  13.     if scan[1].distance < distance then
  14.       return(scan[1].name)
  15.     else
  16.       return("toFarAway")
  17.     end
  18.   end
  19.   os.sleep(1)
  20. end
  21.  
  22. local function checkAuthority(player)
  23.   if player == "toFarAway" or player == "nobodyThere" then
  24. --    print("no player in range")
  25.   else
  26. --    print("checking authorisation")
  27.     for index, value in pairs(whitelist) do
  28.       if value == player then
  29.         return("GRANTED")
  30.       end
  31.     end
  32.   end
  33. end
  34.  
  35. local function shieldControl()
  36.   if ShieldStatus == true then
  37.     ShieldStatus = false
  38.     robot.useUp()
  39.     return("deactivating")
  40.   else
  41.     ShieldStatus = true
  42.     robot.useUp()
  43.     return("activating")
  44.   end
  45. end
  46.  
  47. while true do
  48.   local player = detectPlayer()
  49.   local authorized = checkAuthority(player)
  50.   if authorized == "GRANTED" and ShieldStatus == true then
  51.     shieldControl()
  52.     print("Grant access to player "..player)
  53.   elseif player == "nobodyThere" and ShieldStatus == false then
  54.     shieldControl()
  55.     print("There is currently no player in range")
  56.   elseif player == "toFarAway" and ShieldStatus == false then
  57.     shieldControl()
  58.     print("Player is to far away")
  59.   elseif authorized == nil and ShieldStatus == false then
  60.     shieldControl()
  61.     print("Player "..player.." is not allowed to pass")
  62.   end
  63.  
  64.   os.sleep(.5)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment