Advertisement
XSiggeManx

Draconic Reactor ComputerCraft integration[GUI]

Dec 11th, 2020 (edited)
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.61 KB | None | 0 0
  1. otherComputerId = 15 -- Change this number to the other computers' ID. You can get the ID by typing "id" into the terminal.
  2.  
  3. monitor = peripheral.find("monitor")
  4.  
  5. local modemCount = 0
  6. for i,v in pairs(redstone.getSides()) do
  7. if peripheral.getType(v) == "modem" then
  8. rednet.open(v)
  9. modemCount = modemCount + 1
  10. end
  11. end
  12. if modemCount < 1 then
  13. print("You need a wireless/ender modem.")
  14. return
  15. end
  16. math.randomseed(os.time())
  17.  
  18. local temp
  19. local shield
  20. local sat
  21. local fuel
  22. local statusText
  23.  
  24. local info
  25. local chaos = false
  26.  
  27. mX,mY = monitor.getSize()
  28. local coreUpdateDelay = 30
  29. size = {9,13,15,17,17,19,19,19,17,17,15,13,9}
  30. coreShieldLayout = {}
  31.  
  32. function drawProgressBar(monitor, barColor, backgroundColor, progress, width)
  33. c = math.floor(progress*width)
  34. cR = width-c
  35. monitor.blit((" "):rep(c), (barColor):rep(c), (barColor):rep(c))
  36. monitor.blit((" "):rep(cR), (backgroundColor):rep(cR), (backgroundColor):rep(cR))
  37. end
  38.  
  39. function mainStuff()
  40. while not chaos do
  41. if info then
  42. temp = info.temperature
  43. shield = math.ceil(info.fieldStrength / info.maxFieldStrength * 10000) / 100
  44. sat = math.ceil(info.energySaturation / info.maxEnergySaturation * 10000) / 100
  45. fuel = math.ceil(info.fuelConversion / info.maxFuelConversion * 10000) / 100
  46. monitor.clear()
  47. monitor.setCursorPos(1, 1)
  48. monitor.setTextColor(colors.white)
  49. monitor.write("Core Temperature: " .. temp .. "°C")
  50. monitor.setCursorPos(1, 2)
  51. drawProgressBar(monitor, "1", "8", temp/10000, 49)
  52. monitor.setCursorPos(1, 3)
  53. monitor.write("Containment Field Strength: " .. shield .. "%")
  54. monitor.setCursorPos(1, 4)
  55. drawProgressBar(monitor, "b", "8", shield/100, 49)
  56. monitor.setCursorPos(1, 5)
  57. monitor.write("Energy Saturation: " .. sat .. "%")
  58. monitor.setCursorPos(1, 6)
  59. drawProgressBar(monitor, "5", "8", sat/100, 49)
  60. monitor.setCursorPos(1, 7)
  61. monitor.write("Fuel Conversion Level: " .. fuel .. "%")
  62. monitor.setCursorPos(1, 8)
  63. if info.status == "cold" then statusText = "Inactive" end
  64. if info.status == "warming_up" then statusText = "Charging" end
  65. if info.status == "running" then statusText = "Active" end
  66. if info.status == "stopping" then statusText = "Stopping" end
  67. if info.status == "cooling" then statusText = "Cooling" end
  68. if info.status == "beyond_hope" then
  69. statusText = "EXPLOSION IMMINENT!"
  70. chaos = true
  71. end
  72. monitor.write("Status: " .. statusText)
  73. monitor.setCursorPos(1, 9)
  74. monitor.write("Containment Field Drain Rate: " .. info.fieldDrainRate .. " RF/t")
  75. monitor.setCursorPos(1, 10)
  76. monitor.write("Fuel Conversion Rate: " .. info.fuelConversionRate .. " nb/t")
  77. if info.maxFuelConversion ~= 10368 then
  78. monitor.setTextColor(colors.red)
  79. monitor.setCursorPos(1, 12)
  80. monitor.write("Please use 8 awakened")
  81. monitor.setCursorPos(1, 13)
  82. monitor.write("draconium blocks!")
  83. end
  84. if (info.status == "cold" or info.status == "cooling") and info.maxFuelConversion == 10368 then
  85. monitor.setCursorPos(2, 12)
  86. monitor.blit("Charge Reactor", "00000000000000", "77777777777777")
  87. end
  88. if (info.status == "warming_up" or info.status == "stopping") and info.temperature >= 2000 then
  89. monitor.setCursorPos(2, 12)
  90. monitor.blit("Activate Reactor", "0000000000000000", "7777777777777777")
  91. end
  92. if info.status == "warming_up" or info.status == "running" then
  93. monitor.setCursorPos(2, 14)
  94. monitor.blit("Stop Reactor", "000000000000", "777777777777")
  95. end
  96. coreUpdateDelay = coreUpdateDelay + 1
  97. if coreUpdateDelay >= 30 then
  98. coreShieldLayout = {}
  99. for i = 1,#size do
  100. for j = 1,size[i] do
  101. table.insert(coreShieldLayout, math.random(1,70))
  102. end
  103. end
  104.  
  105. coreUpdateDelay = 0
  106. end
  107. drawCore()
  108. else
  109. monitor.clear()
  110. monitor.setCursorPos(1, 1)
  111. monitor.write("Reactor Computer is not connected!")
  112. end
  113. sleep(0.1)
  114. end
  115. end
  116.  
  117. function drawCore()
  118. local temperature = temp
  119. local fieldStrength = shield - 10
  120. local color1
  121. if temperature < 6000 then color1 = "e" end
  122. if temperature >= 6000 and temperature < 9000 then color1 = "1" end
  123. if temperature >= 9000 then color1 = "4" end
  124. local color2
  125. if fieldStrength < 85 then color2 = "b" else color2 = "9" end
  126. layoutIndex = 1
  127. for i = 1,#size do
  128. monitor.setCursorPos(math.floor(mX-10-size[i]/2),i+11)
  129. if fieldStrength > 50 then fieldStrength = 50 end
  130. for i2 = 1,size[i] do
  131. if coreShieldLayout[layoutIndex] <= fieldStrength then
  132. monitor.blit(" ",color2,color2)
  133. else
  134. monitor.blit(" ",color1,color1)
  135. end
  136. layoutIndex = layoutIndex + 1
  137. end
  138. end
  139. end
  140.  
  141. function redNetReceive()
  142. while true do
  143. id, msg = rednet.receive()
  144. if id == otherComputerId then
  145. info = msg
  146. end
  147. sleep(0)
  148. end
  149. end
  150.  
  151. function buttons()
  152. while not chaos do
  153. event, side, x, y = os.pullEvent("monitor_touch")
  154. if x >= 2 and x < 16 and y == 12 and (info.status == "cold" or info.status == "cooling") then
  155. rednet.send(otherComputerId, "chargeReactor")
  156. end
  157. if x >= 2 and x < 18 and y == 12 and (info.status == "warming_up" or info.status == "stopping") and info.temperature >= 2000 then
  158. rednet.send(otherComputerId, "activateReactor")
  159. end
  160. if x >= 2 and x < 14 and y == 14 and (info.status == "warming_up" or info.status == "running") then
  161. rednet.send(otherComputerId, "stopReactor")
  162. end
  163. sleep(0)
  164. end
  165. end
  166.  
  167. function chaosMessage()
  168. while true do
  169. if chaos then
  170. text1 = "WARNING!"
  171. text2 = "Explosion imminent!"
  172. text3 = "Evacuate now!"
  173. monitor.setTextColor(colors.red)
  174. monitor.setTextScale(2)
  175. yPos = 5
  176. monitor.setCursorPos(math.ceil(mX/2 - text1:len()/2+1),yPos)
  177. monitor.write(text1)
  178. monitor.setCursorPos(math.ceil(mX/2 - text2:len()/2+1),yPos+2)
  179. monitor.write(text2)
  180. monitor.setCursorPos(math.ceil(mX/2 - text3:len()/2+1),yPos+3)
  181. monitor.write(text3)
  182. sleep(1)
  183. monitor.clear()
  184. sleep(0.75)
  185. end
  186. sleep(1)
  187. end
  188. end
  189.  
  190. parallel.waitForAll(mainStuff, redNetReceive, buttons, chaosMessage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement