Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[User Config]]
- local selfName = "Endoflame Controller" --Name to display at top of runtime
- local fuelBurnTime = 360 --How long to close output signal
- local fuelDropTime = 6.8 --How long to send output redstone signal
- local redstoneCompareSide = "right" --Which side to input redstone override to
- local redstoneOutputSide = "back" --Which side to output redstone control to
- local masterSwitch = true --True starts the machine in the ON state, false starts in the OFF state
- --[[]]
- local switch = true --False = currently dropping items, true = not dropping items
- local masterDict = {
- [true] = "Controller running.",
- [false] = "Controller paused. Manual control still available."
- }
- local dict = {
- [true] = "Burning fuel..",
- [false] = "Dropping fuel..",
- ["mana"] = "Mana full. Sleeping..."
- }
- local manaFull = rs.getInput(redstoneCompareSide)
- local burnTimer
- local dropTimer
- local function checkRedstoneState() --Used to verify redstone signal change
- local newState = rs.getInput(redstoneCompareSide)
- if newState ~= manaFull then --If the state has changed
- manaFull = newState
- return true
- end
- end
- local function draw(arg) --Handles updating screen during runtime
- if arg ~= nil then arg = switch end
- term.clear()
- term.setCursorPos(1,1)
- write(selfName)
- write("\n\n" .. masterDict[masterSwitch])
- write("\n\n" .. dict[arg])
- write("\n\n\nPress spacebar to drop fuel.\n\nPress T to toggle the controller on or off.")
- end
- local function dropManual()
- switch = false
- draw()
- rs.setOutput(redstoneOutputSide, false)
- end
- local function dropOn()
- switch = false
- draw()
- rs.setOutput(redstoneOutputSide, false)
- dropTimer = os.startTimer(fuelDropTime)
- end
- local function dropOff()
- switch = true
- draw(switch)
- rs.setOutput(redstoneOutputSide, true)
- burnTimer = os.startTimer(fuelBurnTime)
- end
- local function masterToggle()
- masterSwitch = not masterSwitch
- if masterSwitch and switch then
- dropOn()
- end
- end
- function Main()
- if burnTimer == nil and dropTimer == nil and masterSwitch then --if we are initializing after first startup, and toggled controller ON
- dropOn()
- end
- local event, param1 = os.pullEvent()
- if event == "redstone" and checkRedstoneState() then --if redstone is updated..
- if not manaFull then --and it's not full, then start dropTimer
- dropOn()
- else
- draw("mana") --otherwise display full message in runtime
- end
- elseif event == "timer" and param1 == burnTimer and masterSwitch then --if burnTimer ends and the controller is running
- dropOn()
- elseif event == "timer" and param1 == dropTimer and masterSwitch then --if dropTimer ends and the controller is running
- dropOff()
- elseif event == "key" and param1 == 57 then --if Spacebar is pressed
- dropManual()
- elseif event == "key" and param1 == 20 then --if T is pressed
- masterToggle()
- end
- Main()
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment