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
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.
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()