Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local suppression_distance = 20
- local sensor_side = "top"
- local alarm_side = "right"
- local timeout = 60 * 10
- local cnt_trolled = 0
- local cnt_suppressed = 0
- local function is_player_in_range()
- local prox = peripheral.wrap(sensor_side)
- if prox == nil then
- fatal("Sensor not found")
- end
- for k,target in pairs(prox.getTargets()) do
- if target.IsPlayer then
- local sqrt = math.sqrt
- local pow = math.pow
- local player = target.Position
- local distance = sqrt(
- pow(player.X, 2) +
- pow(player.Z, 2)
- )
- if distance < 20 then
- return true
- end
- end
- end
- return false
- end
- local function on()
- redstone.setOutput(alarm_side, true)
- end
- local function off()
- redstone.setOutput(alarm_side, false)
- end
- local function alarm()
- on()
- os.sleep(1)
- off()
- end
- local function inc_troll_cnt()
- cnt_trolled = cnt_trolled + 1
- end
- local function inc_suppr_cnt()
- cnt_suppressed = cnt_suppressed + 1
- end
- local function print_stats()
- term.clear()
- term.setCursorPos(1,1)
- print('We trolled ' .. tostring(cnt_trolled) ..
- ' times and needed to suppress ' .. tostring(cnt_suppressed) ..
- ' times.')
- end
- local function troll()
- if not is_player_in_range() then
- inc_troll_cnt()
- alarm()
- else
- inc_suppr_cnt()
- end
- print_stats()
- end
- while true do
- troll()
- os.sleep(timeout)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement