Script Lua Evento Zumbi WizarD TeaM Emulator - Source Mu - Mu Server Files
 

Script Lua Evento Zumbi WizarD TeaM Emulator

Publicado por Dakosmu, Nov 23, 2025, 11:28 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Dakosmu

Script Lua Evento Zumbi WizarD TeaM Emulator

Testado na Versão Season 1

Para Funcionar Crie os comandos no CommandManager.txt
   30      1   1   1   1     "/zumbi"         0        *         *          *          *          *          0           0           0           0
   139     1   1   1   1     "/startzumbi"     0        32        *          *          *          *          0           0           0           0

Configure a tabela da Moeda no meu caso criei a coluna WCoinC no MEMB_INFO
Configure o Local onde será o evento
Configure o Tempo do evento e a premiação


-- =============================================================================
-- # WizarD TeaM Emulator
-- # Evento de Infecção Zumbi
-- # /startzumbi - Inicia o evento (GM)
-- # /zumbi - Entra no evento (Player) (commandCode = 30)
-- =============================================================================

-- Anexa as funções aos eventos do servidor
BridgeFunctionAttach('OnCommandManager', 'Zumbi_OnCommandManager')
BridgeFunctionAttach('OnTimerThread', 'Zumbi_OnTimer')
BridgeFunctionAttach('OnUserDie', 'Zumbi_OnUserDie')
BridgeFunctionAttach('OnCharacterClose', 'Zumbi_OnCharacterClose')

LogColor(2, "[EventoZumbi] Script de Infecção Zumbi carregado.")

-- =============================================================================
-- CONFIGURAÇÕES DO EVENTO
-- =============================================================================

-- Comandos
local gmCommandCode = 139 -- Comando para o GM iniciar o evento.
local playerCommand = 30 -- Comando para o jogador entrar no evento.

-- Configurações de tempo (em segundos)
local announcementDuration = 60 -- 60 segundos para anunciar
local eventDuration = 300       -- 300 segundos (5 minutos) de evento

-- Recompensas
local zombieZeroReward = 100 -- WCoinC para o zumbi inicial se todos forem infectados
local survivorReward = 10    -- WCoinC para cada sobrevivente

-- Localização do Evento
local eventMap = 6     -- Stadium
local eventCoordX = 110
local eventCoordY = 156

-- Skin do Zumbi
local monsterSkinId = 55 -- ID do monstro que será usado como skin para os infectados

-- =============================================================================
-- LÓGICA DO SCRIPT (NÃO ALTERAR ABAIXO)
-- =============================================================================

-- Tabela para gerenciar o estado do evento
local eventState = {
    status = "IDLE", -- IDLE, ANNOUNCING, RUNNING, ENDING, CLEANUP, CANCELING
    timer = 0,
    participants = {},
    infected = {},
    zombieZero = nil,
    gmStarter = -1
}

-- Função para resetar o estado do evento
function ResetEventState()
    -- Reverte a skin de todos os participantes para a original
    for pIndex, _ in pairs(eventState.participants) do
        if GetObjectConnected(pIndex) > 0 then
            SkinChangeSend(pIndex, -1) -- -1 reverte para a skin original
        end
    end

    eventState.status = "IDLE"
    eventState.timer = 0
    eventState.participants = {}
    eventState.infected = {}
    eventState.zombieZero = nil
    eventState.gmStarter = -1
    LogColor(2, "[EventoZumbi] Estado do evento resetado.")
end

-- Gerenciador de Comandos
function Zumbi_OnCommandManager(aIndex, code, arg1, arg2)
    -- Comando do GM para iniciar o evento
    if code == gmCommandCode then
        if eventState.status ~= "IDLE" then
            NoticeSend(aIndex, 1, "Um evento zumbi já está em andamento.")
            return 1, 0
        end

        eventState.status = "ANNOUNCING"
        eventState.timer = announcementDuration
        eventState.gmStarter = aIndex
        NoticeSendToAll(0, string.format("Atenção! O Evento de Infecção Zumbi começará em %.0f segundos!", announcementDuration))
        NoticeSendToAll(0, "Use o comando /zumbi para participar!")
        LogColor(2, "[EventoZumbi] Evento iniciado pelo GM: " .. GetObjectName(aIndex))
        return 1, 0
    end

    -- Comando do jogador para entrar no evento
    if code == playerCommand then
        if eventState.status ~= "ANNOUNCING" then
            NoticeSend(aIndex, 1, "Não há um evento zumbi aberto para inscrições no momento.")
            return 1, 0
        end

        -- Verifica se o jogador já está participando ou infectado
        if eventState.participants[aIndex] or eventState.infected[aIndex] then
            NoticeSend(aIndex, 1, "Você já está participando do evento.")
            return 1, 0
        end

        -- Move o jogador para a arena do evento
        MoveUserEx(aIndex, eventMap, eventCoordX, eventCoordY)
        eventState.participants[aIndex] = true
        NoticeSend(aIndex, 0, "Você entrou no Evento de Infecção Zumbi! Esconda-se!")
        LogColor(2, string.format("[EventoZumbi] Jogador '%s' entrou no evento.", GetObjectName(aIndex) or "N/A"))
        return 1, 0
    end

    return 0, 0
