Guest User

PMS

a guest
Jan 4th, 2026
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.67 KB | None | 0 0
  1. --extreme reactors reactor needed
  2. --draconic star needed for power storage
  3.  
  4. --gui api
  5. local mon = peripheral.wrap("top")
  6. local monX, monY = mon.getSize()
  7.  
  8. function clear()
  9.     mon.clear()
  10.     mon.setBackgroundColor(colors.black)
  11.     mon.setCursorPos(1,1)
  12.     mon.setTextColor(colors.white)
  13. end
  14.  
  15. function drawText(x, y, text, color_txt, color_bg)
  16.     mon.setBackgroundColor(color_bg)
  17.     mon.setTextColor(color_txt)
  18.     mon.setCursorPos(x,y)
  19.     mon.write(text)
  20. end
  21.  
  22. function drawLine(x, y, length, size, color_bar)
  23.     for yPos = y, y+size-1 do
  24.         mon.setBackgroundColor(color_bar)
  25.         mon.setCursorPos(x, yPos)
  26.         mon.write(string.rep(" ", length))
  27.     end
  28. end
  29.  
  30. function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
  31.     drawLine(x, y, length, size, color_bg)
  32.     local barSize = math.floor((minVal/maxVal)*length)
  33.     drawLine(x, y, barSize, size, color_bar)
  34.     local text = name.." "..math.floor((minVal/maxVal)*100).."%"
  35.      if barSize > monX/2+#text/2 then
  36.          drawText(monX/2-#text/2, y+size/2, text, colors.black, color_bar)
  37.          elseif barSize > #text/2 then
  38.          drawText((x+barSize)-#text, y+size/2, text, colors.black, color_bar)    
  39.     end
  40. end
  41.  
  42. -- main  code
  43.  
  44. local reactor = peripheral.find("BigReactors-Reactor")
  45. local star = peripheral.find("draconic_rf_storage")
  46. local teir = 7
  47. local starCurr = star.getEnergyStored()
  48. local starMax = star.getMaxEnergyStored()
  49. local starPercent = math.floor((starCurr/starMax)*100)
  50. local starTrans = star.getTransferPerTick()
  51. local version = "1.0"
  52. local reactorPwr = reactor.getActive()
  53. local reactorStatus = "nominal"
  54. local reactorWaste = reactor.getWasteAmount()
  55. local reactorFuel = reactor.getFuelAmountMax()
  56. local reactorWastePercent = math.floor((reactorWaste/reactorFuel)*100)
  57.  
  58.     if starMax == 45500000 then    
  59.          teir = "1"
  60.     elseif starMax == 273000000 then
  61.          teir = "2"
  62.     elseif starMax == 1640000000 then
  63.          teir = "3"
  64.     elseif starMax == 9880000000 then
  65.          teir = "4"
  66.     elseif starMax == 59300000000 then
  67.          teir = "5"
  68.     elseif starMax == 356000000000 then
  69.          teir = "6"
  70.     elseif starMax == 2140000000000 then
  71.          teir = "7"
  72.     elseif starMax > 2140000000000 then
  73.          teir = "8"
  74.     else
  75.      error() "no valid star found"
  76.  end
  77.  
  78. function mainScreen()
  79.     drawLine(2, 2, monX-2, 1, colors.gray)
  80.     for i = 3, 25 do
  81.         drawLine(2, i, 1, 1, colors.gray)
  82.     end
  83.     drawLine(2, 25, monX-2, 1, colors.gray)
  84.     for i = 3, 25 do
  85.         drawLine(70, i, 1, 1, colors.gray)
  86.     end
  87.     for i = 3, 25 do
  88.         drawLine(35, i, 1, 1, colors.gray)
  89.     end
  90.     drawText(10, 4, "Reactor_status", colors.yellow, colors.black)
  91.     drawText(44, 4, "Draconic_Star_status", colors.yellow, colors.black)
  92.     drawText(11, 1, "Power Monitoring System. ver: "..version.." - by: tib tib", colors.green, colors.black)
  93.     drawText(37, 8, "Current Teir: "..teir, colors.yellow, colors.black)
  94.     drawText(37 , 9, "Current Transfer: ", colors.yellow, colors.black)
  95.     drawText(37, 10, "Current Stored:  ", colors.yellow, colors.black)
  96.     drawText(37, 11, "Maximum Storage:  "..starMax, colors.white, colors.black)
  97.     drawLine(2, 5, monX-2, 1, colors.gray)
  98.     drawText(4, 8, "Reactor:  ", colors.yellow, colors.black)
  99.     drawText(4, 10, "status:  ", colors.yellow, colors.black)
  100.     drawText(4, 12, "wasteLevel:  ", colors.yellow, colors.black)
  101.    end
  102.  
  103. function startup()
  104. clear()
  105. sleep(1)
  106. mon.write("Hello, and thank you for choosing Power Management systems by Tibbers")
  107. sleep(1)
  108. mon.setCursorPos(1,3)
  109. mon.write("now detecting all dependencies")
  110. mon.setCursorPos(1,5)
  111. sleep(1)
  112. mon.write("reactor found!!")
  113. mon.setCursorPos(1,7)
  114. sleep(1)
  115. mon.write("energy core found")
  116. mon.setCursorPos(1,9)
  117. sleep(1)
  118. mon.write("all dependencies found...   now booting...")
  119. mon.setCursorPos(1,11)
  120. sleep(1)
  121. sleep(.5)
  122. clear()
  123. mon.setBackgroundColor(colors.black)
  124. sleep(1)
  125. end
  126.  
  127. function Loop()
  128. while true do
  129.   starTrans = star.getTransferPerTick()
  130.   starPercent = math.floor((starCurr/starMax)*100)
  131.   sleep(.1)
  132. end
  133. end
  134.  
  135. function Status()
  136.     while true do
  137.         starTrans = star.getTransferPerTick()
  138.         starPercent = math.floor((starCurr/starMax)*100)
  139.         reactorPwr = reactor.getActive()
  140.         reactorWastePercent = math.floor((reactorWaste/reactorFuel)*100)
  141.         reactorWaste = reactor.getWasteAmount()
  142.         reactorFuel = reactor.getFuelAmountMax()
  143.         mon.setBackgroundColor(colors.black)
  144.         mon.setCursorPos(56,9)
  145.         mon.write("          ")
  146.         mon.setCursorPos(56,9)
  147.         if starTrans > 0 then
  148.             mon.setTextColor(colors.green)
  149.             mon.write(starTrans)
  150.         elseif starTrans < 0 then
  151.             mon.setTextColor(colors.red)
  152.             mon.write(starTrans)
  153.         else
  154.             mon.setTextColor(colors.yellow)
  155.             mon.write(starTrans)
  156.         end
  157.         mon.setCursorPos(55,10)
  158.         mon.write("    ")
  159.         mon.setCursorPos(55,10)
  160.         mon.setTextColor(colors.blue)
  161.         mon.write(starPercent.."%")
  162.         drawProg( 37, 12, " ", 30, 1, starPercent, 100, colors.blue, colors.white)
  163.         if reactorPwr == true then
  164.             mon.setCursorPos(14,8)
  165.             mon.setTextColor(colors.green)
  166.             mon.setBackgroundColor(colors.black)
  167.             mon.write("        ")
  168.             mon.setCursorPos(14,8)
  169.             mon.write("online")    
  170.         else
  171.             mon.setCursorPos(14,8)
  172.             mon.setTextColor(colors.red)
  173.             mon.setBackgroundColor(colors.black)
  174.             mon.write("        ")
  175.             mon.setCursorPos(14,8)
  176.             mon.write("offline")
  177.         end
  178.         if reactorPwr == true and reactorWastePercent < 5 then
  179.             reactorStatus = "nominal"
  180.         elseif reactorPwr == true and reactorWastePercent >= 5 then
  181.             reactorStatus = "Waste Eject Error"
  182.         elseif reactorPwr == false and reactorWastePercent < 5 then
  183.             reactorStatus = "Manual Shutdown"
  184.         elseif reactorPwr == false and reactorWastePercent >= 5 then
  185.             reactorStatus = "multiple Failures"
  186.         else
  187.             error() "not valid peramiter"
  188.         end
  189.         mon.setBackgroundColor(colors.black)
  190.         mon.setTextColor(colors.pink)
  191.         mon.setCursorPos(13,10)
  192.         mon.write("                 ")
  193.         mon.setCursorPos(13,10)
  194.         mon.write(reactorStatus)
  195.         mon.setCursorPos(16,12)
  196.         mon.setTextColor(colors.orange)
  197.         mon.write("     ")
  198.         mon.setCursorPos(16,12)
  199.         mon.write(reactorWastePercent.."%")
  200.         sleep(.1)    
  201.    end
  202. end
  203.  
  204. startup()
  205. clear()
  206. mainScreen()
  207. Status()
  208.  
Advertisement
Add Comment
Please, Sign In to add comment