Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open "top"
- local radar = peripheral.find "radar"
- local side = "right"
- local onoff = false
- local admin = "gollark"
- local alreadyHandledTrespass = false
- local banned = {
- "demhydraz",
- "Terrariola"
- }
- function speak(msg)
- rednet.broadcast({"GTech Base Defense System: ID " .. os.getComputerID(), msg}, "chat_announce")
- end
- function checkTrespassers(radarOutput)
- for _, data in pairs(radarOutput) do
- for _, bannedName in pairs(banned) do
- if data.name == bannedName then
- return true, bannedName
- end
- end
- end
- return false
- end
- function set()
- redstone.setOutput(side, onoff)
- end
- function scanNearby()
- while true do
- local players = radar.getPlayers()
- local trespassersExist, name = checkTrespassers(players)
- if trespassersExist then
- print "Trespass detected"
- if not alreadyHandledTrespass then
- speak "TRESPASSER DETECTED. Coil engaged."
- if name then
- speak("Go away, " .. name .. ".")
- if name == "nagoL2015" then
- speak "Dark Lords are not welcome here, dank or not."
- end
- end
- alreadyHandledTrespass = true
- end
- onoff = true
- else
- if alreadyHandledTrespass then
- onoff = false
- end
- alreadyHandledTrespass = false
- end
- set()
- sleep(1)
- end
- end
- function controlCoil()
- while true do
- local _, raw = rednet.receive "chat_message"
- local msg, usr = raw[2], raw[1]
- local cmd = string.sub(msg or "", 2) -- msg is somehow nil sometimes
- print(usr, msg, cmd)
- if usr == admin then
- if cmd == "toggle" then
- onoff = not onoff
- speak("Message acknowledged. Coil set to: " .. tostring(onoff) .. ".")
- set()
- elseif cmd == "reboot" then
- speak "Rebooting..."
- os.reboot()
- end
- end
- end
- end
- speak "System ready."
- parallel.waitForAll(controlCoil, scanNearby)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement