Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program detects a player named "s3ptum" within a 6-block radius
- -- using an Advanced Peripherals Player Detector. If the player is present,
- -- it sends a redstone signal to the back of the computer.
- -- Define the player's name and the detection radius.
- local targetPlayer = "s3ptum"
- local detectionRadius = 6
- -- Main program loop.
- while true do
- -- Connect to the player detector on the "right" side.
- local playerDetector = peripheral.wrap("right")
- -- Check if the player detector was successfully found.
- if not playerDetector then
- print("Error: Player detector not found on the 'right' side.")
- print("Please ensure the block is correctly placed.")
- sleep(5)
- goto continueLoop
- end
- -- Get a list of all players within the specified range.
- local players = playerDetector.getPlayersInRange(detectionRadius)
- -- Clear the screen and print the players table for debugging.
- term.clear()
- term.setCursorPos(1,1)
- print(players)
- sleep(2)
- local playerFound = false
- -- Loop through the list of players to check for our target.
- for _, player in ipairs(players) do
- if player and player.name == targetPlayer then
- playerFound = true
- break -- Stop the loop as soon as the player is found.
- end
- end
- -- Set the redstone signal based on whether the player was found.
- if playerFound then
- rs.setOutput("back", true)
- print("Player '" .. targetPlayer .. "' detected. Redstone ON.")
- else
- rs.setOutput("back", false)
- print("Player '" .. targetPlayer .. "' not detected. Redstone OFF.")
- end
- -- Wait for a short time before checking again to avoid performance issues.
- sleep(0.5)
- ::continueLoop::
- end
Advertisement
Add Comment
Please, Sign In to add comment