Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURATION
- local leverSide = "front" -- Side of the real lever (physical lever on the computer)
- local relayRedstoneSide = "right" -- Side of redstone input on the relays
- local loopDelay = 1.0 -- Delay between each loop in seconds
- -- VARIABLES
- local redstoneRelays = {}
- local reactor = nil
- -- SCAN
- local function scanPeripherals()
- redstoneRelays = {}
- reactor = peripheral.find("fissionReactorLogicAdapter")
- if reactor then
- print("Reactor detected")
- else
- print("Error: reactor not found")
- end
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name) == "redstone_relay" then
- table.insert(redstoneRelays, peripheral.wrap(name))
- end
- end
- if #redstoneRelays == 0 then
- print("Warning: no relays found")
- end
- end
- -- CHECK INPUTS
- local function isLeverOn()
- return redstone.getInput(leverSide)
- end
- local function isAnyRelayPowered()
- for _, relay in ipairs(redstoneRelays) do
- if relay.getInput(relayRedstoneSide) then
- return true
- end
- end
- return false
- end
- -- CONTROL
- local function controlReactor(leverOn, relayPowered)
- local status = reactor.getStatus()
- if not leverOn then
- -- Lever is OFF: force SCRAM
- if status then
- print("SCRAM: Lever OFF")
- reactor.scram()
- end
- elseif relayPowered then
- -- Lever is ON and relay active: activate reactor
- if not status then
- print("ACTIVATE: Redstone signal")
- reactor.activate()
- end
- else
- -- Lever is ON but no redstone: SCRAM
- if status then
- print("SCRAM: No redstone")
- reactor.scram()
- end
- end
- end
- -- MAIN LOOP
- local function main()
- scanPeripherals()
- if not reactor then return end
- while true do
- local leverOn = isLeverOn()
- local relayPowered = isAnyRelayPowered()
- print(string.format("Lever: %s | Redstone: %s | Reactor: %s",
- leverOn and "ON" or "OFF",
- relayPowered and "ON" or "OFF",
- reactor.getStatus() and "ACTIVE" or "SCRAM"))
- controlReactor(leverOn, relayPowered)
- sleep(loopDelay)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement