Advertisement
BigBlow_

redstonePulseExtender

Mar 27th, 2025 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. -- playerDetectorDoor --
  2. -- https://pastebin.com/tKfbvZT2 --
  3. -- CONFIGURATION --
  4. local detectionRange = 4 -- Detection range in blocks
  5. local redstoneDuration = 2 -- Duration (in seconds) for redstone signal
  6. local invertMode = true -- Invert redstone signal: true = always on, off when player detected
  7. local redstoneSide = "bottom" -- Side where redstone is emitted
  8.  
  9. -- FINDING THE PLAYER DETECTOR AUTOMATICALLY --
  10. local detector = nil
  11. for _, name in ipairs(peripheral.getNames()) do
  12. if peripheral.getType(name) == "playerDetector" then
  13. detector = peripheral.wrap(name)
  14. break
  15. end
  16. end
  17.  
  18. if not detector then
  19. print("No player detector found!")
  20. return
  21. end
  22.  
  23. print("Player detector found on " .. peripheral.getName(detector))
  24. print("Monitoring for players...")
  25.  
  26. -- MAIN LOOP --
  27. while true do
  28. local players = detector.getPlayersInRange(detectionRange)
  29. local playerDetected = #players > 0
  30.  
  31. if invertMode then
  32. redstone.setOutput(redstoneSide, not playerDetected)
  33. else
  34. redstone.setOutput(redstoneSide, playerDetected)
  35. end
  36.  
  37. if playerDetected then
  38. sleep(redstoneDuration)
  39. redstone.setOutput(redstoneSide, invertMode) -- Reset output after duration
  40. end
  41.  
  42. sleep(0.01) -- Short delay to prevent excessive CPU usage
  43. end
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement