Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local radar, currentSecond, lastInput = peripheral.wrap('radar_0'), 0, 0
- function initiate()
- while true do
- loop()
- currentSecond = currentSecond + 1
- sleep(1)
- end
- end
- function loop()
- -- Every 2 Seconds to reduce amount of sensor calls and potentially limit lag
- if ( currentSecond % 1 == 0 ) then
- -- Probe Sensors
- print('starting second')
- local isInside
- print('checking radar')
- local players = radar.getPlayers()
- if ( type(players) ~= 'table' ) then
- return
- end
- for index, player in ipairs(players) do
- if ( player.distance < 5.5 ) then
- print('found player '..player.name)
- isInside = true
- end
- end
- local power = (isInside and 0 or math.random(5,15))
- print('ended radar')
- print('setting state of output to '..tostring(not isInside))
- if ( lastInput ~= isInside ) then
- term.setCursorBlink(true)
- rs.setAnalogOutput('right', power)
- term.setCursorBlink(false)
- print('completed state change '..tostring(not isInside)..':'..tostring(rs.getOutput('right')))
- lastInput = isInside
- end
- term.setCursorBlink(not isInside)
- end
- end
- initiate()
Advertisement
Add Comment
Please, Sign In to add comment