Advertisement
Marlingaming

Facility Management System Base Program

Sep 17th, 2021 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --Facility Manager Base
  3. --this program is the base file for the Facility Management System.
  4. --this program is for minecraft 1.16.5, CC Tweaked
  5. --Facility Related Variables
  6. local Facility_NightShift = 22
  7. local Facility_DayShift = 6
  8. local Facility_SecurityState = 0
  9. local Facility_DEFCON = 5
  10. local Facility_Personal = {..}
  11. local Facility_PersonalSensors = 0
  12. --Protocols
  13. local Facility_SecurityProtocol = 5555
  14. --Security Related Variables
  15. local Security_IncreaseState = "g2sxts"
  16. local Security_DecreaseState = "og37fs"
  17. --Access
  18. local ACCESS_Testing = true
  19. local ACCESS_Security = true
  20. local ACCESS_Manufactoring = true
  21. local ACCESS_EmergencyServices = true
  22. local ACCESS_DEFCON = false
  23. local ACCESS_Lockdown = true
  24. --Emergency Variables
  25. local EFM = 0
  26. local ENP = 0
  27.  
  28.  
  29. rednet.open("back")
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. function start()
  37. if fs.exists("SystemData") == false then
  38. SaveData()
  39. else
  40. LoadData()
  41. end
  42. if Facility_SecurityState == 5 then
  43. LOCKED()
  44. else
  45. MainHandler()
  46. end
  47. end
  48.  
  49. function MainHandler()
  50. rednet.host(0,"FacilityManager")
  51. while true do
  52. local event, Item = os.pullEvent()
  53. local id, message, protocol = rednet.receive()
  54. if event ~= nil then
  55. if event == "key" then
  56. if Item == keys.enter then
  57. UserInterface()
  58. break
  59. end
  60. else
  61.  
  62. end
  63. elseif id ~= nil then
  64. if protocol == Facility_SecurityProtocol and ACCESS_Security == true then
  65. if message == Security_IncreaseState then
  66. Facility_SecurityState = Facility_SecurityState + 1
  67. elseif message == Security_DecreaseState then
  68. Facility_SecurityState = Facility_SecurityState - 1
  69. end
  70. if Facility_SecurityState > 5 then
  71. Facility_SecurityState = 5
  72. elseif Facility_SecurityState < 0 then
  73. Facility_SecurityState = 0
  74. end
  75. else
  76.  
  77. end
  78. else
  79. if Facility_SecurityState < 3 then
  80. local h = os.time("ingame")
  81. if h >= Facility_NightShift or h < Facility_DayShift then
  82. FacilityState("Night")
  83. elseif h >= Facility_DayShift then
  84. FacilityState("Day")
  85. end
  86. elseif Faciltiy_SecurityState < 5 and ACCESS_EmergencyServices == true then
  87. MartialLaw()
  88. elseif Facility_SecurityState == 5 ACCESS_Lockdown == true then
  89. CompleteLockdown()
  90. break
  91. end
  92. end
  93. SaveData()
  94. end
  95. end
  96.  
  97. function FacilityState(State)
  98. rednet.broadcast(0432,State)
  99. end
  100.  
  101. function GetPresentPersonal()
  102. rednet.broadcast(8532,"FindPersonal")
  103. local I = 1
  104. while I < Facility_PersonalSensors do
  105. local id, message, protocol = rednet.receive()
  106. Facility_Personal[#Facility_Personal+1] = message
  107. I = I + 1
  108. end
  109. end
  110.  
  111. function NetworkHandler(Network,Message)
  112. local Protocol = 0
  113. if Network == "Testing" and ACCESS_Testing == true then
  114. Protocol == 0
  115. elseif Network == "Security" and ACCESS_Security == true then
  116. Protocol == 0
  117. elseif Network == "Logistics" and ACCESS_Manufactoring == true then
  118. Protocol == 0
  119. elseif Network == "SubjectManagement" then
  120. Protocol == 0
  121. elseif Network == "Colonies" then
  122. Protocol == 0
  123. elseif Network == "Diplomacy" then
  124. Protocol == 0
  125. elseif Network == "ExpansionAreas" then
  126. Protocol == 0
  127. end
  128. rednet.broadcast(Protocol,Message)
  129. end
  130.  
  131. function SaveData()
  132. local file = fs.open("SystemData","w")
  133. file.writeLine(Facility_SecurityState)
  134. file.writeLine(Facility_PersonalSensors)
  135. file.writeLine(Facility_DEFCON)
  136. file.writeLine(Facility_NightShift)
  137. file.writeLine(Facility_DayShift)
  138. file.writeLine(Facility_SecurityProtocol)
  139. file.writeLine(Security_IncreaseState)
  140. file.writeLine(Security_DecreaseState)
  141. file.writeLine(ACCESS_Testing)
  142. file.writeLine(ACCESS_Security)
  143. file.writeLine(ACCESS_Manufactoring)
  144. file.writeLine(ACCESS_EmergencyServices)
  145. file.writeLine(ACCESS_DEFCON)
  146. file.writeLine(ACCESS_Lockdown)
  147. file.writeLine(EFM)
  148. file.writeLine(ENP)
  149. file.close()
  150. end
  151.  
  152. function LoadData()
  153. local file = fs.open("SystemData","r")
  154. Facility_SecurityState = file.readLine(1)
  155. Facility_PersonalSensors = file.readLine(2)
  156. Facility_DEFCON = file.readLine(3)
  157. Facility_NightShift = file.readLine(4)
  158. Facility_DayShift = file.readLine(5)
  159. Facility_SecurityProtocol = file.readLine(6)
  160. Security_IncreaseState = file.readLine(7)
  161. Security_DecreaseState = file.readLine(8)
  162. ACCESS_Testing = file.readLine(9)
  163. ACCESS_Security = file.readLine(10)
  164. ACCESS_Manufactoring = file.readLine(11)
  165. ACCESS_EmergencyServices = file.readLine(12)
  166. ACCESS_DEFCON = file.readLine(13)
  167. ACCESS_Lockdown = file.readLine(14)
  168. EFM = file.readLine(15)
  169. ENP = file.readLine(16)
  170. file.close()
  171. end
  172.  
  173. --Security Functions
  174.  
  175. function MartialLaw()
  176. rednet.broadcast(ENP,"LOCKDOWN")
  177. rednet.broadcast(Facility_SecurityProtocol,"MaritalLaw")
  178. end
  179.  
  180. function CompleteLockdown()
  181. MartialLaw()
  182. rednet.send(EFM,"Activate",ENP)
  183. LOCKED()
  184. end
  185.  
  186. --Emergency Functions
  187.  
  188. function LOCKED()
  189. while true do
  190. local id, message, protocol = rednet.receive()
  191. if id == EFM and message == "Activate" and protocol == ENP then
  192. Facility_SecurityState = 0
  193. start()
  194. break
  195. end
  196. end
  197.  
  198.  
  199. --User Interaction
  200. function UserInterface()
  201. term.clear()
  202. term.setCursorPos(1,1)
  203. print("==============FACILITY=MANAGER============")
  204. print("--------USER---INTERFACE------------------")
  205. print("---OPTIONS---")
  206. print(" 1 = REBOOT")
  207. print(" 2 = MANAGE ACCESS")
  208. print(" 3 = OPEN CONSOLE")
  209. print(" 4 = SAVED DATA")
  210. print(" 5 = CANCEL")
  211. local event, key = os.pullEvent("key")
  212. if key == keys.one then
  213. os.reboot
  214. elseif key == keys.two then
  215. UserInterface_AccessManagement()
  216. elseif key == keys.three then
  217.  
  218. elseif key == keys.four then
  219. UserInterface_Data()
  220. elseif key == keys.five then
  221. start()
  222. else
  223. UserInterface()
  224. end
  225.  
  226. end
  227.  
  228. function UserInferface_AccessManagement()
  229. term.clear()
  230. term.setCursorPos(1,1)
  231. print("===========ACCESS=MANAGEMENT=========")
  232. print("--OPTIONS--")
  233. print(" 1 = Testing ("..ACCESS_Testing..")")
  234. print(" 1 = Testing ("..ACCESS_Security..")")
  235. print(" 1 = Testing ("..ACCESS_Manufactoring..")")
  236. print(" 1 = Testing ("..ACCESS_EmergencyServices..")")
  237. print(" 1 = Testing ("..ACCESS_DEFCON..")")
  238. print(" 1 = Testing ("..ACCESS_Lockdown..")")
  239. end
  240.  
  241.  
  242. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement