• 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+ Spells

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
Code:
local animationDelay = 600
local combat = {}

local area = {
    {
        {0, 1, 0},
        {1, 2, 1},
        {0, 1, 0}
    },
    {
        {1, 0, 1},
        {0, 2, 0},
        {1, 0, 1}
    },
    {
        {0, 1, 1, 1, 0},
        {1, 0, 0, 0, 1},
        {1, 0, 2, 0, 1},
        {1, 0, 0, 0, 1},
        {0, 1, 1, 1, 0}
    },
    {
        {0, 0, 1, 1, 1, 0, 0},
        {0, 1, 0, 0, 0, 1, 0},
        {1, 0, 0, 0, 0, 0, 1},
        {1, 0, 0, 2, 0, 0, 1},
        {1, 0, 0, 0, 0, 0, 1},
        {0, 1, 0, 0, 0, 1, 0},
        {0, 0, 1, 1, 1, 0, 0}
    },  
    {
        {0, 0, 0, 0, 1, 1, 1, 1, 0 ,0, 0, 0},
        {0, 0, 0, 1, 0, 0, 0, 0, 1 ,0, 0, 0},
        {0, 0, 1, 0, 0, 0, 0, 0, 0 ,1, 0, 0},
        {0, 1, 0, 0, 0, 0, 0, 0, 0 ,0, 1, 0},
        {1, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 1},
        {1, 0, 0, 0, 0, 0, 2, 0, 0 ,0, 0, 1},
        {1, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 1},
        {0, 1, 0, 0, 0, 0, 0, 0, 0 ,0, 1, 0},
        {0, 0, 1, 0, 0, 0, 0, 0, 0 ,1, 0, 0},
        {0, 0, 0, 1, 0, 0, 0, 0, 1 ,0, 0, 0},
        {0, 0, 0, 0, 1, 1, 1, 1, 0 ,0, 0, 0}        
    },          
}

for i = 1, #area do
    combat[i] = Combat()
    combat[i]:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
    combat[i]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
end

for x, _ in ipairs(area) do
    combat[x]:setArea(createCombatArea(area[x]))
end

function executeCombat(p, i)   
    if not p.creature then
        return false
    end
    if not p.creature:isCreature() then
            return false
    end
    p.combat[i]:execute(p.creature, p.var)
end

function onCastSpell(creature, var)
    local p = {creature = creature, var = var, combat = combat}
    for i = 1, #area do      
    safeAddEvent(executeCombat, (animationDelay * i) - animationDelay, p, i)        
    end
    return true
end

I have a problem with this monster spells.
when the monster executes it and is killed and the magic is still running the server goes down
 
Stop using safeAddEvent then. Pass creature id, create creature from that id, check if returned nil, do stuff. There, no more crashes.
 
Lua:
function executeCombat(cid, i, var)   
    local creature = Creature(cid)
    if creature then
        combat[i]:execute(creature, var)
    end
end

function onCastSpell(creature, var)
    for i = 1, #area do      
        addEvent(executeCombat, (animationDelay * i) - animationDelay, creature:getId(), i, var)        
    end
    return true
end
 
Back
Top