Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local REACTOR_AT = "back"
- local SHUTDOWN_AT = 90.0
- local ACTIVATE_AT = 10.0
- local RF_MAX = 10000000 -- maximum power the reactor can store
- print "Activating reactor control..."
- local reactor = peripheral.wrap(REACTOR_AT)
- if (not reactor) then
- print("No reactor found at ", REACTOR_AT, "!")
- return
- end
- local getStoragePercent = function()
- return reactor.getEnergyStored() / RF_MAX * 100.0
- end
- local printReactorState = function()
- print(string.format("Reactor %s at %3.2f%% storage", (reactor.getActive() and "enabled") or "disabled", getStoragePercent()))
- end
- local setActive = function(active)
- if (reactor.getActive() ~= active) then
- reactor.setActive(active)
- printReactorState()
- end
- end
- printReactorState()
- local storage
- while true do
- if (reactor.getConnected()) then
- storage = getStoragePercent()
- if (storage <= ACTIVATE_AT) then
- setActive(true)
- elseif (storage >= SHUTDOWN_AT) then
- setActive(false)
- end
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement