Muzze77

NuclearElmos_Reactor

Oct 26th, 2024 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.61 KB | None | 0 0
  1. shell.run("clear")
  2. dbcol = colors.black
  3. dtcol = colors.lime
  4. diskR = ""
  5. outp = "bottom"
  6. print("REACTOR CORE")
  7.  
  8. function mbut(cx,cy,text,bcol,tcol)
  9.     if bcol == nil then
  10.         bcol = dbcol
  11.     end
  12.     if tcol == nil then
  13.         tcol = dtcol
  14.     end
  15.     mon.setCursorPos(cx,cy)
  16.     mon.setBackgroundColor(bcol)
  17.     mon.setTextColor(tcol)
  18.     mon.write(string.rep(" ",#text))
  19.     mon.setCursorPos(cx,cy)
  20.     mon.write(text)
  21.     mon.setBackgroundColor(dbcol)
  22.     mon.setTextColor(dtcol)
  23. end
  24.  
  25. reactor_colors = {colors.yellow,colors.orange,colors.cyan,colors.purple,colors.pink,colors.magenta,colors.brown,colors.gray, colors.lightBlue, colors.white}
  26.  
  27. function rows(ry)
  28. if ry == nil then
  29. mbut(2,y,"|")
  30. mbut(27,y,"|")
  31. mbut(52,y,"|")
  32. mbut(78,y,"|")
  33. else
  34. mbut(2,ry,"|")
  35. mbut(27,ry,"|")
  36. mbut(52,ry,"|")
  37. mbut(78,ry,"|")
  38. end
  39. end
  40.  
  41. function line(ly)
  42. if ly == nil then
  43. mbut(2,y,"+")
  44. mbut(3,y,string.rep("-",74))
  45. mbut(27,y,"+")
  46. mbut(52,y,"+")
  47. mbut(78,y,"+")
  48. else
  49. mbut(2,ly,"+")
  50. mbut(3,ly,string.rep("-",74))
  51. mbut(27,ly,"+")
  52. mbut(52,ly,"+")
  53. mbut(78,ly,"+")
  54. end
  55. end
  56.  
  57. function frame()
  58. for y = 1,37,1 do
  59. rows(y)
  60. end
  61.  
  62. end
  63.  
  64. state = false
  65. rs.setOutput(outp,false)
  66. machines = {}
  67. machines = peripheral.getNames()
  68.  
  69. mon = ""
  70. reactors = {}
  71.  
  72.  
  73. for v, k in pairs(machines) do
  74.  
  75.     if string.find(k,"monitor")  ~= nil then
  76.         mon = peripheral.wrap(k)
  77.         mon.setTextScale(0.5)
  78.         mon.clear()
  79.     end
  80.     if string.find(k,"reactor") ~= nil then
  81.         table.insert(reactors,k)
  82.        
  83.     end
  84.     if string.find(k,"chest_diamond") ~= nil then
  85.         chest = peripheral.wrap(k)
  86.         chestAPI = k
  87.     end
  88.     if string.find(k,"drive") ~= nil then
  89.         drive = peripheral.wrap(k)
  90.         driveAPI = k
  91.         function readDisk(state)
  92.             if state == nil then
  93.                 diskR = fs.open("disk/akw.lua","r")
  94.                 if diskR == nil then
  95.                     create = fs.open("disk/akw.lua","w")
  96.                     create.write(false)
  97.                     create.close()
  98.                 end
  99.                 reading = diskR.readAll()
  100.                 diskR.close()
  101.                 return reading
  102.             else
  103.                 diskR = fs.open("disk/"..state..".lua","r")
  104.                 if diskR == nil then
  105.                     create = fs.open("disk/"..state..".lua","w")
  106.                     create.write(false)
  107.                     create.close()
  108.                 end
  109.                 reading = diskR.readAll()
  110.                 diskR.close()
  111.                 return reading
  112.                
  113.             end
  114.         end
  115.  
  116.         function saveDisk(text,state)
  117.             if state == nil then
  118.                 disk = fs.open("disk/akw.lua","w")
  119.                 disk.write(text)
  120.                 disk.close()
  121.             else   
  122.                 if type(text) == "table" then
  123.                     disk = fs.open("disk/"..state..".lua","w")
  124.                     for a, b in pairs(text) do
  125.                         disk.writeLine(b)
  126.                     end
  127.                     disk.close()
  128.                 else
  129.                     disk = fs.open("disk/"..state..".lua","w")
  130.                     disk.write(text)   
  131.                     disk.close()   
  132.                 end
  133.             end
  134.         end    
  135.     end
  136.  
  137. end
  138.  
  139. while true do
  140.  
  141. mbut(28,35,"                                              ")
  142.  
  143. x = 2
  144. y = 2
  145.  
  146.  
  147.  
  148. sum = 0
  149. reactorsStats = {}
  150. frame()
  151. line(1)
  152. line(5)
  153. line(19)
  154. line(33)
  155. line(37)
  156. mbut(52,34," ")
  157. mbut(52,35," ")
  158. mbut(52,36," ")
  159.  
  160. y = 7
  161. saveDisk(reactors,"ids")
  162. for v,k in pairs(reactors) do
  163.  
  164.     mod = v % 3
  165.     if mod == 0 then
  166.         x = 54
  167.         y = y - 14 
  168.  
  169.     elseif mod == 1 then
  170.             x = 4
  171.     elseif mod == 2 then
  172.         x = 29
  173.         y = y - 14  
  174.  
  175.                
  176.     end
  177.     reactor = peripheral.wrap(k)
  178.     reactorAPI = k
  179.     reactorCore = reactor.getReactorCore()
  180.     data = reactorCore.getMetadata()
  181.     stats = data["reactor"]
  182.    
  183.     reactor_status = stats.active
  184.     reactor_heat = stats.heat
  185.     reactor_eu = stats.euOutput
  186.     reactor_maxHeat = stats.maxHeat
  187.  
  188.    
  189.     eu = string.format("%d",reactor_eu)
  190.     sum = sum + eu
  191.     rows()
  192.     col = 0
  193.  if fs.exists("disk/akw.lua") == nil then
  194.      state = false
  195.      saveDisk(state)
  196.  else
  197.      state = readDisk()
  198.     if state == nil then
  199.         state = "false"
  200.         saveDisk(state)
  201.     end
  202.  end
  203.  
  204.  
  205.     if reactor_heat >= 2000 then
  206.             state = false
  207.             saveDisk(state)
  208.     end
  209.  
  210.     print("[" .. v .. "] " .. state)
  211.  
  212.     mbut(4,3,"All Reactors: ")
  213.     mbut(20,3,"|")
  214.     if state == "true"  then
  215.         rs.setOutput(outp,true)
  216.         mbut(18,3,"ON",colors.green)
  217.         mbut(21,3,"OFF")
  218.     elseif state == "false" or state == "nil" then
  219.         rs.setOutput(outp,false)
  220.         mbut(18,3,"ON")
  221.         mbut(21,3,"OFF",colors.red)
  222.     end
  223.     saveReactor = textutils.serialize({k,x,y,reactor_status})  
  224.     if reactor_status == true then
  225.         reactor_status = "ON"
  226.         col = colors.green
  227.     else   
  228.         reactor_status = "OFF"
  229.         col = colors.red
  230.     end
  231.    
  232.     mbut(x,y,"                      ")
  233.     rCol = reactor_colors[v]
  234.     mbut(x,y,"REACTOR: " .. v,nil,rCol)
  235.  
  236.     saveDisk(saveReactor,k)
  237.     y = y + 1
  238.     rows()
  239.     mbut(x,y,"                      ")
  240.     mbut(x,y,"ACTIVE: " .. reactor_status,nil,col)
  241.     y = y + 1
  242.     rows()
  243.     mbut(x,y,"                      ")
  244.     mbut(x,y,"EU/T: " .. eu)
  245.     y = y + 1
  246.    
  247.     mbut(x,y,"                      ")
  248.     mbut(x,y,"HEAT: " .. reactor_heat .. " / " .. reactor_maxHeat)
  249.     y = y + 1
  250.     mbut(x,y,"RODS STATUS:" )
  251.     y = y + 1
  252. cells = {}
  253.     for a,b in pairs(reactor.list()) do
  254.         meta = reactor.getItemMeta(a)
  255.  
  256.         if string.find(meta.displayName,"Dual Uranium Cell") ~= nil then
  257.             dama = meta.damage
  258.             table.insert(cells,dama)           
  259.         end
  260.  
  261.     end
  262.     if #cells < 8 then
  263.         c = 8-#cells
  264.         for ce = 1,c,1 do
  265.         table.insert(cells,0)
  266.         end
  267.     end
  268.     x2 = x
  269.     y2 = y
  270.     for a,b in pairs(cells) do
  271.         mod = a % 2
  272.         if mod == 1 then
  273.             x2 = x
  274.  
  275.             y2 = y2 + 1
  276.         else
  277.             x2 = x2 + 8
  278.            
  279.         end
  280.  
  281.         dMax = 20
  282.         d = b
  283.         perc = 100/dMax * d
  284.         sD = string.format("%3d",perc)
  285.         rCol = reactor_colors[a]
  286.         mbut(x2,y2,a .. ": " .. sD .. "%",nil,rCol)
  287.                
  288.     end
  289.  
  290.     y = y + 9
  291.  
  292.  
  293.    
  294.    
  295. end
  296.  
  297. mbut(4,35,"                    ")
  298. mbut(4,35,"Total EU/T: " .. sum, nil, colors.blue)
  299. y = y + 1
  300.  
  301.  
  302.  
  303.  
  304.  
  305. sleep(1)
  306.  
  307. end
  308.  
Advertisement
Add Comment
Please, Sign In to add comment