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

Solved Repeating Spell

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
I am trying to hit the same enemy two times with 500ms interval but i am not sure how I could do that

this code works but it only hits the enemy once and the effect only shows once as well |:

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 29)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -90.2, 1, -95.2, 1)

local combat2 = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -90.2, 1, -95.2, 1)

function onCastSpell(cid, var)
    local position1 = {x=getCreaturePosition(getCreatureTarget(cid)).x+2, y=getCreaturePosition(getCreatureTarget(cid)).y, z=getCreaturePosition(getCreatureTarget(cid)).z}
    doSendMagicEffect(position1, 5)
    doSendMagicEffect(position1, 5)
    return doCombat(cid, combat, var)
end

SOLVED and if anyone is still curious here's the solution:

1. Add additional function

Lua:
function effect(cid)
    local position1 = {x=getCreaturePosition(getCreatureTarget(cid)).x+2, y=getCreaturePosition(getCreatureTarget(cid)).y, z=getCreaturePosition(getCreatureTarget(cid)).z}
    doSendMagicEffect(position1, 5)
end

2. Update your second function

Lua:
function onCastSpell(cid, var)
    addEvent(effect, 0, cid)
    addEvent(effect, 500, cid)
    return doCombat(cid, combat, var)
end
 
Last edited by a moderator:
Solution
Just like this:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 29)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -90.2, 1, -95.2, 1)

function onCastSpell(cid, var)
    local position = {
        x = getCreaturePosition(getCreatureTarget(cid)).x + 2,
        y = getCreaturePosition(getCreatureTarget(cid)).y,
        z = getCreaturePosition(getCreatureTarget(cid)).z
    }

    doSendMagicEffect(position, 5)
    addEvent(function()
        doSendMagicEffect(position, 5)
    end, 500)

    return doCombat(cid, combat, var)
end
You don't need to add another function in there. There's already a "function onSpellCast(..) in your script, you could easily add the "addEvent(..)" directly below "doSendMagicEffect(..)"
 
You don't need to add another function in there. There's already a "function onSpellCast(..) in your script, you could easily add the "addEvent(..)" directly below "doSendMagicEffect(..)"

[How-to] Using addEvent()

It says you need to use function for addEvent, otherwise I am open to see how you do that

--
this doesn't not work, plus it looks like a loop:

Lua:
function onCastSpell(cid, var)
    local position1 = {x=getCreaturePosition(getCreatureTarget(cid)).x+2, y=getCreaturePosition(getCreatureTarget(cid)).y, z=getCreaturePosition(getCreatureTarget(cid)).z}
    doSendMagicEffect(position1, 5)
    addEvent(onCastSpell, 2000, cid)
    return doCombat(cid, combat, var)
end
 
Just like this:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 29)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -90.2, 1, -95.2, 1)

function onCastSpell(cid, var)
    local position = {
        x = getCreaturePosition(getCreatureTarget(cid)).x + 2,
        y = getCreaturePosition(getCreatureTarget(cid)).y,
        z = getCreaturePosition(getCreatureTarget(cid)).z
    }

    doSendMagicEffect(position, 5)
    addEvent(function()
        doSendMagicEffect(position, 5)
    end, 500)

    return doCombat(cid, combat, var)
end
 
Last edited by a moderator:
Solution
Back
Top