Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program controls local Security Turtles and sends them to any detected Security Threats.
- rednet.open("back")
- local ContactedID = 0
- local Sector_Protocol = -1
- local Sector_SecurityState = 0
- local ThreatX = {..}
- local ThreatY = {..}
- local ThreatZ = {..}
- local AvalibleTurtles = {..}
- local TurtleID = {..}
- local Threats = 0
- start()
- function start()
- Setup()
- SystemManager()
- end
- function SystemManager()
- repeat
- local id, message, protocol = rednet.receive()
- until protocol == Sector_Protocol and message == "Security_Turtle" or message == "Management"
- rednet.send(id, "detail", Sector_Protocol)
- ContactedID = id
- repeat
- local id, message, protocol = rednet.receive()
- until protocol == "Sector_Protocol and id == ContactedID
- if message == "Ready" then
- TurtleReady(id)
- SystemManager()
- elseif message == "Engagement Rule" then
- rednet.send(ContactedID,Sector_SecurityState,Sector_Protocol)
- SystemManager()
- elseif message == "SecurityUpdate" then
- repeat
- local id, message, protocol = rednet.receive()
- until id == ContactedID and protocol == Sector_Protocol
- if message == "Lockdown" then
- Sector_SecurityState = "Lockdown"
- elseif message == "Free" then
- Sector_SecurityState = -1
- elseif message == "ChangeAccess" then
- repeat
- local id, message, protocol = rednet.receive()
- until id == ContactedID and protocol == Sector_Protocol
- Sector_SecurityState = message
- end
- SystemManager()
- elseif message == "Threat" then
- rednet.send(ContactedID,"Cords",Sector_Protocol)
- repeat
- local id, message, protocol
- until id == ContactedID and protocol == Sector_Protocol
- local Threat = message
- ThreatX[#ThreatX] = Threat[1]
- ThreatY[#ThreatY] = Threat[2]
- ThreatZ[#ThreatZ] = Threat[3]
- Threats = Threats + 1
- FindTurtle()
- end
- end
- function TurtleReady(id)
- local file = fs.open("Turtles","r")
- for i = 1, #AvalibleTurtles do
- if file.readLine(i) == id then
- AvalibleTurtles[i] = true
- end
- end
- end
- function FindTurtle()
- for I = 1, #Threats do
- for i = 1, #AvalibleTurtles do
- if AvalibleTurtles[i] == true then
- AvalibleTurtles[i] = false
- rednet.send(TurtleID[i],{..ThreatX[I]..","....ThreatY[I]..","....ThreatZ[I]..},Sector_Protocol)
- I = I + 1
- end
- end
- end
- Threats = 0
- ThreatX = {..}
- ThreatY = {..}
- ThreatZ = {..}
- SystemManager()
- end
- function Setup()
- local file = fs.open("Turtles","r")
- for i = 1, #file.list() do
- TurtleID[i] = file.readLine(i)
- AvalibleTurtles[i] = true
- end
- file.flush()
- file = fs.open("System","r")
- Sector_Protocol = file.readLine(1)
- Sector_SecurityState = file.readLine(2)
- file.close()
- end
Add Comment
Please, Sign In to add comment