s3ptum

Untitled

Sep 8th, 2025
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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. -- Clear the screen and print the players table for debugging.
  26. term.clear()
  27. term.setCursorPos(1,1)
  28. print(players)
  29. sleep(2)
  30.  
  31. local playerFound = false
  32. -- Loop through the list of players to check for our target.
  33. for _, player in ipairs(players) do
  34. if player and player.name == targetPlayer then
  35. playerFound = true
  36. break -- Stop the loop as soon as the player is found.
  37. end
  38. end
  39.  
  40. -- Set the redstone signal based on whether the player was found.
  41. if playerFound then
  42. rs.setOutput("back", true)
  43. print("Player '" .. targetPlayer .. "' detected. Redstone ON.")
  44. else
  45. rs.setOutput("back", false)
  46. print("Player '" .. targetPlayer .. "' not detected. Redstone OFF.")
  47. end
  48.  
  49. -- Wait for a short time before checking again to avoid performance issues.
  50. sleep(0.5)
  51.  
  52. ::continueLoop::
  53. end
Advertisement
Add Comment
Please, Sign In to add comment