Scarjit

Untitled

Oct 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local reactor = peripheral.wrap("back")
  2. local monitor = peripheral.wrap("monitor_0")
  3.  
  4. if reactor == nil then
  5. error("No reactor found")
  6. end
  7. if monitor == nil then
  8. error("No monitor found")
  9. end
  10.  
  11. local energyStored = 0
  12. local energyProduced = 0
  13. local energyCapacity = 0
  14. local fillPercentage = 0
  15. local batteryWindowFull = window.create(monitor, 1, 1, 5, 10, true)
  16. batteryWindowFull.setBackgroundColor(colours.red)
  17. batteryWindowFull.clear()
  18. batteryWindowFull.redraw()
  19.  
  20. local function round(num, numDecimalPlaces)
  21. local mult = 10^(numDecimalPlaces or 2)
  22. return math.floor(num * mult + 0.5) / mult
  23. end
  24.  
  25. local function UpdateReactorStats()
  26. local stats = reactor.getEnergyStats()
  27. energyStored = stats["energyStored"]
  28. energyProduced = stats["energyProducedLastTick"]
  29. energyCapacity = stats["energyCapacity"]
  30. if energyStored == 0 then
  31. fillPercentage = 0
  32. else
  33. fillPercentage = energyStored / energyCapacity * 100
  34. end
  35. end
  36.  
  37. local function ClearScreen()
  38. term.setBackgroundColor(colours.black)
  39. term.clear()
  40. term.setCursorPos(1,1)
  41. end
  42.  
  43. local function ClearMonitor()
  44. monitor.setBackgroundColor(colours.black)
  45. monitor.clear()
  46. monitor.setCursorPos(1,1)
  47. end
  48.  
  49. local function UpdateMonitorStats()
  50. batteryWindowFull.redraw()
  51. --monitor.write(fillPercentage)
  52. end
  53.  
  54. ClearScreen()
  55. ClearMonitor()
  56. UpdateReactorStats()
  57.  
  58. while true do
  59. os.sleep(0.2)
  60. UpdateReactorStats()
  61. ClearScreen()
  62. ClearMonitor()
  63. UpdateMonitorStats()
  64. end
Add Comment
Please, Sign In to add comment