s3ptum

check players

Sep 8th, 2025 (edited)
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. -- This program detects a player named "s3ptum" within a 6-block radius
  2. -- using an Advanced Peripherals Player Detector. If the player is present,
  3. -- it sends a redstone signal to the back of the computer.
  4.  
  5. -- Define the player's name and the detection radius.
  6. local targetPlayer = "s3ptum"
  7. local detectionRadius = 6
  8.  
  9. -- Main program loop.
  10. while true do
  11. -- Connect to the player detector on the "right" side.
  12. local playerDetector = peripheral.wrap("right")
  13.  
  14. -- Check if the player detector was successfully found.
  15. if not playerDetector then
  16. print("Error: Player detector not found on the 'right' side.")
  17. print("Please ensure the block is correctly placed.")
  18. sleep(5)
  19. goto continueLoop
  20. end
  21.  
  22. -- Get a list of all players within the specified range.
  23. local players = playerDetector.getPlayersInRange(detectionRadius)
  24.  
  25. local playerFound = false
  26. -- Loop through the list of players to check for our target.
  27. for _, player in ipairs(players) do
  28. if player and player.name == targetPlayer then
  29. playerFound = true
  30. break -- Stop the loop as soon as the player is found.
  31. end
  32. end
  33.  
  34. -- Set the redstone signal based on whether the player was found.
  35. if playerFound then
  36. rs.setOutput("back", true)
  37. print("Player '" .. targetPlayer .. "' detected. Redstone ON.")
  38. else
  39. rs.setOutput("back", false)
  40. print("Player '" .. targetPlayer .. "' not detected. Redstone OFF.")
  41. end
  42.  
  43. -- Wait for a short time before checking again to avoid performance issues.
  44. sleep(0.5)
  45.  
  46. ::continueLoop::
  47. end
  48.  
Advertisement
Add Comment
Please, Sign In to add comment