The3vilM0nk3y

Reactor 4

Apr 25th, 2020 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. local onLevel = .20
  2. local offLevel = .70
  3. local usingInduction = false
  4. local updateRate = .5
  5. local reactor = peripheral.find("BiggerReactors_Reactor")
  6. local m = peripheral.find("monitor")
  7. local powerBank = peripheral.find("Induction Matrix")
  8. local x,y = m.getSize()
  9. local numbars = 0
  10. local p = 0
  11. local level = 0
  12. local lastLevel = 0
  13. local change = 0
  14. local defaultMax = reactor.battery().capacity()
  15. local numRods = reactor.controlRodCount()
  16. local controlLevel = reactor.getControlRod(0).level()
  17. local maxFuelTemp = 5000
  18. local maxCasingTemp = 5000
  19. m.setTextScale(1)
  20. local maxPower = 0
  21.  
  22. if usingInduction and powerBank then
  23. maxPower = powerBank.getMaxEnergy() * .4
  24. else
  25. maxPower = defaultMax
  26. end
  27.  
  28. function getPowerUsage()
  29. return math.floor(reactor.battery().producedLastTick() - change)
  30. end
  31. function checkValue()
  32. if controlLevel > 100 then
  33. controlLevel = 100
  34. elseif controlLevel < 0 then
  35. controlLevel = 0
  36. end
  37. end
  38. function checkFiles()
  39. if not fs.exists("startup") then
  40. startFile = fs.open("startup", "w")
  41. startFile.write("multishell.launch({}, \"reactor\")")
  42. startFile.close()
  43. end
  44. if not fs.exists("update") then
  45. shell.run("pastebin","get","zbwpL7G7","update")
  46. end
  47. end
  48. function center(s)
  49. cx,cy = term.getCursorPos()
  50. term.setCursorPos((x/2) - (string.len(s)/2),cy)
  51. print(s)
  52. end
  53. function formatNumber(num)
  54. if num > 1000000000 then
  55. num = round(num/1000000000) .. "G"
  56. elseif num > 1000000 then
  57. num = round(num/1000000) .. "M"
  58. elseif num > 1000 then
  59. num = round(num/1000) .. "K"
  60. end
  61. return num
  62.  
  63. end
  64. function round(num)
  65. return math.floor(num*1000) / 1000
  66. end
  67. checkFiles()
  68. while true do
  69. if usingInduction then
  70. level = powerBank.getEnergy() *.4
  71. else
  72. level = reactor.battery().stored()
  73. end
  74. x,y = m.getSize()
  75. if level/maxPower < onLevel then
  76. reactor.setActive(true)
  77. end
  78. if level/maxPower > offLevel then
  79. reactor.setActive(false)
  80. end
  81. term.clear()
  82. term.setCursorPos(1,1)
  83. print("Current Level - " .. formatNumber(level))
  84. print("Current Level Raw- " .. level)
  85. print("Powered = " .. tostring(reactor.active()))
  86. print("Number of Control Rods - " .. numRods)
  87. print("\nHit Q to reboot Program.\nHit U to update.")
  88. print("Program written by RedStoner_Pro")
  89.  
  90. timer = os.startTimer(updateRate)
  91. computer = term.redirect(m)
  92. term.clear()
  93. term.setCursorPos(1,1)
  94. center("Reactor Manager Monitor")
  95. -- Power Bar
  96. p = level/maxPower
  97. numBars = math.floor((x-4)*p)
  98. print("Energy")
  99. term.write(" |")
  100. term.setBackgroundColor(colors.red)
  101. if p > offLevel then
  102. term.setBackgroundColor(colors.green)
  103. elseif p > onLevel then
  104. term.setBackgroundColor(colors.yellow)
  105. end
  106. for i=1,numBars do
  107. term.write(" ")
  108. end
  109. term.setBackgroundColor(colors.black)
  110. cx,cy= term.getCursorPos()
  111. term.setCursorPos(x-1,cy)
  112. print("|")
  113. sLevel = formatNumber(level) .. " / ".. formatNumber(maxPower)
  114. center(sLevel)
  115. -- Fuel
  116. fP = reactor.fuelTank().fuel()/reactor.fuelTank().capacity()
  117. numFBars = math.floor((x-4)*fP)
  118. print("Fuel Amount")
  119. term.write(" |")
  120. term.setBackgroundColor(colors.yellow)
  121. for i=1,numFBars do
  122. term.write(" ")
  123. end
  124. term.setBackgroundColor(colors.black)
  125. cx,cy= term.getCursorPos()
  126. term.setCursorPos(x-1,cy)
  127. print("|")
  128. center(math.floor(reactor.fuelTank().fuel()) .. "/" .. math.floor(reactor.fuelTank().capacity()) )
  129. -- Case Temp
  130. caseTemp = reactor.casingTemperature()
  131. caseP = caseTemp/maxCasingTemp
  132. numCaseBars = math.floor((x-4)*caseP)
  133. print("Case Temperature")
  134. term.write(" |")
  135. if caseTemp > maxCasingTemp * .666 then
  136. term.setBackgroundColor(colors.red)
  137. elseif caseTemp > maxCasingTemp * .333 then
  138. term.setBackgroundColor(colors.green)
  139. else
  140. term.setBackgroundColor(colors.blue)
  141. end
  142. for i=1,numCaseBars do
  143. term.write(" ")
  144. end
  145. term.setBackgroundColor(colors.black)
  146. cx,cy= term.getCursorPos()
  147. term.setCursorPos(x-1,cy)
  148. print("|")
  149. center(math.floor(caseTemp) .. " Celcius")
  150. --Fuel Temp
  151. fuelTemp = reactor.fuelTemperature()
  152. fuelP = fuelTemp/maxFuelTemp
  153. numFuelBars = math.floor((x-4)*fuelP)
  154. print("Fuel Temperature")
  155. term.write(" |")
  156. if fuelTemp > maxFuelTemp * .666 then
  157. term.setBackgroundColor(colors.red)
  158. elseif fuelTemp > maxFuelTemp * .333 then
  159. term.setBackgroundColor(colors.green)
  160. else
  161. term.setBackgroundColor(colors.blue)
  162. end
  163. for i=1,numFuelBars do
  164. term.write(" ")
  165. end
  166. term.setBackgroundColor(colors.black)
  167. cx,cy= term.getCursorPos()
  168. term.setCursorPos(x-1,cy)
  169. print("|")
  170. center(math.floor(fuelTemp) .. " Celcius")
  171. -- Stats
  172. change = math.floor((level - lastLevel)/(20 * updateRate))
  173. print("Fuel Usage = " .. reactor.fuelTank().burnedLastTick() .. " mB/t")
  174. print("RF/T Created = " .. math.floor(reactor.battery().producedLastTick()))
  175. print("RF/T Used = " .. getPowerUsage())
  176. print("RF/T Internal Change = " .. change)
  177. -- Control Rod Modifiers
  178. term.setCursorPos(1,y-1)
  179. center("Control Rod Level = " .. controlLevel)
  180. term.setBackgroundColor(colors.red)
  181. term.setCursorPos(2,y)
  182. term.write(" -1 ")
  183. term.setCursorPos(7,y)
  184. term.write(" -10 ")
  185. term.setCursorPos((x/2-1),y)
  186. if reactor.active() then
  187. term.setBackgroundColor(colors.green)
  188. else
  189. term.setBackgroundColor(colors.red)
  190. end
  191. term.write("POWER")
  192. term.setBackgroundColor(colors.green)
  193. term.setCursorPos(x-4,y)
  194. term.write(" +1 ")
  195. term.setCursorPos(x-10,y)
  196. term.write(" +10 ")
  197. term.setBackgroundColor(colors.black)
  198. lastLevel = level
  199. term.redirect(computer)
  200. e = "nottimer"
  201. while e ~= "timer" do
  202. e,p1,p2,p3 = os.pullEvent()
  203. if e == "timer" then
  204. break
  205. elseif e == "key" and p1 == 16 then
  206. os.reboot()
  207. break
  208. elseif e == "key" and p1 == 22 then
  209. shell.run("update")
  210. elseif e == "monitor_touch" then
  211. if p3 == y then
  212. if p2 >= 2 and p2 <= 5 then
  213. controlLevel = controlLevel - 1
  214. checkValue()
  215. reactor.setAllControlRodLevels(controlLevel)
  216. elseif p2 >= 7 and p2 <= 11 then
  217. controlLevel = controlLevel - 10
  218. checkValue()
  219. reactor.setAllControlRodLevels(controlLevel)
  220. elseif p2 >= x-10 and p2 <= x-6 then
  221. controlLevel = controlLevel + 10
  222. checkValue()
  223. reactor.setAllControlRodLevels(controlLevel)
  224. elseif p2 >= x-4 and p2 <= x-1 then
  225. controlLevel = controlLevel + 1
  226. checkValue()
  227. reactor.setAllControlRodLevels(controlLevel)
  228. elseif p2 >= x/2-1 and p2 <= x/2+3 then
  229. if reactor.active() then
  230. reactor.setActive(false)
  231. else
  232. reactor.setActive(true)
  233. end
  234. end
  235. end
  236. end
  237. end
  238. end
  239.  
Advertisement
Add Comment
Please, Sign In to add comment