Advertisement
MrFoxit

cell reader

Feb 21st, 2023 (edited)
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. EnergyCell = {}
  2. hMon = {}
  3. vMon = {}
  4. pPower = 0
  5. Power = 0
  6. Capacity = 0
  7. dPower = 0
  8. dCapacity = 0
  9. dif = 0
  10.  
  11. pList = peripheral.getNames()
  12. for i=1,#pList do
  13.     if peripheral.getType(pList[i]) == "thermalexpansion:storage_cell" then
  14.         EnergyCell[#EnergyCell+1] = peripheral.wrap(pList[i])
  15.     end
  16.     if peripheral.getType(pList[i]) == "monitor" then
  17.         v,h = peripheral.wrap(pList[i]).getSize()
  18.         if v == 18 then
  19.             hMon[#hMon+1] = peripheral.wrap(pList[i])
  20.         end
  21.         if v == 7 then
  22.             vMon[#vMon+1] = peripheral.wrap(pList[i])
  23.         end
  24.     end
  25. end
  26.  
  27. for i = 1,#EnergyCell do
  28.     Power = Power + EnergyCell[i].getRFStored()
  29.     Capacity = Capacity + EnergyCell[i].getRFCapacity()
  30. end
  31.  
  32. while true do
  33.    
  34.     term.clear()
  35.     term.setCursorPos(1,1)
  36.     print("Cellule : "..#EnergyCell)
  37.     print(Power.." RF/"..Capacity.." RF")
  38.     print(math.floor(dif/20).." RF/t")
  39.     Pourcent = (Capacity / Power) * 100
  40.    
  41.     pPower = Power
  42.     Power = 0
  43.     for i = 1,#EnergyCell do
  44.         Power = Power + EnergyCell[i].getRFStored()
  45.     end
  46.     dif = Power - pPower
  47.     if Power > 100000 then
  48.         dPower = math.floor(Power/1000).."K"
  49.     end
  50.     if Power > 1000000 then
  51.         dPower = math.floor(Power/1000000).."M"
  52.     end
  53.     if Capacity > 100000 then
  54.         dCapacity = math.floor(Capacity/1000).."K"
  55.     end
  56.     if Capacity > 1000000 then
  57.         dCapacity = math.floor(Capacity/1000000).."M"
  58.     end
  59.     for h = 1,#hMon do
  60.         hMon[h].setTextScale(2)
  61.         hMon[h].clear()
  62.         hMon[h].setTextColor(colors.white)
  63.         hMon[h].setCursorPos(1,1)
  64.         hMon[h].write(dPower.." RF/"..dCapacity.." RF")
  65.         hMon[h].setCursorPos(1,2)
  66.         hMon[h].write(Pourcent.." %")
  67.         hMon[h].setCursorPos(1,3)
  68.         if dif > 0 then
  69.             hMon[h].setTextColor(colors.green)
  70.             hMon[h].write(tostring(dif).." RF/s")
  71.             hMon[h].setCursorPos(1,4)
  72.             hMon[h].write("Full in "..math.floor((Capacity - Power) / dif).."s")
  73.         elseif dif < 0 then
  74.             hMon[h].setTextColor(colors.red)
  75.             hMon[h].write(tostring(dif).." RF/s")
  76.             hMon[h].setCursorPos(1,4)
  77.             hMon[h].write("Empty in "..math.floor(Power / (dif*-1)).."s")
  78.         elseif dif == 0 then
  79.             hMon[h].setTextColor(colors.white)
  80.             hMon[h].write(tostring(dif).." RF/s")
  81.         end
  82.        
  83.        
  84.        
  85.     end
  86.     for v = 1,#vMon do
  87.         vMon[v].clear()
  88.         vMon[v].setCursorPos(1,1)
  89.         vMon[v].write("Not in")
  90.         vMon[v].setCursorPos(1,2)
  91.         vMon[v].write("use!")
  92.         vMon[v].setCursorPos(1,3)
  93.         vMon[v].write("now...")
  94.     end
  95.     sleep(0.8)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement