• 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+ tfs 1.3. Spell repeat with addevent?

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
How i can put this spell for repeat?
i want to repeat this function 3x, how can i make it? For when the player uses the jutsu, show the effect 3 times

Lua:
addEvent(function()
                position:sendSpellEffect(798)
        end, math.ceil(100 * (getDistanceBetween(creature_pos, position))))

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setFormula(COMBAT_FORMULA_LEVELMAGIC, -161.2, 1, -163.2, 1) -- level 420 free
combat:setArea(createCombatArea(AREA_RECTANGLE7X5))

function onTargetTile(creature, position)
    local creature_pos = creature:getPosition()
    if creature_pos ~= position then
        addEvent(function()
                position:sendSpellEffect(798)
        end, math.ceil(100 * (getDistanceBetween(creature_pos, position))))
    end
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
Try this out:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setFormula(COMBAT_FORMULA_LEVELMAGIC, -161.2, 1, -163.2, 1) -- level 420 free
combat:setArea(createCombatArea(AREA_RECTANGLE7X5))

local function sendEffect(pos, effectId, delay, i, j)
    if i == j then
        return
    end
    pos:sendSpellEffect(effectId)
    addEvent(sendEffect, delay, pos, effectId, delay, i + 1, j)
end

function onTargetTile(creature, position)
    local creature_pos = creature:getPosition()
    if creature_pos ~= position then
        sendEffect(position, 798, math.ceil(100 * (getDistanceBetween(creature_pos, position))), 0, 3)
    end
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
Last edited:
Try this out:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setFormula(COMBAT_FORMULA_LEVELMAGIC, -161.2, 1, -163.2, 1) -- level 420 free
combat:setArea(createCombatArea(AREA_RECTANGLE7X5))

local function sendEffect(pos, effectId, delay, i, j)
    if i == j then
        return
    end
    position:sendSpellEffect(effectId)
    addEvent(sendEffect, delay, pos, effectId, delay, i + 1, j)
end

function onTargetTile(creature, position)
    local creature_pos = creature:getPosition()
    if creature_pos ~= position then
        sendEffect(position, 798, math.ceil(100 * (getDistanceBetween(creature_pos, position)))), 0, 3)
    end
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
Had an error in parentheses in line 17, so I fixed and ran spell and get this error:
Code:
Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/test.lua:onTargetTile
(Unknown scriptfile)
data/spells/scripts/test.lua:10: attempt to index global 'position' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/test.lua:10: in function 'sendEffect'
        data/spells/scripts/test.lua:17: in function <data/spells/scripts/test.lua:14>
        [C]: at 0x7ff71d145460
 
Back
Top