ImTehZink

TE5 Energy Cell Power Monitor

Jan 29th, 2021 (edited)
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.90 KB | None | 0 0
  1. local upper = 0.90
  2. local lower = 0.10
  3. local redstoneSide = ''
  4.  
  5.  
  6. cellCount = 0
  7. connectedCells = {}
  8. monitorCount = 0
  9. connectedMonitors = {}
  10. TE5Cell = 0
  11. periList = table.pack(peripheral.find('thermalexpansion:storage_cell'))
  12.  
  13.  
  14. for i,v in ipairs(periList) do
  15.     local periFunctions = {
  16.         ['thermalexpansion:storage_cell'] = function()
  17.             cellCount = cellCount + 1
  18.             TE5Cell = TE5Cell + 1
  19.             connectedCells[cellCount] = periList[i]
  20.         end
  21.     }
  22.    
  23. end
  24.  
  25. if cellCount == 0 then
  26.     print('No RF Storage Found. Exiting Script!')
  27.     return
  28. end
  29. if monitorCount == 0 then
  30.     print('No Monitor Found. Exiting Script!')
  31.     return
  32. end
  33.  
  34.  
  35.  
  36.  
  37.  
  38. for i = 1, #connectedMonitors do
  39.     local monitor = peripheral.wrap(connectedMonitors[i])
  40. end
  41.  
  42. print('Peripherals Connected:')
  43. if monitorCount > 1 then print(monitorCount..' Monitors') else print(monitorCount..' Monitor') end
  44. if TE5Cell ~= 1 then print(TE5Cell..' TE Energy Cells') else print(TE5Cell..' TE Energy Cell') end
  45. if reactor ~= nil then print('1 Reactor') else print('0 Reactors') end
  46.  
  47.  
  48.  
  49. if redstoneSide ~= 'none' then redstone.setOutput(redstoneSide, false) end
  50. if reactor ~= nil then reactor.setActive(false) end
  51.  
  52.  
  53. for i = 1, #connectedMonitors do
  54.     local monitor = peripheral.wrap(connectedMonitors[i])
  55.         monitor.clear()
  56.         monitor.setBackgroundColor((colors.gray))
  57.         monitor.setCursorPos(1,4)
  58.         monitor.write(' ON ')
  59.         monitor.setBackgroundColor((colors.green))
  60.         monitor.setCursorPos(5,4)
  61.         monitor.write(' OFF ')
  62.         monitor.setBackgroundColor((colors.black))
  63. end
  64.  
  65.  
  66. while true do
  67.  
  68.  
  69.     local eNow = 0 eMax = 0 cellLoops = 0
  70.     for i = 1, cellLoops == #connectedCells do
  71.         cell = peripheral.wrap(connectedCells[i])
  72.         eNow = eNow + cell.getEnergyStored()
  73.         eMax = eMax + cell.getMaxEnergyStored()
  74.         cellLoops = i
  75.     end
  76.    
  77.    
  78.    
  79.     local fill = eNow / eMax
  80.    
  81.    
  82.    
  83.     if eNow >= 1000000000 then eNowScale = 'billion'
  84.     elseif eNow >= 1000000 then eNowScale = 'million'
  85.     else eNowScale = 'none' end
  86.     if eMax >= 1000000000 then eMaxScale = 'billion'
  87.     elseif eMax >= 1000000 then eMaxScale = 'million'
  88.     else eMaxScale = 'none' end
  89.    
  90.    
  91.     if eNowScale == 'billion' then eNowValue = math.ceil(eNow / 1000000)
  92.     elseif eNowScale == 'million' then eNowValue = math.ceil(eNow / 1000)
  93.     else eNowValue = math.ceil(eNow) end
  94.     if eMaxScale == 'billion' then eMaxValue = math.ceil(eMax / 1000000)
  95.     elseif eMaxScale == 'million' then eMaxValue = math.ceil(emax / 1000)
  96.     else eMaxScale = math.ceil(eMax) end
  97.    
  98.    
  99.     if eNowScale == 'billion' then eNowSuffix = 'mRF'
  100.     elseif eNowScale == 'million' then eNowSuffix = 'kRF'
  101.     else eNowSuffix = 'RF' end
  102.     if eMaxScale == 'billion' then eMaxSuffix = 'mRF'
  103.     elseif eMaxScale == 'million' then eMaxSuffix = 'kRF'
  104.     else eMaxSuffix = 'RF' end
  105.    
  106.    
  107.     local eNowDigitCount = 0 eMaxDigitCount = 0
  108.     for digit in string.gmatch(eNowValue, '%d') do eNowDigitCount = eNowDigitCount + 1 end
  109.     for digit in string.gmatch(eMaxValue, '%d') do eMaxDigitCount = eMaxDigitCount + 1 end
  110.    
  111.    
  112.     eNowX = 16 - eNowDigitCount
  113.     eMaxX = 16 - eMaxDigitCount
  114.    
  115.    
  116.     for i = 1, #connectedMonitors do
  117.         local monitor=peripheral.wrap(connectedMonitors[i])
  118.        
  119.         monitor.setCursorPos(10,3)
  120.         monitor.write('       ')
  121.         monitor.setCursorPos(10,5)
  122.         monitor.write('       ')
  123.        
  124.         monitor.setCursorPos(2,2)
  125.         monitor.write('Engines:')
  126.         monitor.setCursorPos(11,2)
  127.         monitor.write('Storage:')
  128.         monitor.setCursorPos(eNowX, 3)
  129.         monitor.write(eNowValue..eNowSuffix)
  130.         monitor.setCursorPos(eMaxX, 4)
  131.         monitor.write('of:')
  132.         monitor.setCursorPos(eMaxX, 5)
  133.         monitor.write(eMaxValue..eMaxSuffix)
  134.         if fill > upper then
  135.             if redstoneSide ~= 'none' then redstone.setOutput(redstoneSide, false) end
  136.             if reactor ~= nil then reactor.setActive(false) end
  137.             monitor.setBackgroundColor((colors.gray))
  138.             monitor.setCursorPos(1,4)
  139.             monitor.write(' ON ')
  140.             monitor.setBackgroundColor((colors.green))
  141.             monitor.setCursorPos(5,4)
  142.             monitor.write(' OFF ')
  143.             monitor.setBackgroundColor((colors.black))
  144.         elseif fill < lower then
  145.             if redstoneSide ~= 'none' then redstone.setOutput(redstoneSide, true) end
  146.             if reactor ~= nil then reactor.setActive(true) end
  147.             monitor.setBackgroundColor((colors.gray))
  148.             monitor.setCursorPos(1,4)
  149.             monitor.write(' ON ')
  150.             monitor.setBackgroundColor((colors.green))
  151.             monitor.setCursorPos(5,4)
  152.             monitor.write(' OFF ')
  153.             monitor.setBackgroundColor((colors.black))
  154.         end
  155.     end
  156.     sleep(1)
  157. end
  158.  
Add Comment
Please, Sign In to add comment