• 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
87
Solutions
1
Reaction score
12
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
 
I see
many people got that problem.
check out this:

maybe it'll help you to fix your problem
kind regards
 
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
 
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:
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.
 
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
 
I already know the solution demi said but i think it should be fixed as its pretty big bug in my opinion inside src engine
Also the code with the solution is a little unpleasant to watch
is not a issue, you just need program correctly to consider the original position from your character, instead of the current direction, also you need to keep the original var attributes.
 
Back
Top