Marlingaming

SectorSecurity Manager

Sep 13th, 2021 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. --this program controls local Security Turtles and sends them to any detected Security Threats.
  2. rednet.open("back")
  3. local ContactedID = 0
  4. local Sector_Protocol = -1
  5. local Sector_SecurityState = 0
  6. local ThreatX = {..}
  7. local ThreatY = {..}
  8. local ThreatZ = {..}
  9. local AvalibleTurtles = {..}
  10. local TurtleID = {..}
  11. local Threats = 0
  12.  
  13. start()
  14.  
  15. function start()
  16. Setup()
  17. SystemManager()
  18. end
  19.  
  20. function SystemManager()
  21. repeat
  22. local id, message, protocol = rednet.receive()
  23. until protocol == Sector_Protocol and message == "Security_Turtle" or message == "Management"
  24. rednet.send(id, "detail", Sector_Protocol)
  25. ContactedID = id
  26. repeat
  27. local id, message, protocol = rednet.receive()
  28. until protocol == "Sector_Protocol and id == ContactedID
  29. if message == "Ready" then
  30. TurtleReady(id)
  31. SystemManager()
  32. elseif message == "Engagement Rule" then
  33. rednet.send(ContactedID,Sector_SecurityState,Sector_Protocol)
  34. SystemManager()
  35. elseif message == "SecurityUpdate" then
  36. repeat
  37. local id, message, protocol = rednet.receive()
  38. until id == ContactedID and protocol == Sector_Protocol
  39. if message == "Lockdown" then
  40. Sector_SecurityState = "Lockdown"
  41. elseif message == "Free" then
  42. Sector_SecurityState = -1
  43. elseif message == "ChangeAccess" then
  44. repeat
  45. local id, message, protocol = rednet.receive()
  46. until id == ContactedID and protocol == Sector_Protocol
  47. Sector_SecurityState = message
  48. end
  49. SystemManager()
  50. elseif message == "Threat" then
  51. rednet.send(ContactedID,"Cords",Sector_Protocol)
  52. repeat
  53. local id, message, protocol
  54. until id == ContactedID and protocol == Sector_Protocol
  55. local Threat = message
  56. ThreatX[#ThreatX] = Threat[1]
  57. ThreatY[#ThreatY] = Threat[2]
  58. ThreatZ[#ThreatZ] = Threat[3]
  59. Threats = Threats + 1
  60. FindTurtle()
  61. end
  62. end
  63.  
  64. function TurtleReady(id)
  65. local file = fs.open("Turtles","r")
  66. for i = 1, #AvalibleTurtles do
  67. if file.readLine(i) == id then
  68. AvalibleTurtles[i] = true
  69. end
  70. end
  71. end
  72.  
  73. function FindTurtle()
  74. for I = 1, #Threats do
  75. for i = 1, #AvalibleTurtles do
  76. if AvalibleTurtles[i] == true then
  77. AvalibleTurtles[i] = false
  78. rednet.send(TurtleID[i],{..ThreatX[I]..","....ThreatY[I]..","....ThreatZ[I]..},Sector_Protocol)
  79. I = I + 1
  80. end
  81. end
  82. end
  83. Threats = 0
  84. ThreatX = {..}
  85. ThreatY = {..}
  86. ThreatZ = {..}
  87. SystemManager()
  88. end
  89.  
  90. function Setup()
  91. local file = fs.open("Turtles","r")
  92. for i = 1, #file.list() do
  93. TurtleID[i] = file.readLine(i)
  94. AvalibleTurtles[i] = true
  95. end
  96. file.flush()
  97. file = fs.open("System","r")
  98. Sector_Protocol = file.readLine(1)
  99. Sector_SecurityState = file.readLine(2)
  100. file.close()
  101. end
Add Comment
Please, Sign In to add comment