Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = nil
- for _,pName in pairs(peripheral.getNames()) do
- if peripheral.getType(pName) == "monitor" then
- mon = peripheral.wrap(pName)
- end
- end
- function getCenter(f, varP)
- if not varP then
- varP = ""
- end
- if (f - string.len(varP) % 2) == 0 then
- return math.floor((f - string.len(varP))/2)
- end
- return math.floor((f - string.len(varP))/2)+1
- end
- while true do
- local amountOfCells = 0
- local totalEnergy = 0
- local totalMaxEnergy = 0
- for _,pName in pairs(peripheral.getNames()) do
- if peripheral.getType(pName) == "cofh_themalexpansion_energycell" then
- energycell = peripheral.wrap(pName)
- totalEnergy = totalEnergy + energycell.getEnergyStored("a")
- totalMaxEnergy = totalMaxEnergy + energycell.getMaxEnergyStored("a")
- amountOfCells = amountOfCells + 1
- end
- end
- local batteryP = totalEnergy*100/totalMaxEnergy
- mon.setBackgroundColor(colors.white)
- mon.clear()
- mon.setBackgroundColor(colors.green)
- if batteryP < 70 then
- mon.setBackgroundColor(colors.red)
- end
- local max_x, max_y = mon.getSize()
- for x=1, math.floor(max_x*batteryP/100), 1 do
- for y=1, max_y, 1 do
- mon.setCursorPos(x,y)
- mon.write(" ")
- end
- end
- mon.setCursorPos(getCenter(max_x, "Battery: " .. math.floor(batteryP*100)/100 .. "%"),getCenter(max_y))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement