• 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!

TFS 1.X+ Spell addevent crashing

T

Tibia Demon

Guest
I am playing with spells-rune and addEvent trying to learn how to create my own spells.
So I have created this one here it works well but when I logout while the addEvent functions still running server crash.
Lua:
local combatOne = Combat()
combatOne:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatOne:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatOne:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatOne:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatTwo = Combat()
combatTwo:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatTwo:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatTwo:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatTwo:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatThree = Combat()
combatThree:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatThree:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatThree:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatThree:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatFour = Combat()
combatFour:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatFour:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatFour:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatFour:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatFive = Combat()
combatFive:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatFive:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatFive:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatFive:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatSix = Combat()
combatSix:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatSix:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatSix:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatSix:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatSeven = Combat()
combatSeven:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatSeven:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatSeven:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatSeven:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatEight = Combat()
combatEight:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatEight:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatEight:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatEight:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatNine = Combat()
combatNine:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatNine:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatNine:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatNine:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatTen = Combat()
combatTen:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatTen:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatTen:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatTen:setArea(createCombatArea(AREA_CIRCLE3X3))

local combatEleven = Combat()
combatEleven:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combatEleven:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
combatEleven:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combatEleven:setArea(createCombatArea(AREA_CIRCLE3X3))

function onGetFormulaValuesOne(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesTwo(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesThree(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesFour(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesFive(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesSix(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesSeven(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesEight(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesNine(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesTen(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

function onGetFormulaValuesEleven(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

combatOne:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesOne")
combatTwo:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesTwo")
combatThree:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesThree")
combatFour:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesFour")
combatFive:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesFive")
combatSix:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesSix")
combatSeven:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesSeven")
combatEight:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesEight")
combatNine:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesNine")
combatTen:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesTen")
combatEleven:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesEleven")

function onCastSpell(creature, variant, isHotkey)
    combatOne:execute(creature, variant)
    combatTwo:execute(creature, variant)
    combatThree:execute(creature, variant)
    combatFour:execute(creature, variant)
    combatFive:execute(creature, variant)
    combatSix:execute(creature, variant)
    combatSeven:execute(creature, variant)
    combatEight:execute(creature, variant)
    combatNine:execute(creature, variant)
    combatTen:execute(creature, variant)
    combatEleven:execute(creature, variant)
    addEvent(function() combatOne:execute(creature, variant) end, 0)
    addEvent(function() combatOne:execute(creature, variant) end, 200)
    addEvent(function() combatOne:execute(creature, variant) end, 400)
    addEvent(function() combatOne:execute(creature, variant) end, 600)
    addEvent(function() combatOne:execute(creature, variant) end, 800)
    addEvent(function() combatOne:execute(creature, variant) end, 1000)
    addEvent(function() combatTwo:execute(creature, variant) end, 1200)
    addEvent(function() combatTwo:execute(creature, variant) end, 1400)
    addEvent(function() combatTwo:execute(creature, variant) end, 1600)
    addEvent(function() combatTwo:execute(creature, variant) end, 1800)
    addEvent(function() combatTwo:execute(creature, variant) end, 2000)
    addEvent(function() combatOne:execute(creature, variant) end, 1200)
    addEvent(function() combatOne:execute(creature, variant) end, 1400)
    addEvent(function() combatOne:execute(creature, variant) end, 1600)
    addEvent(function() combatOne:execute(creature, variant) end, 1800)
    addEvent(function() combatOne:execute(creature, variant) end, 2000)
    addEvent(function() combatOne:execute(creature, variant) end, 1000)
    addEvent(function() combatThree:execute(creature, variant) end, 2200)
    addEvent(function() combatFour:execute(creature, variant) end, 2500)
    addEvent(function() combatFour:execute(creature, variant) end, 3000)
    addEvent(function() combatFive:execute(creature, variant) end, 3500)
    addEvent(function() combatFive:execute(creature, variant) end, 3600)
    addEvent(function() combatSix:execute(creature, variant) end, 3600)
    addEvent(function() combatSix:execute(creature, variant) end, 3700)
    addEvent(function() combatSeven:execute(creature, variant) end, 3700)
    addEvent(function() combatSeven:execute(creature, variant) end, 3800)
    addEvent(function() combatEight:execute(creature, variant) end, 3800)
    addEvent(function() combatEight:execute(creature, variant) end, 3900)
    addEvent(function() combatNine:execute(creature, variant) end, 3900)
    addEvent(function() combatNine:execute(creature, variant) end, 4000)
    addEvent(function() combatTen:execute(creature, variant) end, 4000)
    addEvent(function() combatTen:execute(creature, variant) end, 4100)
    addEvent(function() combatEleven:execute(creature, variant) end, 4100)
    addEvent(function() combatEleven:execute(creature, variant) end, 4200)
    return true
end
 
Inside every different addEvent u need to check if creature exist cause when during some addEvent is currently running if player die this script will try to execute code related stuff to a player that no longer exist which result in a creash so in every addEvent function u need to check if creature exist


Lua:
local function exampleAddevent(creature, variant)
    if not creature or creature:isRemoved() then
        return
    end
end
u put that at the beggining of each addEvent function
 
Solution
is that issue still avaliable on nekiro's downgraded 1.4?
my last update was yesterday but i dont know if he solved it to hos hub or not!?
 
Both solutions in this thread are working.
This is not source issue. It is related to my Lua script.
I only had to add this check to my script and it prevented server's crash.
Lua:
local function castSpell(creatureId, variant)
local creature = Creature(creatureId)
if not creature then
return
end

combat2:execute(creature, variant)
end
 
Back
Top