Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactor = peripheral.find("BigReactors-Reactor")
- local maximum = 100000000 -- subtracted from max
- local minimum = 500000000 -- subtracted from max
- local storage_id = RECIPIENT_ALL
- local last_req = true
- CreateTimer(function()
- if reactor then
- if last_req then
- local active = reactor.getActive()
- if active then
- reactor.setActive(false)
- Log("Disabled reactor")
- end
- end
- last_req = true
- SendMessage("REQ_EN", storage_id, nil)
- end
- end, 3, true)
- OnEvent(function(event, side)
- if not reactor and peripheral.getType(side) == "BigReactors-Reactor" then
- reactor = peripheral.wrap(side)
- Log("Reactor attached")
- end
- end, "peripheral")
- OnMessage(function(id, recipient, sender, data)
- if reactor then
- local active = reactor.getActive()
- if data.max - data.stored <= maximum then
- if active then
- reactor.setActive(false)
- Log("Disabled reactor")
- end
- elseif data.max - data.stored >= minimum then
- if not active then
- reactor.setActive(true)
- Log("Enabled reactor")
- end
- end
- end
- last_req = false
- end, "RES_EN")
- OnMessage(function(id, recipient, sender, data)
- if reactor then
- reactor.setActive(not not data)
- if data then
- Log("Enabled reactor")
- else
- Log("Disabled reactor")
- end
- end
- last_req = false
- end, "REACT_SET")
- OnEvent(function(event, side)
- if reactor and peripheral.getType(side) == "BigReactors-Reactor" then
- reactor = nil
- Log("Reactor detached")
- end
- end, "peripheral_detach")
Add Comment
Please, Sign In to add comment