Advertisement
brucelee

Extreme Reactor Power Management

Oct 10th, 2019 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----------------------------------------------------------
  2. -- Extreme Reactor Power Management                         --         --
  3. ----------------------------------------------------------
  4.  
  5. local reactor = peripheral.wrap("back")
  6. local stored = 0
  7. local prevStored = 0
  8. local lastTick = 0
  9. local status = "Discharging"
  10.  
  11. local function setLastTick()
  12.   lastTick = reactor.getEnergyProducedLastTick()
  13. end
  14.  
  15. local function setStored()
  16.   stored = reactor.getEnergyStored()
  17. end
  18.  
  19. local function checkPower()
  20.   setStored()
  21.   setLastTick()
  22.  
  23.   if (stored > 8000000) then
  24.     reactor.setAllControlRodLevels(100)
  25.     status = "Discharging"
  26.   elseif (stored <= 2000000) then
  27.     reactor.setAllControlRodLevels(0)
  28.     status = "Charging"
  29.   end
  30. end
  31.  
  32. local function displayStatus()
  33.   local pct = stored/10000000
  34.   term.clear()
  35.   term.setCursorPos(1,1)
  36.   local usage = (stored - prevStored)/20
  37.  
  38.   print(" Current Energy: "..math.floor(stored))
  39.   print("Energy Produced: "..math.floor(lastTick).." RF/t")
  40.   print("          Usage: "..math.floor(usage).." RF/t")
  41.   print("         Status: "..status)
  42. end
  43.  
  44. while true do
  45.   checkPower()
  46.   displayStatus()
  47.   prevStored = stored
  48.   os.sleep(1)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement