zootsuitman

Spawner Control

Nov 7th, 2023 (edited)
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local spawners = {"Cow", "Evoker", "Witch", "Blaze", "Enderman", "Spider", "Ghast"}
  2. local controlColors = {
  3.   colors.white,
  4.   colors.orange,
  5.   colors.magenta,
  6.   colors.lightBlue,
  7.   colors.yellow,
  8.   colors.lime,
  9.   colors.pink,
  10.   colors.gray
  11. }
  12. local activeMap = {}
  13. for i=1, #spawners+1 do
  14.   activeMap[i] = false
  15. end
  16. activeMap[#spawners+1] = true
  17.  
  18. local monitor = peripheral.wrap("right")
  19.  
  20. function check(active)
  21.   if active then return "[O]" else return "[ ]" end
  22. end
  23.  
  24. function checkAllActive()
  25.   local aa = true
  26.   for i=1, #spawners do
  27.     aa = aa and activeMap[i]
  28.   end
  29.   return aa
  30. end
  31.  
  32. function updateUi()
  33.   monitor.clear()
  34.   monitor.setTextScale(0.5)
  35.   monitor.setCursorPos(1,1)
  36.   monitor.write(" Spawn Control")
  37.  
  38.   monitor.setCursorPos(1,3)
  39.   monitor.write(check(activeMap[#spawners+1]) .. " Grinders")
  40.  
  41.   for i, monster in ipairs(spawners) do
  42.     monitor.setCursorPos(1, i*2+6)
  43.     monitor.write(check(activeMap[i]) .. " " .. monster)
  44.   end
  45.  
  46.   monitor.setCursorPos(1, 6)
  47.   monitor.write(check(checkAllActive()) .. " All")
  48. end
  49.  
  50. function handleAllClick()
  51.   local isAllActive = not checkAllActive()
  52.   for i=1, #spawners do
  53.     activeMap[i] = isAllActive
  54.   end
  55. end
  56.  
  57. function updateOutput()
  58.   local activeColors = {}
  59.   for i, active in ipairs(activeMap) do
  60.     if active then table.insert(activeColors, controlColors[i]) end
  61.   end
  62.  
  63.   rs.setBundledOutput("left", colors.combine(unpack(activeColors)))
  64. end
  65.  
  66. updateUi()
  67. updateOutput()
  68.  
  69. while true do
  70.   local _, _, _, y = os.pullEvent("monitor_touch")
  71.  
  72.   if y == 3 then activeMap[#spawners+1] = not activeMap[#spawners+1] end
  73.   if y == 6 then handleAllClick() end
  74.  
  75.   local item = (y - 6) / 2
  76.   if math.floor(item) == item and item <= #spawners then activeMap[item] = not activeMap[item] end
  77.  
  78.   updateUi()
  79.   updateOutput()
  80. end
  81.  
Advertisement
Add Comment
Please, Sign In to add comment