Advertisement
Mercyrocket

Player Detector for ComupterCraft (CraftOS 1.8)

May 29th, 2023
1,261
2
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 2 0
  1. --Programm to be used with CraftOS 1.8+ and a "Player Detector" from the mod "Advanced Peripherals"
  2.  
  3. local detector  = peripheral.find("playerDetector") --finds and gives the Player Detector an "address"
  4. local range = 3 --Change this value to the number of blocks you wish to detect the player (centre is the Player Detector)
  5.  
  6. function detectorCheck() --This checks if the Player Detector is coneected to the sytstem.
  7.  
  8. if detector == nil then
  9.  print("Player detector not attached.")
  10.   else
  11.   term.write("Player detector block connected. ")
  12.   print(detector)
  13.   end
  14. end
  15.  
  16. --main code  
  17. detectorCheck()
  18.  
  19. if detector == nil then
  20.  sleep(1)
  21.  print("Terminating program...")
  22.  sleep(1)
  23.  error()  
  24.   else
  25.   print("Redstone output set to 'back'")
  26. end  
  27.  
  28. while true do
  29.  
  30. local inRange = detector.isPlayersInRange(range)
  31. local prevInRange = false
  32. local day = os.day()
  33. local time = os.time()
  34.  
  35.  
  36.     if inRange == true then
  37.         term.write("Day "..day.." @ ")
  38.         term.write(time..": ")
  39.         print("Player detected.")
  40.        
  41.         while inRange == true do
  42.             redstone.setAnalogOutput("back",15)
  43.             sleep(0.5)
  44.             inRange = detector.isPlayersInRange(range)            
  45.         end
  46.     end
  47.    
  48.     if inRange == false then
  49.         term.write("Day "..day.." @ ")
  50.         term.write(time..": ")
  51.         print("Player no longer detected.")
  52.        
  53.         while inRange == false do
  54.             redstone.setAnalogOutput("back",0)
  55.             sleep(0.5)
  56.             inRange = detector.isPlayersInRange(range)
  57.         end
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement