s3ptum

Untitled

Sep 8th, 2025 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 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. -- Function to sanitize and normalize a string for comparison.
  10. -- It converts to lowercase and trims whitespace.
  11. local function sanitizeName(name)
  12. if not name then return "" end
  13. return string.lower(string.gsub(name, "^%s*(.-)%s*$", "%1"))
  14. end
  15.  
  16. -- Main program loop.
  17. while true do
  18. -- Connect to the player detector on the "right" side.
  19. local playerDetector = peripheral.wrap("right")
  20.  
  21. -- Check if the player detector was successfully found.
  22. if not playerDetector then
  23. print("Error: Player detector not found on the 'right' side.")
  24. print("Please ensure the block is correctly placed.")
  25. sleep(5)
  26. goto continueLoop
  27. end
  28.  
  29. -- Get a list of all players within the specified range.
  30. local players = playerDetector.getPlayersInRange(detectionRadius)
  31.  
  32. local playerFound = false
  33. -- Loop through the list of players to check for our target.
  34. for _, player in ipairs(players) do
  35. if player and player.name then
  36. local sanitizedDetectedName = sanitizeName(player.name)
  37. local sanitizedTargetName = sanitizeName(targetPlayer)
  38.  
  39. if sanitizedDetectedName == sanitizedTargetName then
  40. playerFound = true
  41. break -- Stop the loop as soon as the player is found.
  42. end
  43. end
  44. end
  45.  
  46. -- Set the redstone signal based on whether the player was found.
  47. if playerFound then
  48. rs.setOutput("back", true)
  49. print("Player '" .. targetPlayer .. "' detected. Redstone ON.")
  50. else
  51. rs.setOutput("back", false)
  52. print("Player '" .. targetPlayer .. "' not detected. Redstone OFF.")
  53. end
  54.  
  55. -- Wait for a short time before checking again to avoid performance issues.
  56. sleep(0.5)
  57.  
  58. ::continueLoop::
  59. end
  60.  
Advertisement
Add Comment
Please, Sign In to add comment