Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function periphSearch(type)
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == type and name ~= "right" then
- return peripheral.wrap(name)
- end
- end
- return null
- end
- -- notes
- -- It doesn't really know what to do if it should be charging but the reactor is taking more than it gives.
- -- It'll kind of naturally stop the gate, but the display is weird
- -- functions end
- -- peripheral setup start
- monitor = peripheral.wrap("top")
- if monitor == null then
- monitor = periphSearch("monitor")
- end
- if monitor ~= null then
- term.redirect(monitor)
- end
- gate1 = peripheral.wrap("back")
- core1 = periphSearch("draconic_rf_storage")
- -- peripheral end
- -- variables
- local energy, maxenergy, perenergy, transfer, state
- --main loop start
- while true do
- sleep(1)
- energy = core1.getEnergyStored()
- maxenergy = core1.getMaxEnergyStored()
- perenergy = math.floor(energy / maxenergy * 100)
- term.clear()
- if perenergy < 50 then
- gate1.setSignalLowFlow(0)
- print("Reactor buffer below 50%. Stopping flow to public.")
- print("Setting gate to ",gate1.getSignalLowFlow())
- elseif perenergy >= 90 then
- gate1.setSignalLowFlow(core1.getTransferPerTick() + gate1.getSignalLowFlow() + 1000)
- print("Core is near full. Draining a bit.")
- print("Current net rate is: ", core1.getTransferPerTick())
- print("Setting gate to ",gate1.getSignalLowFlow())
- elseif core1.getTransferPerTick() == 0 then
- gate1.setSignalLowFlow(0)
- print("It seems like the core isn't getting energy. Clamping output")
- print("Setting gate to ",gate1.getSignalLowFlow())
- elseif perenergy > 80 and perenergy <= 90 then
- print("Core is bouncing between 80-90% so it doesn't just go crazy.")
- print("Core percent full: ",perenergy,"%")
- print("Core rate: ",core1.getTransferPerTick())
- print("Gate Rate: ",gate1.getSignalLowFlow())
- elseif perenergy >= 50 then
- gate1.setSignalLowFlow(core1.getTransferPerTick() + gate1.getSignalLowFlow() - 1000)
- print("Core is filling up. Trying to get the current rate to 1kRF")
- print("Current rate is: ", core1.getTransferPerTick())
- print("Setting gate to ",gate1.getSignalLowFlow())
- else
- print("I don't know how to react to the current state. Complain to Koriar.")
- print("Core percent full: ",perenergy,"%")
- print("Core rate: ",core1.getTransferPerTick())
- print("Gate Rate: ",gate1.getSignalLowFlow())
- end
- end
- --main loop end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement