BigBlow_

MobFarm-Global-Controller

Mar 14th, 2025 (edited)
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.77 KB | None | 0 0
  1. -- Configuration des spawners (Liste 1 + Liste 2)
  2. local spawnersList1 = {
  3.     {id = 51, name = "Mob Mashers"},
  4.     {id = 52, name = "Mob Fans"},
  5.     {id = 53, name = "Lamps"},
  6.     {id = 56, name = "Dreadful Boost"},
  7.     {id = 54, name = "Void Mod"},
  8.     {id = 55, name = "Blood Cleaner"}
  9. }
  10.  
  11. local spawnersList2 = {
  12.     {id = 1, name = "Cave Creeper"},
  13.     {id = 2, name = "Blaze"},
  14.     {id = 3, name = "Ancient Knight"},
  15.     {id = 4, name = "Wither Skeleton"},
  16.     {id = 5, name = "Witch"},
  17.     {id = 6, name = "Cave Enderman"},
  18.     {id = 7, name = "Creeper"},
  19.     {id = 8, name = "Phantoms"},
  20.     {id = 9, name = "Drowned"},
  21.     {id = 10, name = "Deepling"},
  22.     {id = 11, name = "Slime"},
  23.     {id = 12, name = "Guardian"},
  24.     {id = 13, name = "Skeleton"},
  25.     {id = 14, name = "Evoker"}
  26. }
  27.  
  28. -- Liste des spawners actifs au demarrage exemple : {1, 2, 3, 5, 12}
  29. local activatedSpawners = {51, 52, 53, 55, 1}
  30.  
  31. -- Canal du modem (modifiable ici)
  32. local channel = 128 -- Change ce nombre pour choisir un autre canal
  33.  
  34. -- Timestamp pour les logs
  35. local function getTimestamp()
  36.     return os.date("%Y-%m-%d %H:%M:%S")
  37. end
  38.  
  39. -- Detection du modem et ecran
  40. local modem = peripheral.find("modem")
  41. if not modem then error("Aucun modem sans fil detecte") end
  42. modem.open(channel)
  43.  
  44. local mon = peripheral.find("monitor")
  45. if not mon then error("Aucun ecran detecte") end
  46. mon.setTextScale(1)
  47.  
  48. -- Etat des spawners
  49. local state = {}
  50. for _, s in ipairs(spawnersList1) do state[s.id] = false end
  51. for _, s in ipairs(spawnersList2) do state[s.id] = false end
  52.  
  53. -- Ecran de demarrage
  54. local function startupScreen()
  55.     mon.clear()
  56.     for i = 5, 0, -1 do
  57.         mon.setCursorPos(5, 3)
  58.         mon.setTextColor(colors.white)
  59.         mon.write("Demarrage dans " .. i)
  60.         mon.setCursorPos(5, 5)
  61.         mon.setTextColor(colors.yellow)
  62.         mon.write("[Passer]")
  63.         local timer = os.startTimer(1)
  64.         while true do
  65.             local event, side, x, y = os.pullEvent()
  66.             if event == "timer" and side == timer then break
  67.             elseif event == "monitor_touch" and x >= 5 and x <= 11 and y == 5 then return end
  68.         end
  69.     end
  70. end
  71.  
  72. -- Desactivation globale sauf liste active
  73. local function deactivateAllExceptActivated()
  74.     local function isActive(id)
  75.         for _, activeID in ipairs(activatedSpawners) do
  76.             if id == activeID then return true end
  77.         end
  78.         return false
  79.     end
  80.  
  81.     for _, s in ipairs(spawnersList1) do
  82.         if not isActive(s.id) then
  83.             modem.transmit(channel, channel, {id = s.id, state = false})
  84.             print(getTimestamp() .. " - ID " .. s.id .. " OFF")
  85.             os.sleep(0.1)
  86.         end
  87.     end
  88.     for _, s in ipairs(spawnersList2) do
  89.         if not isActive(s.id) then
  90.             modem.transmit(channel, channel, {id = s.id, state = false})
  91.             print(getTimestamp() .. " - ID " .. s.id .. " OFF")
  92.             os.sleep(0.1)
  93.         end
  94.     end
  95. end
  96.  
  97. -- Activation des spawners de la liste
  98. local function activateSpawnersOnStart()
  99.     for _, id in ipairs(activatedSpawners) do
  100.         modem.transmit(channel, channel, {id = id, state = true})
  101.         print(getTimestamp() .. " - ID " .. id .. " ON")
  102.         os.sleep(0.1)
  103.         state[id] = true
  104.     end
  105. end
  106.  
  107. -- Interface
  108. local function drawUI()
  109.     mon.clear()
  110.     mon.setTextColor(colors.white)
  111.     mon.setCursorPos(1, 1)
  112.     mon.write("System Control Panel :")
  113.  
  114.     for i, s in ipairs(spawnersList1) do
  115.         mon.setCursorPos(1, i + 2)
  116.         mon.setTextColor(colors.white)
  117.         mon.write(s.name)
  118.         mon.setCursorPos(20, i + 2)
  119.         if state[s.id] then
  120.             mon.setTextColor(colors.green)
  121.             mon.write("ON")
  122.         else
  123.             mon.setTextColor(colors.red)
  124.             mon.write("OFF")
  125.         end
  126.     end
  127.  
  128.     mon.setCursorPos(1, #spawnersList1 + 4)
  129.     mon.setTextColor(colors.white)
  130.     mon.write("Spawners Control Panel :")
  131.  
  132.     for i, s in ipairs(spawnersList2) do
  133.         mon.setCursorPos(1, i + #spawnersList1 + 5)
  134.         mon.setTextColor(colors.white)
  135.         mon.write(s.name)
  136.         mon.setCursorPos(20, i + #spawnersList1 + 5)
  137.         if state[s.id] then
  138.             mon.setTextColor(colors.green)
  139.             mon.write("ON")
  140.         else
  141.             mon.setTextColor(colors.red)
  142.             mon.write("OFF")
  143.         end
  144.     end
  145. end
  146.  
  147. -- Envoi d'une commande
  148. local function sendCommand(id, newState)
  149.     modem.transmit(channel, channel, {id = id, state = newState})
  150.     print(getTimestamp() .. " - ID " .. id .. " " .. (newState and "ON" or "OFF"))
  151.     os.sleep(0.1)
  152. end
  153.  
  154. -- Gestion clics sur l'ecran
  155. local function handleClick(x, y)
  156.     local index1 = y - 2
  157.     local index2 = y - (#spawnersList1 + 5)
  158.  
  159.     if spawnersList1[index1] then
  160.         local s = spawnersList1[index1]
  161.         state[s.id] = not state[s.id]
  162.         sendCommand(s.id, state[s.id])
  163.         drawUI()
  164.     elseif spawnersList2[index2] then
  165.         local s = spawnersList2[index2]
  166.         state[s.id] = not state[s.id]
  167.         sendCommand(s.id, state[s.id])
  168.         drawUI()
  169.     end
  170. end
  171.  
  172. -- Reception messages modem
  173. local function listenForMessages()
  174.     while true do
  175.         local _, _, _, _, msg = os.pullEvent("modem_message")
  176.         if msg and msg.id and msg.state ~= nil then
  177.             state[msg.id] = msg.state
  178.             print(getTimestamp() .. " - Recu <- ID " .. msg.id .. " " .. (msg.state and "ON" or "OFF"))
  179.             drawUI()
  180.         end
  181.     end
  182. end
  183.  
  184. -- Lancement
  185. startupScreen()
  186. deactivateAllExceptActivated()
  187. activateSpawnersOnStart()
  188. drawUI()
  189.  
  190. -- Execution parallele
  191. parallel.waitForAny(listenForMessages, function()
  192.     while true do
  193.         local event, side, x, y = os.pullEvent("monitor_touch")
  194.         handleClick(x, y)
  195.     end
  196. end)
  197.  
Advertisement
Add Comment
Please, Sign In to add comment