local colorMsg = "orange"
local tableBoss = {
["[EXP] Statue"] = {seconds = 3600, newBoss = "[EXP] Statue", event = nil}
}
local function timer(position, duration, color)
for i = 0, (duration - 1) do
addEvent(function()
doSendAnimatedText(position, tostring(duration - i), color)
end, i * 1000)
end
end
function onKill(cid, target, damage, flags)
if isPlayer(target) then
return true
end
local bossName = getCreatureName(target)
local boss = tableBoss[bossName]
if not boss then
return true
end
local position = getThingPos(target)
-- Cancelar evento anterior se existir
if boss.event then
stopEvent(boss.event)
end
doPlayerSendTextMessage(cid, MESSAGE_TYPES[colorMsg], "The boss will be born in " .. boss.seconds .. " seconds.")
timer(position, boss.seconds, COLOR_WHITE)
boss.event = addEvent(function()
boss.event = nil -- resetar evento
doCreateMonster(boss.newBoss, position)
end, boss.seconds * 1000)
return true
end
1.Cancelamento do evento anterior: Antes de criar um novo evento de nascimento do monstro, o script cancela o evento anterior usando stopEvent(boss.event) se ele ainda estiver ativo.
2.Reset do evento: Quando o monstro é criado, o evento é resetado para nil, permitindo que novos eventos sejam criados sem problema na próxima vez que o monstro for morto.
Essa modificação deve evitar a criação de múltiplos monstros quando o jogador está em cima do contador de tempo.