Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Programm to be used with CraftOS 1.8+ and a "Player Detector" from the mod "Advanced Peripherals"
- local detector = peripheral.find("playerDetector") --finds and gives the Player Detector an "address"
- local range = 3 --Change this value to the number of blocks you wish to detect the player (centre is the Player Detector)
- function detectorCheck() --This checks if the Player Detector is coneected to the sytstem.
- if detector == nil then
- print("Player detector not attached.")
- else
- term.write("Player detector block connected. ")
- print(detector)
- end
- end
- --main code
- detectorCheck()
- if detector == nil then
- sleep(1)
- print("Terminating program...")
- sleep(1)
- error()
- else
- print("Redstone output set to 'back'")
- end
- while true do
- local inRange = detector.isPlayersInRange(range)
- local prevInRange = false
- local day = os.day()
- local time = os.time()
- if inRange == true then
- term.write("Day "..day.." @ ")
- term.write(time..": ")
- print("Player detected.")
- while inRange == true do
- redstone.setAnalogOutput("back",15)
- sleep(0.5)
- inRange = detector.isPlayersInRange(range)
- end
- end
- if inRange == false then
- term.write("Day "..day.." @ ")
- term.write(time..": ")
- print("Player no longer detected.")
- while inRange == false do
- redstone.setAnalogOutput("back",0)
- sleep(0.5)
- inRange = detector.isPlayersInRange(range)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement