Advertisement
Marlingaming

CC Tweaked Park Control Terminal

Feb 24th, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. local Times = {6.00,21.00}
  2. local Open = false
  3. local Lockdown = false
  4. local Power = false
  5. local Transaction = false
  6. local Gate = 0
  7. local Security = 0
  8. local Atmo = 0
  9. local Pwr = nil
  10. local Announcements = {}
  11. local Facilities = {}
  12. peripheral.find("modem",rednet.open)
  13.  
  14. local function Clear()
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. end
  18.  
  19. function PlayAnnouncement(I)
  20. Announcements[I][1] = true
  21. shell.run("Transmitter",Announcements[I][3])
  22. end
  23.  
  24. function CheckSchedule()
  25. while true do
  26. if Transaction = true and Open = false and os.time() > Times[1] and os.time() < Times[2] then Open = true Transaction = false else Open = false Transaction = false end
  27. if Open == true then
  28. if os.time() > 17.00 then Atmo("Da",false) Atmo("Ni",true") end
  29. for i =1, #Announcements do
  30. if Announcements[i][1] == false and os.time() > Announcements[i][2] then PlayAnnouncement(i) end
  31. end
  32. end
  33. if Transaction == false then
  34. if Open == true then
  35. rednet.send(Gate,"Open")
  36. rednet.send(Security,"Open")
  37. Atmo("Da",true)
  38. elseif Open == false then
  39. rednet.send(Gate,"Close")
  40. rednet.send(Security,"Close")
  41. Atmo("Ni",false)
  42. end
  43. Transaction = true
  44. end
  45. if os.time() > 23.00 and os.time() < 23.10 then break end
  46. end
  47. end
  48.  
  49. function Atmo(t,R)
  50. local Da
  51. if t == "Em" then
  52. Da = {"E_Lights",R}
  53. rednet.send(Atmo,Da,Protocol)
  54. elseif t == "No" then
  55. Da = {"M_Lights",R}
  56. rednet.send(Atmo,Da,Protocol)
  57. elseif t == "Ni" then
  58. Da = {"N_Effects",R}
  59. rednet.send(Atmo,Da,Protocol)
  60. elseif t == "Da" then
  61. Da = {"D_Effects",R}
  62. rednet.send(Atmo,Da,Protocol)
  63. end
  64. end
  65.  
  66. function Int()
  67. local Menu = "Base"
  68. term.setBackgroundColor(colors.lightBlue)
  69. Clear()
  70. while true do
  71. local options
  72. Clear()
  73. print("Park Control Terminal")
  74. if Menu == "Base" then
  75. options = {"lockdown","schedule","facilities"}
  76. elseif Menu == "Schedule" then
  77. options = {"return"}
  78. print(textutils.serialize(Times))
  79. print(textutils.serialize(Announcements))
  80. elseif Menu == "Facilities" then
  81. options = {"return"}
  82. print(textutils.serialize(Facilities))
  83. end
  84. local n = CUI(options)
  85. if options[n] == "lockdown" then Open = false end
  86. if options[n] == "return" then Menu = "Base" end
  87. if options[n] == "schedule" then Menu = "Schedule" end
  88. if options[n] == "facilities" then Menu = "Facilities" end
  89. end
  90. end
  91.  
  92. function PoCheck()
  93. while true do
  94. local id, message = rednet.receive()
  95. if id == Pwr and message == false then Power = false break end
  96. end
  97. if Power == false then
  98. rednet.send(Gate,"Close")
  99. rednet.send(Security,"Off")
  100. Atmo("Ni",false)
  101. Atmo("Da",false)
  102. Atmo("No",false)
  103. Atmo("Em",true)
  104. end
  105. end
  106.  
  107. function GetFiles()
  108. local Content
  109. local F1 = fs.open("Times.txt","r")
  110. Content = F1.readAll()
  111. Times = textutils.unserialize(Content)
  112. F1.close()
  113. local F2 = fs.open("Announcements.txt","r")
  114.  
  115. Content = F2.readAll()
  116. Announcements = textutils.unserialize(Content)
  117. F2.close()
  118. end
  119.  
  120. function Runner()
  121. GetFiles()
  122. parallel.waitForAny(Int,CheckSchedule,PoCheck)
  123. os.reboot()
  124. end
  125.  
  126. function Standby()
  127. Clear()
  128. term.setCursorPos(7,10)
  129. print("no power")
  130. while true do
  131. local id, message = rednet.receive()
  132. if id == Pwr and message == true then Power = true break end
  133. end
  134. if Power == true then
  135. Runner()
  136. else
  137. os.sleep(4)
  138. os.reboot()
  139. end
  140. end
  141.  
  142. if Pwr ~= nil then
  143. rednet.send(Pwr,"status")
  144. local H, J, K = rednet.receive()
  145. Power = J
  146. else
  147. Power = true
  148. end
  149.  
  150. if Power == true then
  151. Runner()
  152. else
  153. Standby()
  154. end
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement