Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sensorSide = "right"
- local rsOutput = "top"
- local privatePlayers = {"1lann", "Oeed", "joebodo"}
- local y = {2, 5}
- local x = {-5, 4}
- local z = {-3, 4}
- local lastToggleTime = false
- local privateOutput = false
- local publicOutuput = false
- local sensor = peripheral.wrap(sensorSide)
- local function setOutput(state, private)
- if state and not lastToggleTime then
- lastToggleTime = os.clock()
- end
- if private then
- privateOutput = state
- else
- publicOutuput = state
- end
- if not(privateOutput or publicOutuput) and lastToggleTime and os.clock()-lastToggleTime > 1 then
- lastToggleTime = false
- rs.setOutput(rsOutput, not(privateOutput or publicOutuput))
- elseif (privateOutput or publicOutuput) then
- rs.setOutput(rsOutput, not(privateOutput or publicOutuput))
- end
- end
- local function everyone()
- while sleep(1) or true do
- local players = sensor.getPlayerNames()
- local playerNearby = false
- for _,name in pairs(players) do
- local player = sensor.getPlayerData(name)
- local position = player.position
- if position and position.x > x[1] and position.x < x[2] and
- position.y > y[1] and position.y < y[2] and
- position.z > z[1] and position.z < z[2] then
- playerNearby = true
- end
- end
- setOutput(playerNearby, false)
- end
- end
- local function private()
- while sleep(0.1) or true do
- local playerNearby = false
- for _,name in pairs(privatePlayers) do
- local player = sensor.getPlayerData(name)
- if player then
- local position = player.position
- local lookingAt = player.lookingAt
- if position and position.x > x[1] and position.x < x[2] and
- position.y > y[1] and position.y < y[2] and
- position.z > z[1] and position.z < z[2] then
- playerNearby = true
- elseif lookingAt and lookingAt.x > x[1] and lookingAt.x < x[2] and
- lookingAt.y > y[1] and lookingAt.y < y[2] and
- lookingAt.z > z[1] and lookingAt.z < z[2] then
- playerNearby = true
- end
- end
- end
- setOutput(playerNearby, true)
- end
- end
- while true do
- local state, msg = pcall(parallel.waitForAny, private, everyone)
- if not state and msg:find("Terminate") then
- print("Terminated.")
- return
- elseif not state then
- print(msg)
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement