Advertisement
GravityCube

Untitled

Sep 21st, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. mon = nil
  2.  
  3. for _,pName in pairs(peripheral.getNames()) do
  4. if peripheral.getType(pName) == "monitor" then
  5. mon = peripheral.wrap(pName)
  6. end
  7. end
  8. mon.setTextColor(colors.black)
  9. function getCenter(f, varP)
  10. if not varP then
  11. varP = ""
  12. end
  13. if (f - string.len(varP) % 2) == 0 then
  14. return math.floor((f - string.len(varP))/2)
  15. end
  16.  
  17. return math.floor((f - string.len(varP))/2)+1
  18.  
  19. end
  20.  
  21. while true do
  22. local amountOfCells = 0
  23. local totalEnergy = 0
  24. local totalMaxEnergy = 0
  25.  
  26. for _,pName in pairs(peripheral.getNames()) do
  27. if peripheral.getType(pName) == "cofh_thermalexpansion_energycell" then
  28. energycell = peripheral.wrap(pName)
  29.  
  30. totalEnergy = totalEnergy + energycell.getEnergyStored("a")
  31. totalMaxEnergy = totalMaxEnergy + energycell.getMaxEnergyStored("a")
  32.  
  33. amountOfCells = amountOfCells + 1
  34. end
  35. end
  36.  
  37. local batteryP = totalEnergy*100/totalMaxEnergy
  38.  
  39. mon.setBackgroundColor(colors.white)
  40. mon.clear()
  41.  
  42. mon.setBackgroundColor(colors.green)
  43.  
  44. if batteryP < 70 then
  45. mon.setBackgroundColor(colors.red)
  46. end
  47.  
  48. local max_x, max_y = mon.getSize()
  49. for x=1, math.floor(max_x*batteryP/100), 1 do
  50. for y=1, max_y, 1 do
  51. mon.setCursorPos(x,y)
  52. mon.write(" ")
  53. end
  54. end
  55. text = ("Battery: " .. math.floor(batteryP*100)/100 .. "%")
  56. mon.setCursorPos(getCenter(max_x, text),getCenter(max_y))
  57. mon.write(text)
  58. sleep(1)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement