Jump to content
  • 0

Canary 3.2.1 13.40


martinsleh

Question

Nessa versão do Canary está depreciada a função onKill... dando aviso no console para usar a onDeath, porém se eu substituo onDeath pelo onKill simplesmente o portal não aparece.

Se eu uso a onKill da esse aviso ao matar qualquer monstro no servidor: [warning] [CreatureEvent::executeOnKill - Creature GOD DreamS target Glacius Death event killMonsterCreatePortal] Deprecated use of onKill event. Use registered onDeath events instead for better performance.

Spoiler

local portalId, t = 25058,
{
["glacius death"] = {
message = "You have defeated Glacius Death!",
config = {
createPos = {}, -- The portal will be created where the monster dies.
toPos = {x = 32202, y = 31863, z = 13}, -- Position where the portal will teleport to
portalTime = 1, -- Duration of the portal in minutes
}
},
}
---------------------------------------------------------------------------------------
-- Config end
---------------------------------------------------------------------------------------

local function spectatorStartCountdown(time, position)
local spectators = Game.getSpectators(position, false, false, 5, 5, 5, 5)

if #spectators > 0 then
for i = 1, #spectators do
if time > 1 then
spectators:say("" .. time .. "", TALKTYPE_MONSTER_SAY, false, spectators, position)
else
spectators:say("Time out!", TALKTYPE_MONSTER_SAY, false, spectators, position)
break
end
end
end

local portal = Tile(position):getItemById(portalId)
if portal then
addEvent(spectatorStartCountdown, 1000, time - 1, position)
end
end


local function removePortal(position)
local portal = Tile(position):getItemById(portalId)
if portal then
portal:remove()
end
end

local killMonsterCreatePortal = CreatureEvent("killMonsterCreatePortal")

function killMonsterCreatePortal.onKill(creature, target)
if not target:isMonster() or target:getMaster() then
return true
end

local player = Player(creature:getGuid())
local k = t[target:getName():lower()]
if not k then
return true
end

local pos, cPos = target:getPosition()
if type(k.config.createPos) == 'table' then
if next(k.config.createPos) == nil then
cPos = pos
else
cPos = k.config.createPos
end
end

if Tile(cPos):getItemById(portalId) then
return true
end

local item = Game.createItem(portalId, 1, cPos)
if item:isTeleport() then
item:setDestination(k.config.toPos)
end

local pt = k.config.portalTime

addEvent(spectatorStartCountdown, 500, pt * 60, cPos)
addEvent(removePortal, pt * 60 * 1000, cPos)
return true
end

killMonsterCreatePortal:type("kill")
killMonsterCreatePortal:register()

---------------------------------------------------------------------------------------
-- Register script onLogin
---------------------------------------------------------------------------------------
local monsterKillLogin = CreatureEvent("monsterKillLogin")

function monsterKillLogin.onLogin(player)
player:registerEvent("killMonsterCreatePortal")
return true
end

monsterKillLogin:type("login")
monsterKillLogin:register()

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
local portalId, t = 25058,
{
    ["glacius death"] = {
        message = "You have defeated Glacius Death!",
        config = {
            createPos = {}, -- O portal será criado onde o monstro morrer.
            toPos = {x = 32202, y = 31863, z = 13}, -- Posição onde o portal irá teleportar
            portalTime = 1, -- Duração do portal em minutos
        }
    },
}
---------------------------------------------------------------------------------------
-- Fim da Configuração
---------------------------------------------------------------------------------------

local function spectatorStartCountdown(time, position)
    local spectators = Game.getSpectators(position, false, false, 5, 5, 5, 5)
    if #spectators > 0 then
        for i = 1, #spectators do
            if time > 1 then
                spectators:say("" .. time .. "", TALKTYPE_MONSTER_SAY, false, spectators, position)
            else
                spectators:say("Time out!", TALKTYPE_MONSTER_SAY, false, spectators, position)
                break
            end
        end
    end
    local portal = Tile(position):getItemById(portalId)
    if portal then
        addEvent(spectatorStartCountdown, 1000, time - 1, position)
    end
end

local function removePortal(position)
    local portal = Tile(position):getItemById(portalId)
    if portal then
        portal:remove()
    end
end

local deathMonsterCreatePortal = CreatureEvent("deathMonsterCreatePortal")

function deathMonsterCreatePortal.onDeath(creature, corpse, killer, mostDamageKiller)
    if not creature:isMonster() or creature:getMaster() then
        return true
    end

    local k = t[creature:getName():lower()]
    if not k then
        return true
    end

    local pos = creature:getPosition()
    local cPos = k.config.createPos
    if next(cPos) == nil then
        cPos = pos
    end

    if Tile(cPos):getItemById(portalId) then
        return true
    end

    local item = Game.createItem(portalId, 1, cPos)
    if item:isTeleport() then
        item:setDestination(k.config.toPos)
    end

    local pt = k.config.portalTime
    addEvent(spectatorStartCountdown, 500, pt * 60, cPos)
    addEvent(removePortal, pt * 60 * 1000, cPos)
    return true
end

deathMonsterCreatePortal:type("death")
deathMonsterCreatePortal:register()

---------------------------------------------------------------------------------------
-- Registrar script onLogin
---------------------------------------------------------------------------------------
local monsterDeathLogin = CreatureEvent("monsterDeathLogin")

function monsterDeathLogin.onLogin(player)
    player:registerEvent("deathMonsterCreatePortal")
    return true
end

monsterDeathLogin:type("login")
monsterDeathLogin:register()

 

Link to comment
Share on other sites

  • 0
16 horas atrás, El Rusher disse:
local portalId, t = 25058,
{
    ["glacius death"] = {
        message = "You have defeated Glacius Death!",
        config = {
            createPos = {}, -- O portal será criado onde o monstro morrer.
            toPos = {x = 32202, y = 31863, z = 13}, -- Posição onde o portal irá teleportar
            portalTime = 1, -- Duração do portal em minutos
        }
    },
}
---------------------------------------------------------------------------------------
-- Fim da Configuração
---------------------------------------------------------------------------------------

local function spectatorStartCountdown(time, position)
    local spectators = Game.getSpectators(position, false, false, 5, 5, 5, 5)
    if #spectators > 0 then
        for i = 1, #spectators do
            if time > 1 then
                spectators:say("" .. time .. "", TALKTYPE_MONSTER_SAY, false, spectators, position)
            else
                spectators:say("Time out!", TALKTYPE_MONSTER_SAY, false, spectators, position)
                break
            end
        end
    end
    local portal = Tile(position):getItemById(portalId)
    if portal then
        addEvent(spectatorStartCountdown, 1000, time - 1, position)
    end
end

local function removePortal(position)
    local portal = Tile(position):getItemById(portalId)
    if portal then
        portal:remove()
    end
end

local deathMonsterCreatePortal = CreatureEvent("deathMonsterCreatePortal")

function deathMonsterCreatePortal.onDeath(creature, corpse, killer, mostDamageKiller)
    if not creature:isMonster() or creature:getMaster() then
        return true
    end

    local k = t[creature:getName():lower()]
    if not k then
        return true
    end

    local pos = creature:getPosition()
    local cPos = k.config.createPos
    if next(cPos) == nil then
        cPos = pos
    end

    if Tile(cPos):getItemById(portalId) then
        return true
    end

    local item = Game.createItem(portalId, 1, cPos)
    if item:isTeleport() then
        item:setDestination(k.config.toPos)
    end

    local pt = k.config.portalTime
    addEvent(spectatorStartCountdown, 500, pt * 60, cPos)
    addEvent(removePortal, pt * 60 * 1000, cPos)
    return true
end

deathMonsterCreatePortal:type("death")
deathMonsterCreatePortal:register()

---------------------------------------------------------------------------------------
-- Registrar script onLogin
---------------------------------------------------------------------------------------
local monsterDeathLogin = CreatureEvent("monsterDeathLogin")

function monsterDeathLogin.onLogin(player)
    player:registerEvent("deathMonsterCreatePortal")
    return true
end

monsterDeathLogin:type("login")
monsterDeathLogin:register()

 

Olá, primeiramente muito obrigado pela ajuda!

Testei o script e a criatura (glacius death) morreu, porém  o portal não foi criado.

Link to comment
Share on other sites

  • 0
local portalId, t = 25058,
{
    ["glacius death"] = {
        message = "You have defeated Glacius Death!",
        config = {
            createPos = {}, -- O portal será criado onde o monstro morrer.
            toPos = {x = 32202, y = 31863, z = 13}, -- Posição onde o portal irá teleportar
            portalTime = 1, -- Duração do portal em minutos
        }
    },
}
---------------------------------------------------------------------------------------
-- Fim da Configuração
---------------------------------------------------------------------------------------

local function spectatorStartCountdown(time, position)
    local spectators = Game.getSpectators(position, false, false, 5, 5, 5, 5)
    if #spectators > 0 then
        for i = 1, #spectators do
            if time > 1 then
                spectators:say("" .. time .. "", TALKTYPE_MONSTER_SAY, false, spectators, position)
            else
                spectators:say("Time out!", TALKTYPE_MONSTER_SAY, false, spectators, position)
                break
            end
        end
    end
    local portal = Tile(position):getItemById(portalId)
    if portal then
        addEvent(spectatorStartCountdown, 1000, time - 1, position)
    end
end

local function removePortal(position)
    local portal = Tile(position):getItemById(portalId)
    if portal then
        portal:remove()
    end
end

local deathMonsterCreatePortal = CreatureEvent("deathMonsterCreatePortal")

function deathMonsterCreatePortal.onDeath(creature, corpse, killer, mostDamageKiller)
    if not creature:isMonster() or creature:getMaster() then
        return true
    end

    -- Debug para ver se a criatura correta foi detectada
    print("A criatura morreu: " .. creature:getName())

    local k = t[creature:getName():lower()]
    if not k then
        print("A criatura " .. creature:getName() .. " não está na lista de criação de portais.")
        return true
    end

    print("Criando portal para a criatura: " .. creature:getName())

    local pos = creature:getPosition()
    local cPos = k.config.createPos
    if next(cPos) == nil then
        cPos = pos
    end

    if Tile(cPos):getItemById(portalId) then
        print("Portal já existente na posição: " .. cPos.x .. ", " .. cPos.y .. ", " .. cPos.z)
        return true
    end

    local item = Game.createItem(portalId, 1, cPos)
    if item:isTeleport() then
        item:setDestination(k.config.toPos)
        print("Portal criado com sucesso na posição: " .. cPos.x .. ", " .. cPos.y .. ", " .. cPos.z)
    else
        print("Erro ao criar o portal.")
    end

    local pt = k.config.portalTime
    addEvent(spectatorStartCountdown, 500, pt * 60, cPos)
    addEvent(removePortal, pt * 60 * 1000, cPos)
    return true
end

deathMonsterCreatePortal:type("death")
deathMonsterCreatePortal:register()

---------------------------------------------------------------------------------------
-- Registrar script onLogin
---------------------------------------------------------------------------------------
local monsterDeathLogin = CreatureEvent("monsterDeathLogin")

function monsterDeathLogin.onLogin(player)
    player:registerEvent("deathMonsterCreatePortal")
    return true
end

monsterDeathLogin:type("login")
monsterDeathLogin:register()


 

  • Ao matar o monstro glacius death, veja no console as mensagens de debug. Elas ajudarão a identificar se o problema está na identificação do monstro ou na criação do portal.
  • Verifique se a posição do portal (onde o monstro morre) é adequada e acessível para criar o item.
  • Certifique-se de que o portalId (25058) corresponde ao item do portal correto.
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...