robocyclone

endoflame controller.lua

Apr 7th, 2023
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. --[[User Config]]
  2. local selfName = "Endoflame Controller"
  3. local fuelBurnTime = 360
  4. local fuelDropTime = 6.8
  5. local redstoneCompareSide = "right"
  6. local redstoneOutputSide = "back"
  7. --[[]]
  8.  
  9. local masterSwitch = false
  10. local switch = false
  11. local dict = {
  12.     [true] = "Burning fuel..",
  13.     [false] = "Dropping fuel..",
  14.     ["mana"] = "Mana full. Sleeping..."
  15. }
  16. local manaFull = rs.getInput(redstoneCompareSide)
  17. local burnTimer
  18. local dropTimer
  19.  
  20. local function checkRedstoneState()
  21.     local newState = rs.getInput(redstoneCompareSide)
  22.     if newState ~= manaFull then --If the state has changed
  23.         manaFull = newState
  24.         return true
  25.     end
  26. end
  27.  
  28. local function toggle()
  29.     masterSwitch = not masterSwitch
  30. end
  31.  
  32. local function draw(arg)
  33.     term.clear()
  34.     term.setCursorPos(1,1)
  35.     write(selfName)
  36.     write("\n\n" .. dict[arg])
  37.     write("\n\n\n Press spacebar to drop fuel no matter the conditions, and T to toggle the controller on or off.")
  38. end
  39.  
  40. local function dropManual()
  41.     switch = false
  42.     draw(switch)
  43.     rs.setOutput(redstoneOutputSide, false)
  44. end
  45.  
  46. local function dropOn()
  47.     switch = false
  48.     draw(switch)
  49.     rs.setOutput(redstoneOutputSide, false)
  50.     dropTimer = os.startTimer(fuelDropTime)
  51. end
  52.  
  53. local function dropOff()
  54.     switch = true
  55.     draw(switch)
  56.     rs.setOutput(redstoneOutputSide, true)
  57.     burnTimer = os.startTimer(fuelBurnTime)
  58. end
  59.  
  60. function EventHandler()
  61.     local event, param1 = os.pullEvent()
  62.     if event == "redstone" and checkRedstoneState() then
  63.         if not manaFull then
  64.             dropOn()
  65.         else
  66.             draw("mana")
  67.         end
  68.     elseif event == "timer" and param1 == burnTimer and masterSwitch then
  69.         dropOn()
  70.     elseif event == "timer" and param1 == dropTimer and masterSwitch then
  71.         dropOff()
  72.     elseif event == "key" and param1 == 57 then
  73.         dropManual()
  74.     elseif event == "key" and param1 == 20 then
  75.         toggle()
  76.     end
  77.     Main()
  78. end
  79.  
  80. function Main()
  81.     draw(switch)
  82.     EventHandler()
  83. end
  84. Main()
  85.  
Advertisement
Add Comment
Please, Sign In to add comment