Advertisement
robocyclone

wither skele farm.lua

Apr 2nd, 2023
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. --[[USER CONFIG VARIABLES]]
  2.  
  3. MONITOR_NAME = "monitor_0" --gathered by using a wired modem; alternatively, directly connect the monitor to the computer
  4. WITHER_OFF_TIME = 5 --in seconds; how long the cooldown is before spawner turns on
  5. WITHER_ON_TIME = 10 --in seconds; how long the spawner stays on per cycle
  6. RS_OUT = "right" --string relative side
  7. START_ON = true
  8.  
  9. --[[----------------------------------------------------------------]]
  10.  
  11. local monitor = peripheral.wrap(MONITOR_NAME) --Initialize monitor
  12.  
  13. if not monitor then --Check if monitor is wired, adjacent, or missing
  14.     monitor = peripheral.find("monitor")
  15.     if not monitor then
  16.         error("Monitor not found! Double check peripheral name.")
  17.     end
  18. end
  19.  
  20.  
  21.  
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. term.write("Running!") --Give an output to computer before swapping print output to monitor
  25.  
  26. term.redirect(monitor)
  27. local switch = START_ON
  28. local userSwitch = START_ON
  29. rs.setOutput(RS_OUT, switch)
  30. local eng = {[true] = "Running", [false] = "OFF"} --Used to translate bools to ON/OFF for user readability
  31. local offTimer = os.startTimer(WITHER_ON_TIME)
  32. local onTimer --to be initialized later
  33.  
  34. local function termDraw()
  35.     term.clear()
  36.     term.setCursorPos(1,1)
  37.     write("Wither Skeleton Farm")
  38.     term.setCursorPos(4, 4)
  39.     write("\n STATUS: " .. eng[switch])
  40. end
  41.  
  42. function Main() --Event handling and loop
  43.     termDraw()
  44.     rs.setOutput(RS_OUT, switch)
  45.     while true do
  46.         local e, p = os.pullEvent()
  47.         if e == "timer" and p == offTimer then
  48.             if switch and userSwitch then
  49.                 switch = false
  50.                 onTimer = os.startTimer(WITHER_OFF_TIME)
  51.                 Main()
  52.             end
  53.         elseif e == "timer" and p == onTimer then
  54.             if not switch and userSwitch then
  55.                 switch = true
  56.                 offTimer = os.startTimer(WITHER_ON_TIME)
  57.                 Main()
  58.             end
  59.         elseif e == "monitor_touch" then
  60.             switch = not switch
  61.             userSwitch = switch
  62.             Main()
  63.         end
  64.     end
  65. end
  66. Main()
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement