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

Lua addEvent problem

whiteblXK

Active Member
Joined
Apr 20, 2011
Messages
315
Solutions
9
Reaction score
32
Location
Poland
Hello, I writed simple spell for monsters which quickly repeats the combat, but while continues addEvent monster will die, server is crashed. Why and how to fix that?

I using TFS 1.3

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 11)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, 4)


function onCastSpell(creature, variant)
    for i = 1, 5 do
    addEvent(function()
        if isCreature(creature) then
            combat:execute(creature, variant)
        end
        end, (i * 300))       
    end
end
 
Solution
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 11)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, 4)

local function execute(cid, variant, i, j)
    if i > j then
        return
    end
    local creature = Creature(cid)
    if not creature then
        return
    end
    combat:execute(creature, variant)
    addEvent(execute, 300, cid, variant, i + 1, j)
end


function onCastSpell(creature, variant)
    execute(creature:getId(), variant, 1, 5)
end
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 11)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, 4)

local function execute(cid, variant, i, j)
    if i > j then
        return
    end
    local creature = Creature(cid)
    if not creature then
        return
    end
    combat:execute(creature, variant)
    addEvent(execute, 300, cid, variant, i + 1, j)
end


function onCastSpell(creature, variant)
    execute(creature:getId(), variant, 1, 5)
end
 
Solution
Back
Top