Posted 25 August 2015 - 05:08 AM
For some reason, this code will not always write on the monitor:
Spoiler
local nameStart = "tile_thermalexpansion_cell"
local names = {
["Leadstone"] = 400000;
["Hardened"] = 2000000;
["Redstone"] = 20000000;
["Resonant"] = 80000000;
}
local totalStored = 0
local totalMax = 0
function cellName(maxstore)
local name = "Unknown"
for i,v in pairs(names)do
if v == maxstore then
name = i
end
end
return name
end
function shorten(num)
retNum = num
if num >= 1000 then
retNum = math.floor(num/10)/100 .."K"
end
if num >= 1000000 then
retNum = math.floor(num/10000)/100 .."M"
end
if num >= 1000000000 then
retNum = math.floor(num/10000000)/100 .."B"
end
if num >= 1000000000000 then --1 trillion, very impossible to get.
retNum = math.floor(num/10000000000)/100 .."T"
end
return retNum
end
local m = peripheral.find("monitor")
if not m then print("Monitor not found.") return end
while true do
local num = 1
totalStored = 0
totalMax = 0
for i,v in pairs(peripheral.getNames())do
local p = peripheral.wrap(v)
if v:lower():sub(1,#nameStart) == nameStart:lower() then
totalStored = totalStored + p.getEnergyStored()
totalMax = totalMax + p.getEnergyStored()
m.setCursorPos(1,num)
local percent = math.floor((p.getEnergyStored()/p.getMaxEnergyStored())*100)
local msg = cellName(p.getMaxEnergyStored()).." Energy Cell "..shorten(p.getEnergyStored()).."/"..shorten(p.getMaxEnergyStored()).." "..percent.."%"
m.clearLine()
m.write(msg)
num = num + 1
end
end
m.setCursorPos(1,num)
local percent = math.floor((totalStored/totalMax)*100)
local msg = "Total "..shorten(totalStored).."/"..shorten(totalMax).." "..percent.."%"
m.clearLine()
m.write(msg)
sleep(1)
end