• 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!

C++ How to create distance effect for spells in tfs 1.5

3alola1

I don't have time
Premium User
Joined
Sep 2, 2010
Messages
742
Solutions
7
Reaction score
309
Location
Middle Earth
1731706141883.webp

I want my spell to have this sudden death distance effect



LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

-- Formula to calculate the damage
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 15) + 50
    local max = (level / 5) + (magicLevel * 18) + 75
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

-- Spell cast function
function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

the spell script
 
Solution
IDK, if area spells show "distance effect" at all. If they do, they probably show it only for 'hit targets', not for every tile in area.
There is probably no function to show that effect using combat area.
Only way would be to set spell callback to CALLBACK_PARAM_TARGETTILE, it should execute this function for every tile inside attacked area:
LUA:
function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_SUDDENDEATH)
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")
but it would cancel combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues") (there is only 1 spell callback in C++?)
So probably final solution is to call 2 combats one after...
IDK, if area spells show "distance effect" at all. If they do, they probably show it only for 'hit targets', not for every tile in area.
There is probably no function to show that effect using combat area.
Only way would be to set spell callback to CALLBACK_PARAM_TARGETTILE, it should execute this function for every tile inside attacked area:
LUA:
function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_SUDDENDEATH)
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")
but it would cancel combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues") (there is only 1 spell callback in C++?)
So probably final solution is to call 2 combats one after another:
LUA:
-- damage combat
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

-- Formula to calculate the damage
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 15) + 50
    local max = (level / 5) + (magicLevel * 18) + 75
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

-- animation combat
local combat2 = Combat()
combat2:setArea(createCombatArea(AREA_CIRCLE5X5))
function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_SUDDENDEATH)
end

combat2:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

-- Spell cast function
function onCastSpell(creature, variant)
-- if damage combat works, then execute animation combat
    return combat:execute(creature, variant) and combat2:execute(creature, variant)
end
 
Solution
IDK, if area spells show "distance effect" at all. If they do, they probably show it only for 'hit targets', not for every tile in area.
There is probably no function to show that effect using combat area.
Only way would be to set spell callback to CALLBACK_PARAM_TARGETTILE, it should execute this function for every tile inside attacked area:
LUA:
function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_SUDDENDEATH)
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")
but it would cancel combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues") (there is only 1 spell callback in C++?)
So probably final solution is to call 2 combats one after another:
LUA:
-- damage combat
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

-- Formula to calculate the damage
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 15) + 50
    local max = (level / 5) + (magicLevel * 18) + 75
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

-- animation combat
local combat2 = Combat()
combat2:setArea(createCombatArea(AREA_CIRCLE5X5))
function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_SUDDENDEATH)
end

combat2:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

-- Spell cast function
function onCastSpell(creature, variant)
-- if damage combat works, then execute animation combat
    return combat:execute(creature, variant) and combat2:execute(creature, variant)
end
Probably yeah there was a function on tfs 0.4 were you can add the distance spelleffect with it I'm just new to the new tfs and getting confused but still learning but Thanks it worked perfectly <3
 
Back
Top