Advertisement
oGoOgO

eeprom_Player_Detector.lua

Jun 3rd, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. local setOutput = component.proxy(component.list("redstone")()).setOutput
  2. local getPlayers = component.proxy(component.list("radar")()).getPlayers
  3.  
  4. function os.sleep(timeout)
  5. local deadline = computer.uptime() + (timeout or 0)
  6. repeat
  7. computer.pullSignal(deadline - computer.uptime())
  8. until computer.uptime() >= deadline
  9. end
  10.  
  11. local isActive = false
  12. local OUTPUT_SIDE = 1
  13.  
  14. local function scan()
  15. local scanResult = getPlayers()
  16. for i = 1, #scanResult do
  17. if scanResult[i].distance <= 4 then
  18. return true
  19. end
  20. end
  21. return false
  22. end
  23.  
  24. while true do
  25. os.sleep(2)
  26. local scanResult = scan()
  27.  
  28. if not isActive and scanResult then
  29. setOutput(OUTPUT_SIDE, 15)
  30. isActive = true
  31. elseif isActive and not scanResult then
  32. setOutput(OUTPUT_SIDE, 0)
  33. isActive = false
  34. end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement