local dfpwm = require("cc.audio.dfpwm") local speaker = peripheral.find("speaker") local monitor = peripheral.find("monitor") local chat = peripheral.find("chatBox") local detector = peripheral.find("playerDetector") local distance = 20 local target = "OROURKEIRE" --local target = "devplayer0" function klaxon() local decoder = dfpwm.make_decoder() for chunk in io.lines("data/danger.dfpwm", 16 * 1024) do local buffer = decoder(chunk) while not speaker.playAudio(buffer) do os.pullEvent("speaker_audio_empty") end end end function showWarning() monitor.clear() monitor.setTextScale(2) --[[local w, h = monitor.getSize() local tw = string.len("WARNING") for i = 1, 3 do monitor.setCursorPos(w/2 - tw/2, (h/3)*i) monitor.write("WARNING") end]] monitor.setCursorPos(8, 3) monitor.write("WARNING") monitor.setCursorPos(8, 5) monitor.write("WARNING") monitor.setCursorPos(8, 8) monitor.write("WARNING") end function broadcastWarning() local msg = { {text = "WARNING", color = "red"}, {text = ": Kevin is ", color = "white"}, {text = "IN THE BASE", color = "yellow"}, {text = "!"}, } local msgJSON = textutils.serializeJSON(msg) chat.sendFormattedMessage(msgJSON) end while true do if detector.isPlayerInRange(25, target) then showWarning() broadcastWarning() klaxon() else monitor.clear() end sleep(1) end