Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function wrapPeripherals()
- local attachedReactor = peripheral.find("BigReactors-Reactor")
- local attachedCubes = {}
- for k,v in pairs(peripheral.getNames()) do
- if string.sub(peripheral.getType(v),-11) == "energy_cube" then
- table.insert(attachedCubes,peripheral.wrap(v))
- end
- end
- return attachedReactor, attachedCubes
- end
- local reactor, cubes = wrapPeripherals()
- --[[if not reactor then
- print("No Reactor Computer Port found!")
- return
- end
- if not cubes[1] then
- print("No energy cube found!")
- return
- end
- if not reactor.getConnected() then
- print("No valid reactor connected!")
- return
- end--]]
- local function checkReactor()
- if not reactor.getConnected() then
- repeat
- print("Connected reactor invalid! Please rectify and press any key to continue.")
- os.pullEvent("key")
- until reactor.getConnected()
- return true
- end
- end
- local function checkPeripherals()
- reactor, cubes = wrapPeripherals()
- if not reactor or not cubes[1] then
- print("Peripheral missing! Please ensure that both a Reactor Computer Port and an energy cube are attached to continue operation.")
- repeat
- os.pullEvent()
- reactor, cubes = wrapPeripherals()
- until reactor and cubes[1]
- checkReactor()
- print("Peripherals attached. Resuming normal operation.")
- end
- end
- local function addCubes(cubesTable,getMax)
- local val = 0
- for k,v in pairs(cubesTable) do
- if getMax then
- val = val + v.getMaxEnergyStored("")
- else
- val = val + v.getEnergyStored("")
- end
- end
- return val
- end
- local timer
- local eventParamters
- while true do
- if addCubes(cubes,false) < addCubes(cubes,true) and not reactor.getActive() then
- reactor.setActive(true)
- elseif addCubes(cubes,false) == addCubes(cubes,true) and reactor.getActive() then
- reactor.setActive(false)
- end
- timer = os.startTimer(1)
- repeat
- eventParameters = {os.pullEvent()}
- until (eventParameters[1] == "timer" and eventParameters[2] == timer) or string.sub(eventParameters[1],1,10) == "peripheral"
- if string.sub(eventParameters[1],1,10) == "peripheral" then
- checkPeripherals()
- end
- if checkReactor() then
- print("Resuming normal operation.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement