Marlingaming

CC Tweaked Facility Security Manager

Feb 25th, 2022 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. local SecState = 0
  2. local Open = false
  3. local AllowVisitors = false
  4. local Aggression = 0--0 = no aggressive actions allowed, 1 = can give warnings, 2 = can attack if in defense, 3 = attack on sight
  5. local Manager = 0
  6. local Sections = {}
  7. local Bots = {}
  8. peripheral.find("modem",rednet.open)
  9.  
  10. function CheckBotIds(id)
  11. local R = false
  12. for i = 1, #Bots do
  13. if Bots[i][1] == id then R = true end
  14. end
  15. return R
  16. end
  17.  
  18. function Respond(player,Am)
  19. Sent = 0
  20. local S = {"Engage",player,Aggression}
  21. local Data = textutils.serialize(S,{compact = true})
  22. for i = 1, #Bots do
  23. if Sent < Am and Bots[i][2] == true then
  24. Sent = Sent + 1
  25. rednet.send(Bots[i][1],Data)
  26. Bots[i][2] = false
  27. end
  28. end
  29. end
  30.  
  31. function SecurityUpdate()
  32. if SecState == 0 then
  33. rednet.broadcast("shutdown")
  34. elseif SecState > 0 then
  35. if SecState == 1 then
  36. Aggression = 2
  37. elseif SecState == 2 then
  38. Aggression = 3
  39. elseif SecState == 3 then
  40. Aggression = 4
  41. end
  42. if Open == true then
  43. AllowVisitors = true
  44. Aggression = Aggression - 1
  45. elseif Open == false then
  46. AllowVisitors = false
  47. end
  48. if Aggression == 0 then Aggression = 1 elseif Aggression == 4 then Aggression = 3 end
  49. end
  50. end
  51.  
  52. function ManageBot(id,action)
  53. local I
  54. for i = 1, #Bots do
  55. if Bots[i][1] == id then I = i end
  56. end
  57. if action == "Standby" then
  58. Bots[I][2] = true
  59. end
  60. end
  61.  
  62. function ManageSection(Action,a,b,c)
  63. local ID = Section[a][1]
  64. if Action == "status" then
  65. rednet.send(ID,"status")
  66. return (rednet.receive())
  67. elseif Action == "Close" then
  68. rednet.send(ID,"close")
  69. elseif Action == "Open" then
  70. rednet.send(ID,"close")
  71. elseif Action == "Scan" then
  72. rednet.send(ID,"scan")
  73. local id, message
  74. repeat
  75. id, message = rednet.receive()
  76. until id == ID
  77. if message == 0 then--clear
  78.  
  79. elseif message == 1 then--on alert
  80.  
  81. elseif message == 2 then--Emergency
  82.  
  83. elseif message == 3 then--no longer able to control area
  84.  
  85. end
  86. end
  87. end
  88.  
  89. function CheckSections(ID)
  90. local R = false
  91. for i = 1, #Sections do
  92. if Sections[i][1] == ID then R == true end
  93. end
  94. return R
  95. end
  96.  
  97. function Loop()
  98. localnDir
  99. while true do
  100. local id, message = rednet.receive()
  101. if id == Manager then
  102. if message == "Off" then
  103. SecState = 0
  104. elseif message == "Open" then
  105. Open = true
  106. elseif message == "Close" then
  107. Open = false
  108. elseif message == "Lockdown" then
  109. SecState = 3
  110. end
  111. elseif CheckSections(id) == true then
  112. Dir = textutils.unserialize(message)
  113. if Dir[1] == "event" then
  114. if Dir[2] == "threat" then
  115. Response(Dir[3],Dir[4],Dir[5],2)
  116. end
  117. elseif Dir[1] == "low" then
  118.  
  119. elseif Dir[1] == "disabled" then
  120. Sections[Dir[2]][2] = false
  121. Aggression = Aggression + 1
  122. end
  123. elseif CheckBotIds(id) == true then
  124. Dir = textutils.unserialize(message)
  125. if Dir[1] == "standby" then
  126. ManageBot(id,"Standby")
  127. elseif Dir[1] == "event" then
  128. Respond(Dir[2],Dir[3],Dir[4],2)
  129. end
  130. end
  131. SecurityUpdate()
  132. end
  133. end
  134.  
  135. Loop()
Add Comment
Please, Sign In to add comment