local detector = peripheral.find("player_detector") local doorSide = "back" local range = 10 -- Updated to 10 blocks as requested -- Table to keep track of who is currently in range local activePlayers = {} term.clear() term.setCursorPos(1,1) print("=== EVIL DOOR SECURITY SYSTEM ===") if not detector then print("STATUS: ERROR - Detector not found!") return end print("STATUS: INITIALIZING...") print("RANGE: " .. range .. " blocks") sleep(1) -- Helper function to check if a name is in a list local function isNameInList(name, list) for _, value in ipairs(list) do if value == name then return true end end return false end while true do -- Get the current list of players within range local detectedNow = detector.getPlayersInRange(range) local timestamp = "[" .. textutils.formatTime(os.time(), true) .. "] " -- 1. Check for NEW players (Entered) for _, name in ipairs(detectedNow) do if not isNameInList(name, activePlayers) then print(timestamp .. "ENTERED: " .. name) table.insert(activePlayers, name) end end -- 2. Check for players who LEFT for i = #activePlayers, 1, -1 do local name = activePlayers[i] if not isNameInList(name, detectedNow) then print(timestamp .. "LEFT: " .. name) table.remove(activePlayers, i) end end -- 3. Door Control Logic if #activePlayers > 0 then -- Someone is here! Keep the door open. if redstone.getOutput(doorSide) == false then redstone.setOutput(doorSide, true) print("STATUS: SECURE ACCESS GRANTED") end else -- Area is empty. Close the door. if redstone.getOutput(doorSide) == true then redstone.setOutput(doorSide, false) print("STATUS: AREA CLEAR - LOCKING DOWN") end end sleep(0.5) -- Fast enough to catch sprinters, slow enough to prevent lag end