Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration des spawners (Liste 1 + Liste 2)
- local spawnersList1 = {
- {id = 51, name = "Mob Mashers"},
- {id = 52, name = "Mob Fans"},
- {id = 53, name = "Lamps"},
- {id = 54, name = "Void Mod"},
- {id = 55, name = "Blood Cleaner"}
- }
- local spawnersList2 = {
- {id = 1, name = "Cave Creeper"},
- {id = 2, name = "Blaze"},
- {id = 3, name = "Ancient Knight"},
- {id = 4, name = "Enderman"},
- {id = 5, name = "Witch"},
- {id = 6, name = "Cave Enderman"},
- {id = 7, name = "Creeper"},
- {id = 8, name = "Wither Skeleton"},
- {id = 9, name = "Drowned"},
- {id = 10, name = "Deepling"},
- {id = 11, name = "Slime"},
- {id = 12, name = "Magma Slime"},
- {id = 13, name = "Skeleton"},
- {id = 14, name = "Evoker"}
- }
- -- Liste des spawners actifs au demarrage
- local activatedSpawners = {51, 52, 53, 55}
- -- Canal du modem (modifiable ici)
- local channel = 128 -- Change ce nombre pour choisir un autre canal
- -- Timestamp pour les logs
- local function getTimestamp()
- return os.date("%Y-%m-%d %H:%M:%S")
- end
- -- Detection du modem et ecran
- local modem = peripheral.find("modem")
- if not modem then error("Aucun modem sans fil detecte") end
- modem.open(channel)
- local mon = peripheral.find("monitor")
- if not mon then error("Aucun ecran detecte") end
- mon.setTextScale(1)
- -- Etat des spawners
- local state = {}
- for _, s in ipairs(spawnersList1) do state[s.id] = false end
- for _, s in ipairs(spawnersList2) do state[s.id] = false end
- -- Ecran de demarrage
- local function startupScreen()
- mon.clear()
- for i = 5, 0, -1 do
- mon.setCursorPos(5, 3)
- mon.setTextColor(colors.white)
- mon.write("Demarrage dans " .. i)
- mon.setCursorPos(5, 5)
- mon.setTextColor(colors.yellow)
- mon.write("[Passer]")
- local timer = os.startTimer(1)
- while true do
- local event, side, x, y = os.pullEvent()
- if event == "timer" and side == timer then break
- elseif event == "monitor_touch" and x >= 5 and x <= 11 and y == 5 then return end
- end
- end
- end
- -- Desactivation globale sauf liste active
- local function deactivateAllExceptActivated()
- local function isActive(id)
- for _, activeID in ipairs(activatedSpawners) do
- if id == activeID then return true end
- end
- return false
- end
- for _, s in ipairs(spawnersList1) do
- if not isActive(s.id) then
- modem.transmit(channel, channel, {id = s.id, state = false})
- print(getTimestamp() .. " - ID " .. s.id .. " OFF")
- os.sleep(0.1)
- end
- end
- for _, s in ipairs(spawnersList2) do
- if not isActive(s.id) then
- modem.transmit(channel, channel, {id = s.id, state = false})
- print(getTimestamp() .. " - ID " .. s.id .. " OFF")
- os.sleep(0.1)
- end
- end
- end
- -- Activation des spawners de la liste
- local function activateSpawnersOnStart()
- for _, id in ipairs(activatedSpawners) do
- modem.transmit(channel, channel, {id = id, state = true})
- print(getTimestamp() .. " - ID " .. id .. " ON")
- os.sleep(0.1)
- state[id] = true
- end
- end
- -- Interface
- local function drawUI()
- mon.clear()
- mon.setTextColor(colors.white)
- mon.setCursorPos(1, 1)
- mon.write("System Control Panel :")
- for i, s in ipairs(spawnersList1) do
- mon.setCursorPos(1, i + 2)
- mon.setTextColor(colors.white)
- mon.write(s.name)
- mon.setCursorPos(20, i + 2)
- if state[s.id] then
- mon.setTextColor(colors.green)
- mon.write("ON")
- else
- mon.setTextColor(colors.red)
- mon.write("OFF")
- end
- end
- mon.setCursorPos(1, #spawnersList1 + 4)
- mon.setTextColor(colors.white)
- mon.write("Spawners Control Panel :")
- for i, s in ipairs(spawnersList2) do
- mon.setCursorPos(1, i + #spawnersList1 + 5)
- mon.setTextColor(colors.white)
- mon.write(s.name)
- mon.setCursorPos(20, i + #spawnersList1 + 5)
- if state[s.id] then
- mon.setTextColor(colors.green)
- mon.write("ON")
- else
- mon.setTextColor(colors.red)
- mon.write("OFF")
- end
- end
- end
- -- Envoi d'une commande
- local function sendCommand(id, newState)
- modem.transmit(channel, channel, {id = id, state = newState})
- print(getTimestamp() .. " - ID " .. id .. " " .. (newState and "ON" or "OFF"))
- os.sleep(0.1)
- end
- -- Gestion clics sur l'ecran
- local function handleClick(x, y)
- local index1 = y - 2
- local index2 = y - (#spawnersList1 + 5)
- if spawnersList1[index1] then
- local s = spawnersList1[index1]
- state[s.id] = not state[s.id]
- sendCommand(s.id, state[s.id])
- drawUI()
- elseif spawnersList2[index2] then
- local s = spawnersList2[index2]
- state[s.id] = not state[s.id]
- sendCommand(s.id, state[s.id])
- drawUI()
- end
- end
- -- Reception messages modem
- local function listenForMessages()
- while true do
- local _, _, _, _, msg = os.pullEvent("modem_message")
- if msg and msg.id and msg.state ~= nil then
- state[msg.id] = msg.state
- print(getTimestamp() .. " - Recu <- ID " .. msg.id .. " " .. (msg.state and "ON" or "OFF"))
- drawUI()
- end
- end
- end
- -- Lancement
- startupScreen()
- deactivateAllExceptActivated()
- activateSpawnersOnStart()
- drawUI()
- -- Execution parallele
- parallel.waitForAny(listenForMessages, function()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- handleClick(x, y)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement