• 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.4.2 - Coding advanced spell with for loop but spell doesn't run?

thefakemacaw

New Member
Joined
May 20, 2024
Messages
4
Reaction score
0
GitHub
thefakemacaw
Hi,

I'm attempting to code an advanced spell based on the following example found in TFS 1.2 looking for unique area spell (https://otland.net/threads/tfs-1-2-looking-for-unique-area-spell.278764/):

Lua:
local combats = {}
local areas = {
    -- Area 1
    {{1, 0, 1, 0, 1, 0, 1},
     {0, 1, 0, 1, 0, 1, 0},
     {1, 0, 1, 0, 1, 0, 1},
     {0, 1, 0, 3, 0, 1, 0},
     {1, 0, 1, 0, 1, 0, 1},
     {0, 1, 0, 1, 0, 1, 0},
     {1, 0, 1, 0, 1, 0, 1}},
    -- Area 2
    {{0, 1, 0, 1, 0, 1, 0},
     {1, 0, 1, 0, 1, 0, 1},
     {0, 1, 0, 1, 0, 1, 0},
     {1, 0, 1, 3, 1, 0, 1},
     {0, 1, 0, 1, 0, 1, 0},
     {1, 0, 1, 0, 1, 0, 1},
     {0, 1, 0, 1, 0, 1, 0}}
}
 
for i = 1, #areas do
combats[i] = Combat()
combats[i]:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combats[i]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combats[i]:setArea(createCombatArea(areas[i]))
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 8) + 50
    local max = (level / 5) + (magicLevel * 12) + 75
    return -min, -max
end
 
combats[i]:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
end
local function castSpell(creatureId, variant, combatIndex)
    local creature = Creature(creatureId)
    if creature then
        combats[combatIndex]:execute(creature, variant)
    end
end
 
local spell = Spell("instant")
function spell.onCastSpell(creature, variant)
    for i = 2, #areas do
        addEvent(castSpell, 250 * i, creature:getId(), variant, i)
    end
    return combats[1]:execute(creature, variant)
end

I also added the XML to spells.xml:

XML:
    <instant group="attack" spellid="162" name="testspell" words="test" level="1" mana="0" premium="0" selftarget="1" needweapon="0" cooldown="500" needlearn="0" script="attack/testspell.lua">
        <vocation name="Sorcerer"/>
    </instant>

But when I type "test" in OTClient, it just prints a text message without running the spell. I even restarted TFS to get the spells to update but no luck. Any advice?
 
Solution
Change:
Lua:
local spell = Spell("instant")
function spell.onCastSpell(creature, variant)
    for i = 2, #areas do
        addEvent(castSpell, 250 * i, creature:getId(), variant, i)
    end
    return combats[1]:execute(creature, variant)
end
To:
Lua:
function onCastSpell(creature, variant)
    for i = 2, #areas do
        addEvent(castSpell, 250 * i, creature:getId(), variant, i)
    end
    return combats[1]:execute(creature, variant)
end

The former one is used for RevScripts, the latter one is when you want to use spells.xml to register your spells.
Change:
Lua:
local spell = Spell("instant")
function spell.onCastSpell(creature, variant)
    for i = 2, #areas do
        addEvent(castSpell, 250 * i, creature:getId(), variant, i)
    end
    return combats[1]:execute(creature, variant)
end
To:
Lua:
function onCastSpell(creature, variant)
    for i = 2, #areas do
        addEvent(castSpell, 250 * i, creature:getId(), variant, i)
    end
    return combats[1]:execute(creature, variant)
end

The former one is used for RevScripts, the latter one is when you want to use spells.xml to register your spells.
 
Solution
Back
Top