• 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 Directional Spell & addEvent issue

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,798
Solutions
581
Reaction score
5,361
TFS 1.4.2

I want the direction of the spell to remain static. So if I'm facing south and cast, it will cast south 3 times, in the original casted spot.

So this works as expected, until I start moving my character around. xD

It seems like the direction of the character is checked everytime combat is called.. and there's no way to give the spell any information to get around that.

Is there something simple I'm missing?

bandicam2024-01-2808-06-14-375-ezgif.com-video-to-gif-converter.gif

Lua:
local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat1:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat1:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat2:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combat2:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))

local combat3 = Combat()
combat3:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat3:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISON)
combat3:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))


local function castDelayedSpell(creatureId, variant, combat)
    local creature = Creature(creatureId)
    if not creature then
        return
    end
    combat:execute(creature, variant)
end

local spell = Spell("instant")

function spell.onCastSpell(creature, variant)
    local creatureId = creature:getId()
    addEvent(castDelayedSpell, 0, creatureId, variant, combat1)
    addEvent(castDelayedSpell, 500, creatureId, variant, combat2)
    addEvent(castDelayedSpell, 1000, creatureId, variant, combat3)
    return 
end

spell:name("triple effect spell")
spell:words("triple effect spell")
spell:group("attack")
spell:id(179)
spell:cooldown(1000)
spell:groupCooldown(1000)
spell:level(1)
spell:mana(10)
spell:isSelfTarget(false)
spell:isPremium(true)
spell:needLearn(false)
spell:needDirection(true)
spell:register()
 
Solution
Nice.
This should work. Give me a few minutes to give it a try.
Lua:
local combat = Combat()
combat:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))

local effects = {CONST_ME_MAGIC_BLUE, CONST_ME_MAGIC_RED, CONST_ME_MAGIC_GREEN}
local disEffects = {CONST_ANI_ENERGY, CONST_ANI_FIRE, CONST_ANI_POISON}

local function callback(cid, creaturePos, toPos, positions, index)
    local caster = Creature(cid)
    if not caster then return end
    creaturePos:sendDistanceEffect(toPos, disEffects[index])
    for _, pos in ipairs(positions) do
        pos:sendMagicEffect(effects[index])
        local tile = Tile(pos)
        if tile then
            local creatures = tile:getCreatures()
            if creatures then...
You can generate the positions first and then do a 3x loop (with addEvents) and using doTargetCombat

Lua:
local combat = Combat()
combat:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))

local spell = Spell("instant")
function spell.onCastSpell(creature, variant)

    local positions = combat:getPositions(creature, variant) -- # array
    -- # your code
 
    return
end
Nice.
This should work. Give me a few minutes to give it a try.
 
Nice.
This should work. Give me a few minutes to give it a try.
Lua:
local combat = Combat()
combat:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))

local effects = {CONST_ME_MAGIC_BLUE, CONST_ME_MAGIC_RED, CONST_ME_MAGIC_GREEN}
local disEffects = {CONST_ANI_ENERGY, CONST_ANI_FIRE, CONST_ANI_POISON}

local function callback(cid, creaturePos, toPos, positions, index)
    local caster = Creature(cid)
    if not caster then return end
    creaturePos:sendDistanceEffect(toPos, disEffects[index])
    for _, pos in ipairs(positions) do
        pos:sendMagicEffect(effects[index])
        local tile = Tile(pos)
        if tile then
            local creatures = tile:getCreatures()
            if creatures then
                for _, creature in ipairs(creatures) do
                    doTargetCombatHealth(caster, creature, COMBAT_FIREDAMAGE, -100, -100, CONST_ME_NONE)
                end
            end
        end
    end
end

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(creature, variant)
    local creatureId = creature:getId()
    local creaturePos = creature:getPosition()
    local toPos = Position(creaturePos)
    toPos:getNextPosition(creature:getDirection())
    local positions = combat:getPositions(creature, variant)
    for index = 1, #effects do
        addEvent(callback, 500 * (index - 1), creatureId, creaturePos, toPos, positions, index)
    end
    return true
end

spell:name("triple effect spell")
spell:words("triple effect spell")
spell:group("attack")
spell:id(179)
spell:cooldown(1000)
spell:groupCooldown(1000)
spell:level(1)
spell:mana(10)
spell:isSelfTarget(false)
spell:isPremium(true)
spell:needLearn(false)
spell:needDirection(true)
spell:register()
View attachment test.mp4
 
Solution
Lua:
local combat = Combat()
combat:setArea(createCombatArea(AREA_SQUAREWAVE5, AREADIAGONAL_SQUAREWAVE5))

local effects = {CONST_ME_MAGIC_BLUE, CONST_ME_MAGIC_RED, CONST_ME_MAGIC_GREEN}
local disEffects = {CONST_ANI_ENERGY, CONST_ANI_FIRE, CONST_ANI_POISON}

local function callback(cid, creaturePos, toPos, positions, index)
    local caster = Creature(cid)
    if not caster then return end
    creaturePos:sendDistanceEffect(toPos, disEffects[index])
    for _, pos in ipairs(positions) do
        pos:sendMagicEffect(effects[index])
        local tile = Tile(pos)
        if tile then
            local creatures = tile:getCreatures()
            if creatures then
                for _, creature in ipairs(creatures) do
                    doTargetCombatHealth(caster, creature, COMBAT_FIREDAMAGE, -100, -100, CONST_ME_NONE)
                end
            end
        end
    end
end

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(creature, variant)
    local creatureId = creature:getId()
    local creaturePos = creature:getPosition()
    local toPos = Position(creaturePos)
    toPos:getNextPosition(creature:getDirection())
    local positions = combat:getPositions(creature, variant)
    for index = 1, #effects do
        addEvent(callback, 500 * (index - 1), creatureId, creaturePos, toPos, positions, index)
    end
    return true
end

spell:name("triple effect spell")
spell:words("triple effect spell")
spell:group("attack")
spell:id(179)
spell:cooldown(1000)
spell:groupCooldown(1000)
spell:level(1)
spell:mana(10)
spell:isSelfTarget(false)
spell:isPremium(true)
spell:needLearn(false)
spell:needDirection(true)
spell:register()
View attachment 81749
Thanks for that. xD
Life jumped up and I wasn't able to try it out as quick as I wanted to.

gg
 
Back
Top