Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SecState = 0
- local Open = false
- local AllowVisitors = false
- local Aggression = 0--0 = no aggressive actions allowed, 1 = can give warnings, 2 = can attack if in defense, 3 = attack on sight
- local Manager = 0
- local Sections = {}
- local Bots = {}
- peripheral.find("modem",rednet.open)
- function CheckBotIds(id)
- local R = false
- for i = 1, #Bots do
- if Bots[i][1] == id then R = true end
- end
- return R
- end
- function Respond(player,Am)
- Sent = 0
- local S = {"Engage",player,Aggression}
- local Data = textutils.serialize(S,{compact = true})
- for i = 1, #Bots do
- if Sent < Am and Bots[i][2] == true then
- Sent = Sent + 1
- rednet.send(Bots[i][1],Data)
- Bots[i][2] = false
- end
- end
- end
- function SecurityUpdate()
- if SecState == 0 then
- rednet.broadcast("shutdown")
- elseif SecState > 0 then
- if SecState == 1 then
- Aggression = 2
- elseif SecState == 2 then
- Aggression = 3
- elseif SecState == 3 then
- Aggression = 4
- end
- if Open == true then
- AllowVisitors = true
- Aggression = Aggression - 1
- elseif Open == false then
- AllowVisitors = false
- end
- if Aggression == 0 then Aggression = 1 elseif Aggression == 4 then Aggression = 3 end
- end
- end
- function ManageBot(id,action)
- local I
- for i = 1, #Bots do
- if Bots[i][1] == id then I = i end
- end
- if action == "Standby" then
- Bots[I][2] = true
- end
- end
- function ManageSection(Action,a,b,c)
- local ID = Section[a][1]
- if Action == "status" then
- rednet.send(ID,"status")
- return (rednet.receive())
- elseif Action == "Close" then
- rednet.send(ID,"close")
- elseif Action == "Open" then
- rednet.send(ID,"close")
- elseif Action == "Scan" then
- rednet.send(ID,"scan")
- local id, message
- repeat
- id, message = rednet.receive()
- until id == ID
- if message == 0 then--clear
- elseif message == 1 then--on alert
- elseif message == 2 then--Emergency
- elseif message == 3 then--no longer able to control area
- end
- end
- end
- function CheckSections(ID)
- local R = false
- for i = 1, #Sections do
- if Sections[i][1] == ID then R == true end
- end
- return R
- end
- function Loop()
- localnDir
- while true do
- local id, message = rednet.receive()
- if id == Manager then
- if message == "Off" then
- SecState = 0
- elseif message == "Open" then
- Open = true
- elseif message == "Close" then
- Open = false
- elseif message == "Lockdown" then
- SecState = 3
- end
- elseif CheckSections(id) == true then
- Dir = textutils.unserialize(message)
- if Dir[1] == "event" then
- if Dir[2] == "threat" then
- Response(Dir[3],Dir[4],Dir[5],2)
- end
- elseif Dir[1] == "low" then
- elseif Dir[1] == "disabled" then
- Sections[Dir[2]][2] = false
- Aggression = Aggression + 1
- end
- elseif CheckBotIds(id) == true then
- Dir = textutils.unserialize(message)
- if Dir[1] == "standby" then
- ManageBot(id,"Standby")
- elseif Dir[1] == "event" then
- Respond(Dir[2],Dir[3],Dir[4],2)
- end
- end
- SecurityUpdate()
- end
- end
- Loop()
Add Comment
Please, Sign In to add comment