• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua [TFS 1.2] Animated Spell (executing)

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am having issues with the spell all executing at once. Not sure how to setup the execute for this situation.

Code:
-- Areas/Combat for 0ms
local combat0 = Combat()
combat0:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat0:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat0:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat0:setArea(createCombatArea({{1},
{1},
{0},
{2}}))
combat0:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, 200, 0, 200)

local condition0 = Condition(CONDITION_POISON)
condition0:setParameter(CONDITION_PARAM_DELAYED, true)
condition0:addDamage(4, 4000, -3)
condition0:addDamage(9, 4000, -2)
condition0:addDamage(20, 4000, -1)
combat0:setCondition(condition)

-- Areas/Combat for 200ms
local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat2:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat2:setArea(createCombatArea({{1, 0, 1},
{0, 0, 0},
{0, 0, 0},
{0, 2, 0}}))
combat2:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, 200, 0, 200)

-- Areas/Combat for 400ms
local combat4 = Combat()
combat4:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat4:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat4:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat4:setArea(createCombatArea({{1, 0, 1, 0, 1},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 2, 0, 0}}))
combat4:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, 200, 0, 200)

-- Areas/Combat for 600ms
local combat6 = Combat()
combat6:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat6:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat6:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat6:setArea(createCombatArea({{1, 0, 1},
{1, 0, 1},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 2, 0}}))
combat6:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, 200, 0, 200)

-- Areas/Combat for 500ms
local combat5 = Combat()
combat5:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat5:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat5:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat5:setArea(createCombatArea({{1, 0, 1},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 2, 0}}))
combat5:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, 200, 0, 200)

-- Areas/Combat for 800ms
local combat8 = Combat()
combat8:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)
combat8:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat8:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat8:setArea(createCombatArea({{1},
{1},
{0},
{0},
{0},
{2}}))
combat8:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, 200, 0, 200)

function executeCombat(p, i)
        if not p.creature then
            return false
        end
        combat0:execute(p.creature, p.var)
        combat2:execute(p.creature, p.var)
        combat4:execute(p.creature, p.var)
        combat6:execute(p.creature, p.var)
        combat5:execute(p.creature, p.var)
        combat8:execute(p.creature, p.var)
    end


function onCastSpell(creature, var)
local p = {creature = creature, var = var, combat = combat}
     local time_ = {100, 200, 500, 800, 1000, 1200}
     for t, _ in ipairs(time_) do
         addEvent(executeCombat, time_[t], p, t)
    return true
    end
end
 
your executeCombat function executes all combats at once, then you add an event to call that function multiple times
if you add all your combats to a table and add that many entries in time table
then you can do
Code:
for i=1,#time do
addEvent(doCombat, time[i], combats[i], creature, var)
end
or if you dont want to change code you can do it like
Code:
addEvent(doCombat, 100, combat0, creature, var)
addEvent(doCombat, 200, combat1, creature, var)
etc
 
addEvent(doCombat, 100, combat0, creature, var) addEvent(doCombat, 200, combat1, creature, var)
Not sure I understand where I would do this. wouldn't I have to add the doCombat Function to my script to make the addEvent work properly?
 
if you have
Code:
function double(a)
return a*2
end

Code:
wait 200 ms -> double(2)
is the same as
addEvent(double, 200, 2)
Code:
addEvent(functionName, delayInMS, funcArg1, funcArg2, ...)
so the 2 addEvents in my example is the same as
combat0:execute(creature, var)
combat1:execute(creature, var)
 
How about stop using the combat object?

doTargetCombatHealth() is much easier to use.

Can you provide any sort of example on how to do this? All I can find in my server, is in the source, doTargetCombatHealth(cid, target, type, min, max, effect).
 
first of all you need to create algorithm for the area position calculator. (I think there is no default function what does that)
I suggest to make function like: getAreaPosT(startpos, area_array_table, direction)
You can obviously make it easier at start. by just choosing startpos and not doing the area_array_table rotations with direction parameter yet.

Now you can feed in the area tables you got in the script to getAreaPosT() and in return get the position functions.
(if you want to go advanced way then draw the entire spell sequence in a single area_array_table and let it calculate the all the positions for each sequence)

Once you have created getAreaPosT, you now have table of position which you can loop trough with addEvent()
for addEvent you create the function dealDamageToPosition() and use same parameters as the doTargetCombatHealth(), but instead of targetID you use position.
In that function you simply ask is there tile and creature in that position, and if there is , hurt it.

That's about it.

This is how the same spell looks like in my server if I only did damage to all these positions:
Code:
local areaT = {
    {n, 4, n, 4, n},
    {3, 5, {3,6}, 5, 3},
    {n, 2, 1, 2, n},
    {n, n, 1, n, n},
    {n, n, n, n, n},
    {n, n, 0, n, n},
}

function onCastSpell(creature, var)
local area = getAreaPos(creature, areaT, compass(creature))
local timeT = {100, 200, 500, 800, 1000, 1200}
local cid = creature:getId()

    for i, posT in pairs(area) do
        for _, pos in ipairs(posT) do
            addEvent(dealDamagePos, cid, timeT[i], pos, CONST_ME_ENERGYHIT, PHSYICAL, minDam, maxDam, CONST_ME_ENERGYHIT)
        end
    end
end
 
Code:
local areaT = {
{n, 4, n, 4, n},
{3, 5, {3,6}, 5, 3},
{n, 2, 1, 2, n},
{n, n, 1, n, n},
{n, n, n, n, n},
{n, n, 0, n, n},
}

function onCastSpell(creature, var)
local area = getAreaPos(creature, areaT, compass(creature))
local timeT = {100, 200, 500, 800, 1000, 1200}
local cid = creature:getId()

for i, posT in pairs(area) do
for _, pos in ipairs(posT) do
addEvent(dealDamagePos, cid, timeT[i], pos, CONST_ME_ENERGYHIT, PHSYICAL, minDam, maxDam, CONST_ME_ENERGYHIT)
end
end
end

this will not even cast :(
 
Back
Top