end

-- Função executada a cada segundo
function Zumbi_OnTimer()
    if eventState.status == "IDLE" then
        return
    end

    eventState.timer = eventState.timer - 1

    -- Anuncia contagem regressiva para o início do evento
    if eventState.status == "ANNOUNCING" and eventState.timer > 0 and (eventState.timer == 30 or eventState.timer == 10) then
        NoticeSendToAll(0, string.format("O Evento Zumbi começará em %d segundos! Use /zumbi para entrar!", eventState.timer))
    end

    if eventState.status == "ANNOUNCING" then
        if eventState.timer <= 0 then
            local participantCount = 0
            local participantIndexes = {}
            for pIndex, _ in pairs(eventState.participants) do
                participantCount = participantCount + 1
                table.insert(participantIndexes, pIndex)
            end
            -- Verifica se o número de participantes é menor que 2
            if participantCount < 2 then
                eventState.status = "CANCELING" -- Impede a repetição da mensagem
                NoticeSendToAll(0, "Evento Zumbi cancelado. Não houve participantes suficientes.")
                LogColor(1, "[EventoZumbi] Evento cancelado por falta de jogadores.")
                ResetEventState()
                return
            end

            eventState.status = "RUNNING"
            eventState.timer = eventDuration

            -- Escolhe o Zumbi Zero aleatoriamente
            local randomIndex = math.random(1, participantCount)
            local zombieZeroIndex = participantIndexes[randomIndex]
            eventState.zombieZero = zombieZeroIndex
            eventState.infected[zombieZeroIndex] = true
            SkinChangeSend(zombieZeroIndex, monsterSkinId) -- Aplica a skin de zumbi
           
            local zombieZeroName = GetObjectName(zombieZeroIndex)

            NoticeSendToAll(0, "O Evento de Infecção Zumbi começou! Corram por suas vidas!")
            NoticeSendToAll(0, string.format("Cuidado! %s é o Paciente Zero!", zombieZeroName or "Um jogador misterioso"))
            NoticeSend(zombieZeroIndex, 1, "Você é o Zumbi Zero! Infecte todos os outros jogadores!")
            LogColor(2, string.format("[EventoZumbi] Evento iniciado com %d participantes. Paciente Zero: %s", participantCount, zombieZeroName))

        end

    elseif eventState.status == "RUNNING" then
        -- Verifica se algum participante saiu do mapa do evento
        local playersToRemove = {}
        for pIndex, _ in pairs(eventState.participants) do
            if GetObjectConnected(pIndex) > 0 and GetObjectMap(pIndex) ~= eventMap then
                table.insert(playersToRemove, pIndex)
            end
        end

        -- Remove os jogadores que saíram do mapa
        if #playersToRemove > 0 then
            for _, pIndex in ipairs(playersToRemove) do
                local playerName = GetObjectName(pIndex) or "N/A"
                LogColor(1, string.format("[EventoZumbi] Jogador '%s' removido por sair do mapa do evento.", playerName))
                NoticeSend(pIndex, 1, "Você foi removido do Evento Zumbi por sair do mapa.")
               
                SkinChangeSend(pIndex, -1) -- Reverte a skin
                eventState.participants[pIndex] = nil
                eventState.infected[pIndex] = nil
            end
        end

        -- Verifica se ainda há zumbis no evento
        local activeInfectedCount = 0
        for pIndex, _ in pairs(eventState.infected) do
            -- Verifica se o jogador está conectado, é um participante e está no mapa do evento
            if GetObjectConnected(pIndex) > 0 and eventState.participants[pIndex] and GetObjectMap(pIndex) == eventMap then
                activeInfectedCount = activeInfectedCount + 1
            end
        end

        -- Se não houver mais zumbis ativos, os sobreviventes vencem
        if activeInfectedCount == 0 then
            LogColor(1, "[EventoZumbi] Não há mais zumbis no evento. Encerrando.")
            NoticeSendToAll(0, "Todos os zumbis foram neutralizados! Os sobreviventes venceram!")
            eventState.status = "ENDING" -- Altera o status para finalizar o evento
            eventState.timer = 0 -- Força a finalização imediata
        end

        -- Verifica se todos os participantes foram infectados (só executa se o timer for maior que 0)
        if eventState.timer > 0 then
            local activeParticipants = 0
            local infectedCount = 0
            for pIndex, _ in pairs(eventState.participants) do
                -- Considera apenas jogadores que ainda estão conectados
                if GetObjectConnected(pIndex) > 0 then
                    activeParticipants = activeParticipants + 1
                    if eventState.infected[pIndex] then
                        infectedCount = infectedCount + 1
                    end
                end
            end

            -- Se todos os participantes ativos estiverem infectados, encerra o evento
            if activeParticipants > 0 and activeParticipants == infectedCount then
                LogColor(2, "[EventoZumbi] Todos os participantes foram infectados. Encerrando o evento.")
                NoticeSendToAll(0, "Todos os sobreviventes foram infectados! Os zumbis venceram!")
                eventState.timer = 1 -- Força o fim do evento no próximo ciclo, acionando a lógica de finalização.
            end
    end   

        -- Anuncia o tempo restante do evento
        if eventState.timer > 0 and eventState.timer % 60 == 0 then
            NoticeSendToAll(0, string.format("Tempo restante no Evento Zumbi: %d minuto(s).", eventState.timer / 60))
        end

        -- Verifica se o tempo acabou ou se o evento foi forçado a terminar
        if eventState.timer <= 0 and (eventState.status == "RUNNING" or eventState.status == "ENDING") then
            -- Fim do evento: verifica os resultados
            local survivors = {}
            for pIndex, _ in pairs(eventState.participants) do
                if GetObjectConnected(pIndex) > 0 and not eventState.infected[pIndex] then
                    table.insert(survivors, pIndex)
                end
            end
           
            if #survivors > 0 then
                -- Existem sobreviventes
                LogColor(2, string.format("[EventoZumbi] Evento finalizado. Sobreviventes: %d", #survivors))
                NoticeSendToAll(0, "O tempo acabou! Os sobreviventes venceram a infecção!")
                for _, sIndex in ipairs(survivors) do
                    local accountId = GetObjectAccount(sIndex)
                    if accountId and string.len(accountId) > 0 then
                        local query = string.format("UPDATE MEMB_INFO SET WCoinC = WCoinC + %d WHERE memb___id = '%s'", survivorReward, accountId)
                        SQLQuery(query)
                        NoticeSend(sIndex, 0, string.format("Parabéns! Você sobreviveu e ganhou %d WCoinC!", survivorReward))
                        LogColor(2, string.format("[EventoZumbi] Premiando sobrevivente '%s' (conta: %s) com %d WCoinC.", GetObjectName(sIndex), accountId, survivorReward))
                    end
                end
            else
                -- Todos foram infectados
                LogColor(2, "[EventoZumbi] Evento finalizado. Todos foram infectados!")
                NoticeSendToAll(0, "O tempo acabou! Os zumbis dominaram! Todos foram infectados!")
                if eventState.zombieZero and GetObjectConnected(eventState.zombieZero) > 0 then
                    local accountId = GetObjectAccount(eventState.zombieZero)
                    if accountId and string.len(accountId) > 0 then
                        local query = string.format("UPDATE MEMB_INFO SET WCoinC = WCoinC + %d WHERE memb___id = '%s'", zombieZeroReward, accountId)
                        SQLQuery(query)
                        NoticeSend(eventState.zombieZero, 0, string.format("Parabéns! Como Zumbi Zero, você ganhou %d WCoinC!", zombieZeroReward))
                        LogColor(2, string.format("[EventoZumbi] Premiando Zumbi Zero '%s' (conta: %s) com %d WCoinC.", GetObjectName(eventState.zombieZero), accountId, zombieZeroReward))
                    end
                end
            end

            eventState.status = "CLEANUP"
            eventState.timer = 5 -- 5 segundos para limpeza
        end
    elseif eventState.status == "CLEANUP" then
        if eventState.timer <= 0 then
            ResetEventState()
        end
    end
end

-- Função chamada quando um jogador morre
function Zumbi_OnUserDie(victimIndex, killerIndex)
    if eventState.status ~= "RUNNING" or not eventState.participants[victimIndex] then
        return
    end

    -- Verifica se o assassino está na lista de infectados
    if not eventState.infected[killerIndex] then
        return -- Se o assassino não for um zumbi, não faz nada.
    end

    -- Verifica se a vítima é um participante e ainda não está infectada
    local isVictimParticipant = eventState.participants[victimIndex]

    -- Se um zumbi (killer) matou um humano (victim) dentro do evento
    if isVictimParticipant and not eventState.infected[victimIndex] then
        -- Se um zumbi matou um humano
        local victimName = GetObjectName(victimIndex)
        eventState.infected[victimIndex] = true
        SkinChangeSend(victimIndex, monsterSkinId) -- Aplica a skin de zumbi
        NoticeSend(victimIndex, 1, "Você foi infectado! Agora você é um zumbi!")
        NoticeSendToAll(0, string.format("%s foi infectado e se tornou um zumbi!", victimName))
        LogColor(2, string.format("[EventoZumbi] '%s' foi infectado por '%s'.", victimName, GetObjectName(killerIndex)))
    end
end

-- Função para remover jogador do evento se ele deslogar
function Zumbi_OnCharacterClose(aIndex)
    if eventState.status == "IDLE" then return end

    if eventState.participants[aIndex] then
        local playerName = GetObjectName(aIndex)
        eventState.participants[aIndex] = nil
        eventState.infected[aIndex] = nil -- Garante que ele seja removido da lista de infectados também
        LogColor(1, string.format("[EventoZumbi] Jogador '%s' saiu do evento (desconectado).", playerName or "N/A"))
    end
end
Bon Dia

🡱 🡳
Real Time Web Analytics