Marlingaming

Cell Automated Management System

Sep 13th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. --This Program keeps track of a prisoners Schedule and ensures the Cells main systems run
  2. Settings_PrisonerID = 'n'
  3. Settings_StorageBlock = -1
  4. Settings_PrisonerName = 'n'
  5. Settings_PrisonerAccess = -1
  6. Settings_CellSleep = 0
  7. Settings_CellAwake = 0
  8. CellState = "start"
  9. PersonalID = 0
  10. SystemMode = "StandBy"
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. start()
  18.  
  19. function start()
  20. if fs.exists("Prisoner") == false then
  21. local file = fs.open("Prisoner","w")
  22. file.writeLine("Disabled")
  23. file.close()
  24. end
  25. GetPrisonerData()
  26. if CellState == "Disabled" then
  27. DISABLED()
  28. else
  29. MAIN()
  30. end
  31. end
  32.  
  33. function DISABLED()
  34. term.clear()
  35. print("Cell is Currently Disabled, to reenable, go to")
  36. print("file called 'Prisoner' and set the first line to")
  37. print("Prisoners Name, the 2nd line to 'need Update' and the 3rd Line")
  38. print(" to the Prisoners ID")
  39. print("then restart the computer, the Program should Continue")
  40. end
  41.  
  42. function MAIN()
  43. local Time = os.time("ingame")
  44. while true do
  45. Time = os.time("ingame")
  46. if Time == Settings_CellCleep then
  47. CellMode("Sleep")
  48. elseif Time == Settings_CellAwake then
  49. ScheduleUpdate()
  50. CellMode("Wake")
  51. elseif SystemMode == "StandBy" then
  52. ScheduleCheck(Time)
  53. else
  54. break
  55. end
  56. end
  57. end
  58.  
  59. function ScheduleCheck(Time)
  60. local file = fs.open("Schedule","r")
  61. for i = 1, #24 do
  62. if file.readLine(i*2-1) == Time
  63. file.close()
  64. ScheduleAction(i*2)
  65. end
  66. end
  67. end
  68.  
  69. function ScheduleAction(I)
  70. local file = fs.open("Schedule","r")
  71. if file.readLine(I) == "Testing" then
  72. CellManager("Testing","Move",0)
  73. elseif file.readLine(I) == "Search" then
  74. CellManager("Cell","Search",1)
  75. elseif file.readLine(I) == "Repairs" then
  76. CellManager("Cell","Repairs","Cell")
  77. elseif file.readLine(I) == "Meal" then
  78.  
  79. elseif file.readLine(I) == "RollCall" then
  80.  
  81. end
  82. file.close()
  83. end
  84.  
  85. function ScheduleUpdate()
  86. rednet.open("bottom")
  87. rednet.send(PersonalID,"Schedule",1000)
  88. rednet.send(PersonalID,Settings_PrisonerName,1000)
  89. repeat
  90. local id, message = rednet.receive()
  91. until message == "Method"
  92. rednet.send(PersonalID,"view",1000)
  93. repeat
  94. local id, message = rednet.receive()
  95. until id == PersonalID
  96. local file = fs.open("Schedule","w")
  97. file.write(message)
  98. file.close()
  99. end
  100.  
  101. function CellManager(Target,Action,Variable)
  102. if Target == "Cell" then
  103. if Action == "Search" then
  104. Bots("Security","Watch","Prisoner")
  105. Bots("Maintenance","Search","Containers")
  106. elseif Action == "Repairs" then
  107. Bots("Maintenance","Repair","Furniture")
  108. elseif Action == "CleanUp" then
  109. Bots("Maintenance","Repair","All")
  110. end
  111. elseif Target == "Testing" then
  112.  
  113. elseif Target == "Prisoner" then
  114.  
  115. elseif Target == "Turtles" then
  116.  
  117. end
  118. end
  119.  
  120. function CellMode(Action)
  121.  
  122. end
  123.  
  124. function Bots(Group,Action,Target)
  125. rednet.open("bottom")
  126. local file = fs.open("BotIDs","r")
  127. if Group == "Security then
  128. if Action == "Watch" then
  129. rednet.send(file.readLine(1),"Watch",0)
  130. elseif Action == "Eliminate" then
  131. rednet.send(file.readLine(1),"Eliminate",0)
  132. rednet.send(file.readLine(1),PrisonerName,0)
  133. end
  134. elseif Group == "Maintenance" then
  135. if Action == "Search" then
  136. if Target == "Player" then
  137. rednet.send(file.readLine(2),"S_Player",0)
  138. elseif Target == "Containers" then
  139. rednet.send(file.readLine(2),"S_Containers",0)
  140. end
  141. elseif Action == "Repair" then
  142. if Target == "All" then
  143.  
  144. elseif Target == "Furniture" then
  145.  
  146. end
  147. end
  148. end
  149. file.close()
  150. end
  151.  
  152. function GetPrisonerData()
  153. rednet.open("bottom")
  154. local file = fs.open("Prisoner","r")
  155. if file.readLine(1) == "Disabled" then
  156. CellState = "Disabled"
  157. elseif file.readLine(1) ~= "Disabled and file.readLine(2) == "Need Update" then
  158. CellState = "Data Required"
  159. Settings_PrisonerID = file.readLine(3)
  160. file.delete()
  161. rednet.broadcast(Settings_PrisonerID,1000)
  162. repeat
  163. local id, message, protocol = rednet.receive()
  164. until protocol == 1203
  165. local file = fs.open("Prisoner","w")
  166. file.write(message)
  167. file.close()
  168. CellState = "Operating"
  169. else
  170. CellState = "Operating"
  171. Settings_PrisonerID = file.readLine(3)
  172. Settings_PrisonerName = file.readLine(1)
  173. Settings_PrisonerAccess = file.readLine(4)
  174. Settings_CellSleep = file.readLine(5)
  175. Settings_CellAwake = file.readLine(6)
  176. Settings_StorageBlock = file.readLine(7)
  177. end
  178. file.close()
  179. end
Add Comment
Please, Sign In to add comment