• 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+ loop crashing the server

Nokturno

Not a human
Joined
Aug 7, 2009
Messages
496
Solutions
2
Reaction score
358
Sup , im having troubles with this spell,
its looping a a function and it does work but the problem comes when the player dies and the spell is still there.

can someone help me fix this, or maybe a tip on how to solve it?

Code:
function onTargetTiledmg(cid, pos, creature)
    local player = Player(cid)
    if not cid then return false end
    
    local level = player:getLevel()
    local ml = player:getMagicLevel()
    
    local amin = 1
    local amax = 1
    local damage = {min = -amin, max = -amax}
    
    for i = 1, config12.rounds do
        if not cid then return false end
        addEvent(function()
        if cid then 
            local param = {}
            param.cid = cid
            param.pos = pos
            param.count = 0
            doAreaCombatHealth(cid, COMBAT_HOLYDAMAGE, mainPos, areaxx, 0, 0, config12.ggx1)           
            doAreaCombatHealth(cid, COMBAT_HOLYDAMAGE, mainPos, areaxx, 0, 0, config12.ggx2)                               
            
        end
        end, i * config12.speed)
    end   

end
    
holycombat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTiledmg")
realcombat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    mainPos = creature:getPosition()
    holycombat:execute(creature, variant)
    
    for i = 1, config12.rounds do
        if not creature then return false end
        addEvent(function() if creature then                         
        realcombat:execute(creature, variant)
        end end, i * config12.speed2)
    end
    
    
    return true
end
 

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,548
Solutions
119
Reaction score
1,845
You are passing userdata to addEvent, which dereferences nullptr if creature logs out or die. Pass creature id and recreate userdata using Creature()
 
Top