Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getDevices(deviceType)
- local deviceName = nil
- local deviceIndex = 1
- local deviceList, deviceNames = {}, {}
- local peripheralList = peripheral.getNames()
- deviceType = deviceType:lower()
- for peripheralIndex = 1, #peripheralList do
- if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then
- -- write("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] as index \"["..deviceIndex.."]\" attached as \""..peripheralList[peripheralIndex].."\".\n")
- deviceNames[deviceIndex] = peripheralList[peripheralIndex]
- deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
- deviceIndex = deviceIndex + 1
- end
- end
- return deviceList, deviceNames
- end
- function energyStorage(numCapacitors)
- energyBank, energyNames = getDevices("tile_blockcapacitorbank_name")
- for bankIndex = 1, #energyBank do
- capacitor = energyBank[bankIndex]
- if not capacitor then
- table.remove(energyBank, bankIndex)
- if bankIndex ~= #energyBank then
- bankIndex = bankIndex - 1
- end
- return math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored()) * 100)
- end
- print("Capacitor Bank "..bankIndex)
- print("Current RF: "..capacitor.getEnergyStored() * numCapacitors)
- print("Max RF : "..capacitor.getMaxEnergyStored() * numCapacitors)
- print("Percentage: "..math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored()) * 100).."%")
- end
- return math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored()) * 100)
- end
- function turbines(engPct)
- turbineBank, turbineNames = getDevices("BigReactors-Turbine")
- for bankIndex = 1, #turbineBank do
- turbine = turbineBank[bankIndex]
- if not turbine then
- table.remove(turbineBank, bankIndex)
- if bankIndex ~= #turbineBank then
- bankIndex = bankIndex - 1
- end
- return powerNeeded
- end
- turbineSpeed = turbine.getRotorSpeed()
- if turbineSpeed < 1800 then
- turbine.setActive(true)
- powerNeeded = true
- else
- turbine.setActive(false)
- end
- if engPct < 15 then
- turbine.setInductorEngaged(true)
- powerNeeded = true
- elseif engPct > 98 then
- turbine.setInductorEngaged(false)
- end
- if turbine.getActive() == true then
- state = "Online"
- else
- state = "Offline"
- end
- if turbine.getInductorEngaged() == true then
- inductor = "Generating"
- else
- inductor = "Not Generating"
- end
- print("Turbine "..bankIndex.." is "..state.." and "..inductor..".")
- end
- return powerNeeded
- end
- function reactor(powerNeeded)
- reactorBank, reactorNames = getDevices("BigReactors-Reactor")
- for bankIndex = 1, #reactorBank do
- reactor = reactorBank[bankIndex]
- if not reactor then
- table.remove(reactorBank, bankIndex)
- if bankIndex ~= #reactorBank then
- bankIndex = bankIndex - 1
- end
- return
- end
- if powerNeeded == true then
- reactor.setActive(true)
- print("Reactor Online")
- else
- reactor.setActive(false)
- print("Reactor Offline")
- end
- end
- return
- end
- while true do
- bankIndex = 1
- term.clear()
- numCapacitors = 3 --enter the number of capacitors in your storage ba
- engPct = nil
- powerNeeded = false
- engPct = energyStorage(numCapacitors)
- powerNeeded = turbines(engPct)
- holder = reactor(powerNeeded)
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment