• 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.X+ Distance effect damage

T

Tibia Demon

Guest
How can i make distance effect hit each time it go through player on way?
Lua:
local combatOne = Combat()
combatOne:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combatOne:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_SMALLCLOUDS)
combatOne:setArea(createCombatArea(testOne))

function onGetFormulaValuesOne(creature, level, magicLevel)
    local min = 1
    local max = 2
    return -min, -max
end

function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_DEATH)
end

combatOne:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesOne")
combatOne:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

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

function onCastSpell(creature, variant)
        addEvent(castSpellOne, 0, creature:getId(), variant)
    return true
end
distance.gif
like if sd runes are standing players they get hit and not only the ones on the end of distance effect
 
Solution
Not sure if its allowed, but you could maybe have two Combats?
CombatOne is the same as the one in your script. You can change it so it deals 0 damage.
CombatTwo got the same area as CombatOne, but doesn't have an effect. It just deals damage.
Tried to toss something together fast. Cant test it.
I dont know what testOne area is. If its just the edges of the spells, then you need to create a new area that covers everything.
Lua:
local combatOne = Combat()
combatOne:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combatOne:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_SMALLCLOUDS)
combatOne:setArea(createCombatArea(testOne))

local combatTwo = Combat()
combatOne:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)...
I know I probably won't help much just describing a possible solution without giving any code, but still, I think what you can do is look at the square area covered by the SD spell you have in your picture and check every square if a player is present there. Then, for every player, do damage to them.
 
I know I probably won't help much just describing a possible solution without giving any code, but still, I think what you can do is look at the square area covered by the SD spell you have in your picture and check every square if a player is present there. Then, for every player, do damage to them.
Thanks but i think i will need more hints to make it
i don't know how to check every player in the spell area.
 
Not sure if its allowed, but you could maybe have two Combats?
CombatOne is the same as the one in your script. You can change it so it deals 0 damage.
CombatTwo got the same area as CombatOne, but doesn't have an effect. It just deals damage.
Tried to toss something together fast. Cant test it.
I dont know what testOne area is. If its just the edges of the spells, then you need to create a new area that covers everything.
Lua:
local combatOne = Combat()
combatOne:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combatOne:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_SMALLCLOUDS)
combatOne:setArea(createCombatArea(testOne))

local combatTwo = Combat()
combatOne:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combatOne:setArea(createCombatArea(testOne))

function onGetFormulaValuesOne(creature, level, magicLevel)
    local min = 1
    local max = 2
    return -min, -max
end

function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_DEATH)
end

combatTwo:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesOne")
combatTwo:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile") --Not sure if this line is needed at all

local function castSpellOne(creatureId, variant)
    local creature = Creature(creatureId)
    if not creature then
        return
    end
    combatOne:execute(creature, variant)
    combatTwo:execute(creature, variant)
end

function onCastSpell(creature, variant)
        addEvent(castSpellOne, 0, creature:getId(), variant) --Why event here?
    return true
end

EDIT: If you want to execute a combat on every player, you can use Functions · otland/forgottenserver Wiki (https://github.com/otland/forgottenserver/wiki/Functions#Game.getSpectators). That function returns all players or creatures in an area around a position.
You can then use something like Metatable:Position · otland/forgottenserver Wiki (https://github.com/otland/forgottenserver/wiki/Metatable:position#isSightClear) to check if the creature is behind a wall or something similar.
 
Last edited:
Solution
Works thank you i made 2 combats and one more area that cover the full square.
i couldnt make it with the other functions you posted its complicated for me
i will use this for now unless someone wrote a better way because creating new area to cover spell will get harder if the spell is more complex
 
Back
Top