Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local keyboard = require("keyboard")
- local event = require("event")
- local gpu = component.gpu
- local reactor = component.br_reactor
- -- defninitions
- reactor["stats"] = {}
- local running = true
- local maxRF = 75
- local minRF = 25
- local currentRF = 0
- local maxRFStorage = 10000000
- -- functions
- function toint(n)
- local s = tostring(n)
- local i, j = s:find('%.')
- if i then
- return tonumber(s:sub(1, i-1))
- else
- return n
- end
- end
- function getInfoFromReactor()
- local reactorEnergyStats = reactor.getEnergyStats()
- local reactorFuelStats = reactor.getFuelStats()
- reactorRodsLevel = reactor.getControlRodsLevels()
- -- reactor.stats["tick"] = toint(math.ceil(reactorEnergyStats["energyProducedLastTick"]))
- reactor.stats["stored"] = toint(reactorEnergyStats["energyStored"])
- -- reactor.stats["rods"] = toint(reactorRodsLevel[0])
- -- reactor.stats["fuel"] = round(reactorFuelStats["fuelConsumedLastTick"], 2)
- currentRf = (reactor.stats["stored"] * 100) / maxRFStorage
- end
- function powerOn()
- reactor.setActive(true)
- end
- function powerOff()
- reactor.setActive(false)
- end
- -- helpers
- function round(val, decimal)
- if (decimal) then
- return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
- else
- return math.floor(val+0.5)
- end
- end
- function init()
- powerOn()
- running = true
- getInfoFromReactor()
- print("Initialisation...")
- end
- function showInfos()
- os.execute("clear")
- print("Actualisation des informations tout les 5 seconds")
- if (running) then
- print("Etat du reactor : Marche")
- else
- print("Etat du reactor : Arret")
- end
- print("Energie Actuel : " .. currentRF .. "%")
- end
- function process()
- while event.pull(0.1, "interrupted") == nil do
- print(currentRF)
- if (running and currentRF >= maxRF) then
- powerOff()
- running = false
- end
- if (not(running) and currentRF <= minRF) then
- powerOn()
- running = true
- end
- showInfos()
- os.sleep(5)
- end
- end
- function finish()
- powerOff()
- running = false
- print('Finish.')
- end
- init()
- process()
- finish()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement