• 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 (TFS 1.2 Request) Exori mort casted on target tile + animation delay by distance

orosama1235

New Member
Joined
Sep 18, 2010
Messages
11
Reaction score
0
  • Distro: TFS 1.2
  • Script type: Spell / Lua Function
    Original death strike:
  • 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_DEATH)
    
    function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 2.2) + 14
    return -min, -max
    end
    
    combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
    
    function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
    end

  • Description: I need death strike to be casted on the ground that target is, not instant on the target, so if target moves from casted position, will be possible to avoid the death strike. Original death strikes send a distance shoot and a magic effect with dmg directly on the target. I need to send a distance shoot, effect to the target TILE, not directly on the target. Then i need a delay per distance only in animation effect, NOT IN DISTANCE SHOOT:

    1 sqm: if distance between target is = 1 add ANIMATION delay (dont change distance shoot) + 0 miliseconds (instant)
    2 sqm: if distance between target is = 2 add ANIMATION delay (dont change distance shoot) + 60 miliseconds
    3 sqm: if distance between target is = 3 add ANIMATION delay (dont change distance shoot) + 120 miliseconds
    4 sqm: i will just replicate

    example.png

    This is the function getDistanceBetween i have, just dont know how to put it to do that and if will work with it:
  • Lua:
    function getDistanceBetween(pos1, pos2)
        local xDif = math.abs(pos1.x - pos2.x)
        local yDif = math.abs(pos1.y - pos2.y)
    
        local posDif = math.max(xDif, yDif)
        if (pos1.z ~= pos2.z) then
            posDif = (posDif + 9 + 6)
        end
        return posDif
    end

    So basically:
    if target 1 sqm return event 1 (combat1, delay0)
    if target 2 sqm return event 2 (combat2, delay60)
    if target 3 sqm return event 3 (combat3, delay120)

    so if i want to change dmg and area by distance will be possible too. Thank in advance!


 
Solution
About "timing" and hit's opponent only if missile reached target tile, here is my piece of code from spell that I wrote for myself with kinda-similar mechanic, you should make something like this:
Lua:
    local target_pos = creature:getTarget():getPosition()
    creature:getPosition():sendDistanceEffect(target_pos, 1)  
    local timing = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition()) * 50
    addEvent(
    function()
        target_pos:sendMagicEffect(30)
        return combat:execute(cid, variant)
    end, timing, cid, variant)
About "timing" and hit's opponent only if missile reached target tile, here is my piece of code from spell that I wrote for myself with kinda-similar mechanic, you should make something like this:
Lua:
    local target_pos = creature:getTarget():getPosition()
    creature:getPosition():sendDistanceEffect(target_pos, 1)  
    local timing = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition()) * 50
    addEvent(
    function()
        target_pos:sendMagicEffect(30)
        return combat:execute(cid, variant)
    end, timing, cid, variant)
 
Solution
About "timing" and hit's opponent only if missile reached target tile, here is my piece of code from spell that I wrote for myself with kinda-similar mechanic, you should make something like this:
Lua:
    local target_pos = creature:getTarget():getPosition()
    creature:getPosition():sendDistanceEffect(target_pos, 1)
    local timing = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition()) * 50
    addEvent(
    function()
        target_pos:sendMagicEffect(30)
        return combat:execute(cid, variant)
    end, timing, cid, variant)

Yes, missile will go to the target tile and do the combat even if the target is not there anymore. Well, i have no idea how to put this into death strike :(. Can you share this spell or try to adapt into death strike? I can test here. Thanks!

EDIT: @Fresh
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_NONE)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 2.2) + 14
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    local target_pos = creature:getTarget():getPosition()
    creature:getPosition():sendDistanceEffect(target_pos, 1)
    local timing = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition()) * 70
    addEvent(
    function()
        target_pos:sendMagicEffect(18)
        return combat:execute(cid, variant)
    end, timing, cid, variant)
end

With this now, i get no errors in console but Its not dealing any damage at all, the delay worked just fine by distance. thankkks. Just need to know how i put dmg if creature is 1 sqm away:execute combat1, if creature is 2 sqm away:execute combat2, etc.

https://im2.ezgif.com/tmp/ezgif-2-3297ffffb6ee.gif
ezgif.com-gif-maker.gif
 
Last edited:
EDIT: I figured it out, now is dealing dmg.

Lua:
return combat:execute(cid, variant)
to:
Code:
return combat:execute(creature, variant)

Trying now how i put dmg if creature is 1 sqm away:execute combat1, if creature is 2 sqm away:execute combat2, etc.
How it is:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 2.2) + 14
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    local target_pos = creature:getTarget():getPosition()
    creature:getPosition():sendDistanceEffect(target_pos, 32)
    local timing = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition()) * 70
    addEvent(
    function()
        target_pos:sendMagicEffect(18)
        return combat:execute(creature, variant)
    end, timing, cid, variant)
end
Post automatically merged:

EDIT 2: Done. Its almost perfect. I didnt manage to put the dmg formula inside the oncast like:

Lua:
function onCastSpell(cid, creature, variant)
    local player = Player(cid)
    if not player then
        return false
    end
    local level = player:getLevel()
    local maglevel = player:getMagicLevel()
    local a = (level / 5) + (maglevel * 4) + 225
    local b = (level / 5) + (maglevel * 10) + 300
    local damage = {min = -a, max = -b}

So i put separated and is working anyway. Dont know if i put inside the oncast will be a cleaner code. Thanks @Fresh
I actually dont know if that way can make any errors later on or if is everything running clear, but is tested and working.

Lua:
local combat1sqm = Combat()
combat1sqm:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.5) + 5
    local max = (level / 7) + (magicLevel * 2.0) + 10
    return -min, -max
end
combat1sqm:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

local combat2sqm = Combat()
combat2sqm:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 7) + (magicLevel * 2.5) + 10
    local max = (level / 9) + (magicLevel * 3.0) + 15
    return -min, -max
end
combat2sqm:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

local combat3sqm = Combat()
combat3sqm:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 9) + (magicLevel * 3.5) + 50
    local max = (level / 11) + (magicLevel * 4.0) + 100
    return -min, -max
end
combat3sqm:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    local target_pos = creature:getTarget():getPosition() creature:getPosition():sendDistanceEffect(target_pos, 32)
    local timing = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition()) * 70
    local sqms = getDistanceBetween(creature:getPosition(), creature:getTarget():getPosition())
        if sqms == 1 then
    addEvent(function() return combat1sqm:execute(creature, variant) end, timing, cid, variant)
    end
        if sqms == 2 then
    addEvent(function() return combat2sqm:execute(creature, variant) end, timing, cid, variant)
    end
        if sqms >= 3 then
    addEvent(function() return combat3sqm:execute(creature, variant) end, timing, cid, variant)
    end
end
 
Last edited:
Back
Top