Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local radar = component.radar
- local ShieldStatus = true
- local whitelist = {"pandorrama","kat3nemar"}
- local distance = 5
- local function detectPlayer()
- local scan = radar.getPlayers()
- if not scan[1] then
- return("nobodyThere")
- else
- if scan[1].distance < distance then
- return(scan[1].name)
- else
- return("toFarAway")
- end
- end
- os.sleep(1)
- end
- local function checkAuthority(player)
- if player == "toFarAway" or player == "nobodyThere" then
- -- print("no player in range")
- else
- -- print("checking authorisation")
- for index, value in pairs(whitelist) do
- if value == player then
- return("GRANTED")
- end
- end
- end
- end
- local function shieldControl()
- if ShieldStatus == true then
- ShieldStatus = false
- robot.useUp()
- return("deactivating")
- else
- ShieldStatus = true
- robot.useUp()
- return("activating")
- end
- end
- while true do
- local player = detectPlayer()
- local authorized = checkAuthority(player)
- if authorized == "GRANTED" and ShieldStatus == true then
- shieldControl()
- print("Grant access to player "..player)
- elseif player == "nobodyThere" and ShieldStatus == false then
- shieldControl()
- print("There is currently no player in range")
- elseif player == "toFarAway" and ShieldStatus == false then
- shieldControl()
- print("Player is to far away")
- elseif authorized == nil and ShieldStatus == false then
- shieldControl()
- print("Player "..player.." is not allowed to pass")
- end
- os.sleep(.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment