• 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 spell problem with position/direction while using addevent

poe6man3

Member
Joined
Aug 6, 2020
Messages
57
Reaction score
9
Hello whenever i cast a spell the area where dmg and effects are apply TFS 1.3
Gif:


There is the code:

Lua:
local area1 = {
    {0, 1, 0},
    {0, 1, 0},
    {0, 3, 0}
}
local area2 = {
    {1, 1, 1},
    {1, 1, 1},
    {1, 1, 1},
    {0, 0, 0},
    {0, 0, 0},
    {0, 2, 0}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setArea(createCombatArea(area1))

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat2:setArea(createCombatArea(area2))

local function doCombat(creature, variant, combatCount)
    if combatCount == 0 then
        combatCount = combatCount + 1
        combat:execute(creature, variant)
        combat2:execute(creature, variant)
        addEvent(doCombat, 200, creature, variant, combatCount)
    elseif combatCount > 0 and combatCount <= 2 then
        combatCount = combatCount + 1
        combat2:execute(creature, variant)
        addEvent(doCombat, 200, creature, variant, combatCount)
    end
end

function onGetFormulaValues(player, level, ninjutsu)
    local min = (level / 5) + (ninjutsu * 1.6) + 9
    local max = (level / 5) + (ninjutsu * 3.2) + 19
    return -1, -2
end

function onGetFormulaValues2(player, level, ninjutsu)
    local min = (level / 5) + (ninjutsu * 1.6) + 9
    local max = (level / 5) + (ninjutsu * 3.2) + 19
    return -1, -2
end

combat:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues")
combat2:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues2")

local function castSpell(creature, variant)
    local creatureDirection = creature:getDirection()
    local creaturePos = creature:getPosition()
    if creatureDirection== DIRECTION_SOUTH then
        creaturePos.x = creaturePos.x + 1
        creaturePos.y = creaturePos.y + 6
        --creaturePos:sendMagicEffect(97)
    elseif creatureDirection == DIRECTION_NORTH then
        creaturePos.x = creaturePos.x + 1
        creaturePos.y = creaturePos.y - 1
        --creaturePos:sendMagicEffect(95)
    elseif creatureDirection == DIRECTION_WEST then
        creaturePos.x = creaturePos.x - 1
        creaturePos.y = creaturePos.y + 1
        --creaturePos:sendMagicEffect(98)
    elseif creatureDirection == DIRECTION_EAST then
        creaturePos.x = creaturePos.x + 6
        creaturePos.y = creaturePos.y + 1
        --creaturePos:sendMagicEffect(96)
    end
    local combatCount = 0
    doCombat(creature, variant, combatCount)
end

function onCastSpell(creature, variant)
    addEvent(castSpell, 100, creature, variant)
end

XML:
XML:
<instant type="attack" spellid="4" name="spell" words="spell" aggressive="1" direction="1" script="attack/spell.lua">
        <vocation name="Druid"/>
    </instant>

Idk what is really going on but if i had to guess there is a problem inside the variant parameter which is acting weird after the position changes during the addevent loop ?
Or its a problem in my code ?

Also i printed direction of the creature and the direction stays the same dont change at all
 

N e r o n Z

Banned User
Joined
Jul 12, 2016
Messages
308
Reaction score
81
I see
many people got that problem.
check out this:

maybe it'll help you to fix your problem
kind regards
 

dami1310

◄ Unidentified ►
Joined
Jan 27, 2013
Messages
651
Solutions
9
Reaction score
552
Location
Poland
Try this and tell me if this is what you wanted to achieve.
Code:
local area1 = {
    {0, 1, 0},
    {0, 1, 0},
    {0, 3, 0}
}
local area2 = {
    {1, 1, 1},
    {1, 1, 1},
    {1, 1, 1},
    {0, 0, 0},
    {0, 0, 0},
    {0, 2, 0}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setArea(createCombatArea(area1))

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat2:setArea(createCombatArea(area2))

function onGetFormulaValues(player, level, ninjutsu)
    local min = (level / 5) + (ninjutsu * 1.6) + 9
    local max = (level / 5) + (ninjutsu * 3.2) + 19
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues")
combat2:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues")

local function castSpell(creature, variant, combatt)
    combatt:execute(creature, var)
end

function onCastSpell(creature, variant)
    castSpell(creature, variant, combat)
    addEvent(castSpell, 200, creature, variant, combat2)
    return true
end
 
OP
OP
P

poe6man3

Member
Joined
Aug 6, 2020
Messages
57
Reaction score
9
Try this and tell me if this is what you wanted to achieve.
Code:
local area1 = {
    {0, 1, 0},
    {0, 1, 0},
    {0, 3, 0}
}
local area2 = {
    {1, 1, 1},
    {1, 1, 1},
    {1, 1, 1},
    {0, 0, 0},
    {0, 0, 0},
    {0, 2, 0}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setArea(createCombatArea(area1))

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat2:setArea(createCombatArea(area2))

function onGetFormulaValues(player, level, ninjutsu)
    local min = (level / 5) + (ninjutsu * 1.6) + 9
    local max = (level / 5) + (ninjutsu * 3.2) + 19
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues")
combat2:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues2")

local function castSpell(creature, variant, combatt)
    combatt:execute(creature, var)
end

function onCastSpell(creature, variant)
    castSpell(creature, variant, combat)
    addEvent(castSpell, 200, creature, variant, combat2)
    return true
end

I changed it a little cause errors but almost yes just wanted to cast the area2 3 times with dmg which even if there is not the bug is happening also

Lua:
local area1 = {
    {0, 1, 0},
    {0, 1, 0},
    {0, 3, 0}
}
local area2 = {
    {1, 1, 1},
    {1, 1, 1},
    {1, 1, 1},
    {0, 0, 0},
    {0, 0, 0},
    {0, 2, 0}
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setArea(createCombatArea(area1))

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat2:setArea(createCombatArea(area2))

function onGetFormulaValues(player, level, ninjutsu)
    local min = (level / 5) + (ninjutsu * 1.6) + 9
    local max = (level / 5) + (ninjutsu * 3.2) + 19
    return -min, -max
end

function onGetFormulaValues2(player, level, ninjutsu)
    local min = (level / 5) + (ninjutsu * 1.6) + 9
    local max = (level / 5) + (ninjutsu * 3.2) + 19
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues")
combat2:setCallback(CALLBACK_PARAM_NINJUTSUVALUE, "onGetFormulaValues")

local function castSpell(creature, variant, combatt)
    combatt:execute(creature, variant)
end

function onCastSpell(creature, variant)
    castSpell(creature, variant, combat)
    addEvent(castSpell, 200, creature, variant, combat2)
    return true
end


Gif:
 
Last edited:

dami1310

◄ Unidentified ►
Joined
Jan 27, 2013
Messages
651
Solutions
9
Reaction score
552
Location
Poland
Well, I played with it for a while and it doesn't want to work properly.
I have 1 solution for you, but this is a very cheap way to do that.
Create 8 different combats with 8 different areas and use them depending on the direction.
 
OP
OP
P

poe6man3

Member
Joined
Aug 6, 2020
Messages
57
Reaction score
9
Well, I played with it for a while and it doesn't want to work properly.
I have 1 solution for you, but this is a very cheap way to do that.
Create 8 different combats with 8 different areas and use them depending on the direction.
So im guessing its src related problem if yes could u post it in the tfs repo cause when i try i get an error on github
 
Top