Advertisement
hypnotizd

Hypno's Redstone Energy Cell Monitor

Oct 14th, 2013
1,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. ----------------------------------------------------------
  2. -- Hypno's Redstone Energy Cell Monitor                 --
  3. --                                                      --
  4. -- Hypno HermitCraft FTB Unleashed S2E16                --
  5. -- https://www.youtube.com/watch?v=rZPJd3SC3FQ          --
  6. --                                                      --
  7. -- YouTube Channel http://youtube.com/hypnotizd         --
  8. ----------------------------------------------------------
  9.  
  10. local function getPower(i)
  11.   local p = peripheral.wrap("right")
  12.   return p.callRemote(i, "getEnergyStored")
  13. end
  14.  
  15. local function getStatus()
  16.   local status = "Discharging"
  17.   if (rs.getOutput("left")) then
  18.     status = "Charging"
  19.   end
  20.   return status
  21. end
  22.  
  23. local function getPeripherals()
  24.   local t = {}
  25.   for k, v in pairs(peripheral.getNames()) do
  26.     if (string.find(v, "redstone_energy_cell")) then
  27.       t[v] = getPower(v)
  28.     end
  29.   end
  30.   return t
  31. end
  32.  
  33. while true do
  34.   local t = getPeripherals()
  35.   local power = 0
  36.   local i = 0
  37.   term.clear()
  38.   term.setCursorPos(1,1)
  39.  
  40.   for k, v in pairs(t) do
  41.     print("Cell "..(i+1)..": "..v)
  42.     power = power + v
  43.     i = i + 1
  44.   end
  45.  
  46.   if ((power/i) > 550000) then
  47.     rs.setOutput("left", false)
  48.   elseif ((power/i) < 300000) then
  49.     rs.setOutput("left", true)
  50.   end
  51.  
  52.   print("")
  53.   print("Average: "..(power/i))
  54.   print("Status: "..getStatus())
  55.  
  56.   os.sleep(10)
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement