• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Teleport after kill

tulio271

New Member
Joined
Jul 15, 2019
Messages
9
Reaction score
2
Hey, folks! I've created a script here, but I'm facing a certain difficulty.

The script's goal is that whenever monster 'X' is killed, it creates a portal in a specific location. It's working fine, but it keeps giving the following warning

Lua:
[warning] [CreatureEvent::executeOnKill - Creature GOD target Gargantua event BossKill] Deprecated use of onKill event. Use registered onDeath events instead for better performance.

I couldn't adapt the script to use 'onKill'. If anyone could help me with this, I'd be grateful. Also, feel free to refactor the script to make it better if you'd like.

Lua:
local bosses = {
    ["gothmog"] = {
        portalId = 25057,
        teleportCreateDestination = Position(1078, 825, 7),
        teleportDestination = Position(1062, 711, 7),
        teleportRemoveTime = 2, -- 2 minutes
        message = "A alma perdida de Yukon gerou o portal!",
    },
    ["bellzeboss"] = {
        portalId = 25054,
        teleportCreateDestination = Position(1108, 1026, 5),
        teleportDestination = Position(1104, 1026, 6),
        teleportRemoveTime = 2, -- 2 minutes
        message = "As divindades de Rio gerou o portal!",
    },
    ["gargantua"] = {
        portalId = 25055,
        teleportCreateDestination = Position(669, 1138, 7),
        teleportDestination = Position(664, 1130, 7),
        teleportRemoveTime = 2, -- 2 minutes
        message = "As divindades de Abre gerou o portal!",
    },
    ["bug"] = {
        portalId = 1949,
        teleportCreateDestination = false,
        teleportDestination = Position(1021, 1024, 7),
        teleportRemoveTime = 1, -- 1 minute
        message = "You have killed the boss! The teleport will disappear in 1 minute.",
    },
    -- Add more bosses here
}

local function removeTeleport(position, portalId)
    local teleportItem = Tile(position):getItemById(portalId)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

local event = CreatureEvent("BossKill")

function event.onKill(creature, target)
    local bossName = target:getName():lower()
    if not bosses[bossName] then
        return true
    end

    local bossConfig = bosses[bossName]
    local bossPosition = target:getPosition()
    local teleportCreateDestination = bossConfig.teleportCreateDestination
    if not teleportCreateDestination then
        teleportCreateDestination = bossPosition
    end

    local portalId = bossConfig.portalId
    local teleport = Game.createItem(portalId, 1, teleportCreateDestination)
    if teleport:isTeleport() then
        teleport:setDestination(bossConfig.teleportDestination)
    end

    teleportCreateDestination:sendMagicEffect(CONST_ME_TELEPORT)
    target:say(bossConfig.message, TALKTYPE_MONSTER_SAY, 0, 0, bossPosition)

    addEvent(removeTeleport, bossConfig.teleportRemoveTime * 60 * 1000, teleportCreateDestination)

    return true
end

event:register()

local login = CreatureEvent("RegisterBossKill")

function login.onLogin(player)
    player:registerEvent("BossKill")
    return true
end

login:register()
 
So to use this as an onDeath, instead of registering the event to the player, you would register the event to the monster.

Either inside it's monster file, or when it is spawned.

if doing inside the monster file (so it's registered for all monsters with that name)
xml
XML:
<script>
    <event name="BossKill" />
</script>
lua monster
Lua:
monsterType:registerEvent("BossKill")

if spawning a creature via script..
Lua:
local monster = Game.createMonster("monsterName", position)
if monster then
    monster:registerEvent("BossKill")
else
    -- monster did not spawn correctly
end

as far as swapping from onKill to onDeath
Lua:
onKill(creature, target)
onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
creature in onKill is the person killing the monster
creature in onDeath is the person dying.

likewise
target in onKill is the monster dying
killer in onDeath is the person who killed the monster

So it's a bit swapped around, and you'd need to adjust the script to reflect that.
 
So to use this as an onDeath, instead of registering the event to the player, you would register the event to the monster.

Either inside it's monster file, or when it is spawned.

if doing inside the monster file (so it's registered for all monsters with that name)
xml
XML:
<script>
    <event name="BossKill" />
</script>
lua monster
Lua:
monsterType:registerEvent("BossKill")

if spawning a creature via script..
Lua:
local monster = Game.createMonster("monsterName", position)
if monster then
    monster:registerEvent("BossKill")
else
    -- monster did not spawn correctly
end

as far as swapping from onKill to onDeath
Lua:
onKill(creature, target)
onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
creature in onKill is the person killing the monster
creature in onDeath is the person dying.

likewise
target in onKill is the monster dying
killer in onDeath is the person who killed the monster

So it's a bit swapped around, and you'd need to adjust the script to reflect that.

Could you show me what my script would look like with these changes?
 
Could you show me what my script would look like with these changes?
Sure.

change
Lua:
function event.onKill(creature, target)
to
Lua:
function event.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)

change
Lua:
local bossName = target:getName():lower()
to
Lua:
local bossName = creature:getName():lower()

change
Lua:
local bossPosition = target:getPosition()
to
Lua:
local bossPosition = creature:getPosition()

change
Lua:
target:say(bossConfig.message, TALKTYPE_MONSTER_SAY, 0, 0, bossPosition)
to
Lua:
creature:say(bossConfig.message, TALKTYPE_MONSTER_SAY, 0, 0, bossPosition)

remove
Lua:
local login = CreatureEvent("RegisterBossKill")

function login.onLogin(player)
    player:registerEvent("BossKill")
    return true
end

login:register()

and like I said earlier, make sure to register the event to the creatures, using your intended method.
 
Sure.

change
Lua:
function event.onKill(creature, target)
to
Lua:
function event.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)

change
Lua:
local bossName = target:getName():lower()
to
Lua:
local bossName = creature:getName():lower()

change
Lua:
local bossPosition = target:getPosition()
to
Lua:
local bossPosition = creature:getPosition()

change
Lua:
target:say(bossConfig.message, TALKTYPE_MONSTER_SAY, 0, 0, bossPosition)
to
Lua:
creature:say(bossConfig.message, TALKTYPE_MONSTER_SAY, 0, 0, bossPosition)

remove
Lua:
local login = CreatureEvent("RegisterBossKill")

function login.onLogin(player)
    player:registerEvent("BossKill")
    return true
end

login:register()

and like I said earlier, make sure to register the event to the creatures, using your intended method.

Works fine, thanks so much.

just have one problem, the teleport is not removed after time over.

@Xikini
 
Last edited:
Post your current code. Thanks. :)
Lua:
local bosses = {
    ["gothmog"] = {
        portalId = 25057,
        teleportCreateDestination = Position(1078, 825, 7),
        teleportDestination = Position(1062, 711, 7),
        teleportRemoveTime = 2, -- 2 minutes
        message = "A alma perdida de Yukon gerou o portal!",
    },
    ["bellzeboss"] = {
        portalId = 25054,
        teleportCreateDestination = Position(1108, 1026, 5),
        teleportDestination = Position(1104, 1026, 6),
        teleportRemoveTime = 2, -- 2 minutes
        message = "As divindades de Rio gerou o portal!",
    },
    ["gargantua"] = {
        portalId = 25055,
        teleportCreateDestination = Position(669, 1138, 7),
        teleportDestination = Position(664, 1130, 7),
        teleportRemoveTime = 2, -- 2 minutes
        message = "As divindades de Abre gerou o portal!",
    },
    ["bug"] = {
        portalId = 1949,
        teleportCreateDestination = false,
        teleportDestination = Position(1021, 1024, 7),
        teleportRemoveTime = 1, -- 1 minute
        message = "You have killed the boss! The teleport will disappear in 1 minute.",
    },
    -- Add more bosses here
}

local function removeTeleport(position, portalId)
    local teleportItem = Tile(position):getItemById(portalId)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

local event = CreatureEvent("BossKill")

function event.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    local bossName = creature:getName():lower()
    if not bosses[bossName] then
        return true
    end

    local bossConfig = bosses[bossName]
    local bossPosition = creature:getPosition()
    local teleportCreateDestination = bossConfig.teleportCreateDestination
    if not teleportCreateDestination then
        teleportCreateDestination = bossPosition
    end

    local portalId = bossConfig.portalId
    local teleport = Game.createItem(portalId, 1, teleportCreateDestination)
    if teleport:isTeleport() then
        teleport:setDestination(bossConfig.teleportDestination)
    end

    teleportCreateDestination:sendMagicEffect(CONST_ME_TELEPORT)
    creature:say(bossConfig.message, TALKTYPE_MONSTER_SAY, 0, 0, bossPosition)

    addEvent(removeTeleport, bossConfig.teleportRemoveTime * 60 * 1000, teleportCreateDestination)

    return true
end

event:register()
 
Your addEvent doesn't have the portalId

change
Lua:
addEvent(removeTeleport, bossConfig.teleportRemoveTime * 60 * 1000, teleportCreateDestination)
for
Lua:
addEvent(removeTeleport, bossConfig.teleportRemoveTime * 60 * 1000, teleportCreateDestination, portalId)
 
Back
Top