Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- local prox=sensor.wrap("top")
- redstone.setOutput("right",true)
- function findTargets()
- targets = {}
- numTargets = 0
- totalCap = 0
- for target in pairs(prox.getTargets()) do
- local details = prox.getTargetDetails(target)
- if details.Capacity == 10000000 or details.Capacity == 100000000 then
- numTargets = numTargets + 1
- targets[numTargets] = target
- totalCap = totalCap + details.Capacity
- end
- end
- formatCap = comma_value(totalCap)
- end
- function comma_value(amount)
- local formatted = amount
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then
- break
- end
- end
- return formatted
- end
- function clear()
- term.clear()
- term.setCursorPos (1,1)
- end
- function main()
- while run == true do
- local totalStored = 0
- local deadBats = 0
- for target = 1, numTargets do
- local details = prox.getTargetDetails(targets[target])
- totalStored = totalStored + details.Stored
- if details.Stored < 10000 then
- deadBats = deadBats + 1
- end
- end
- local formatStored = comma_value(totalStored)
- local energy = (totalStored / totalCap) * 100
- clear()
- print("# Batteries : " ..numTargets)
- print("Dead Batts : " ..deadBats)
- print("Tot Capacity: " ..formatCap.. " EU")
- print("Total Stored: " ..formatStored.. " EU")
- print("Energy Level: " ..energy.. "%")
- if redstone.getOutput("right") then
- print("Generators : OFF")
- else
- print("Generators : ON")
- end
- print()
- print("Press r to re-scan for batteries.")
- print("Press f to force the generators on.")
- print("Press o to force the generators off.")
- print("Press x to exit.")
- if pause == false then
- if energy < 50 or (deadBats / numTargets) > 0.5 then
- redstone.setOutput("right",false)
- end
- if energy > 95 then
- redstone.setOutput("right",true)
- end
- end
- sleep (4)
- end
- end
- function commands()
- while run == true do
- event, param = os.pullEvent("char")
- if param == "r" then
- clear()
- pause = true
- print("Re-scanning, please wait.")
- sleep(1)
- findTargets()
- pause = false
- elseif param == "f" then
- clear()
- print("You have forced the generators on.")
- sleep(1)
- redstone.setOutput("right",false)
- elseif param == "o" then
- clear()
- print("You have forced the generators off.")
- sleep(1)
- redstone.setOutput("right",true)
- elseif param == "x" then
- run = false
- end
- end
- end
- term.redirect(peripheral.wrap("left"))
- clear()
- print("Welcome to lava-backup! Please wait.")
- run = true
- pause = false
- findTargets()
- parallel.waitForAll(main, commands)
- clear()
- print("Good bye!")
Advertisement
Add Comment
Please, Sign In to add comment