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

[Solved] Backstab Spell

Doitforthegains

Well-Known Member
Joined
Aug 30, 2014
Messages
231
Reaction score
74
Welcome,
I use TFS 1.1 10.41 and I've been looking for a backstab spell for one of my custom vocations. The idea is that when you stand behind a target (they're facing away from you) you deal double damage, if they're facing any other direction then it would just be normal damage. I've tried the search function already and I found spells that teleport you behind the target, but thats not what I want. Any help would be greatly appreciated! Thank you in advance!
 
This is a modified version of brutal strike but I think this is what your looking for
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid):getDirection()
    local monster = Player(cid):getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, getPlayerLevel(cid) / 5
    local moredmg = 2
    -- 0 north, 1 east, 2 south, 3 west
    if (player ==  0 and monster == 2) or (player ==  2 and monster == 0) or (player ==  1 and monster == 3) or (player ==  3 and monster == 1) then
        -- double dmg
        return -((((skillTotal * 0.02) + 4) + (levelTotal)) * moredmg), -((((skillTotal * 0.04) + 9) + (levelTotal)) * moredmg)
    else
        -- regular dmg
        return -(((skillTotal * 0.02) + 4) + (levelTotal)), -(((skillTotal * 0.04) + 9) + (levelTotal))
    end
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
 
This is a modified version of brutal strike but I think this is what your looking for
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid):getDirection()
    local monster = Player(cid):getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, getPlayerLevel(cid) / 5
    local moredmg = 2
    -- 0 north, 1 east, 2 south, 3 west
    if (player ==  0 and monster == 2) or (player ==  2 and monster == 0) or (player ==  1 and monster == 3) or (player ==  3 and monster == 1) then
        -- double dmg
        return -((((skillTotal * 0.02) + 4) + (levelTotal)) * moredmg), -((((skillTotal * 0.04) + 9) + (levelTotal)) * moredmg)
    else
        -- regular dmg
        return -(((skillTotal * 0.02) + 4) + (levelTotal)), -(((skillTotal * 0.04) + 9) + (levelTotal))
    end
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
So this is essentially what I asked for, only 1 problem and one request. Problem is that it deals double damage if the Target is facing me instead of facing the opposite direction. And as for the request, how would I go about making it more like old school exori vis..in the manner of being able to use it 1sqm infront of me instead of using it on the target

I made actually spell like that, to Ninja vocation. It jumps behind the target:
http://otland.net/threads/ninja-vocation-spells.223635/
Yeah man, I saw you're scripts for those spells. They're pretty sweet, infact Im using the basis of your backstab as just an invisibility spell. I'm looking for a spell to combine that with now so you can go invis, sneak up and backstab someone.
 
So this is essentially what I asked for, only 1 problem and one request. Problem is that it deals double damage if the Target is facing me instead of facing the opposite direction. And as for the request, how would I go about making it more like old school exori vis..in the manner of being able to use it 1sqm infront of me instead of using it on the target
Silly me hehe
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid):getDirection()
    local monster = Player(cid):getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, getPlayerLevel(cid) / 5
    local moredmg = 2
    -- 0 north, 1 east, 2 south, 3 west
    if player == monster then
        -- double dmg
        return -((((skillTotal * 0.02) + 4) + (levelTotal)) * moredmg), -((((skillTotal * 0.04) + 9) + (levelTotal)) * moredmg)
    else
        -- regular dmg
        return -(((skillTotal * 0.02) + 4) + (levelTotal)), -(((skillTotal * 0.04) + 9) + (levelTotal))
    end
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
 
Awesome man! Script works without errors, thanks a ton! <3

EDIT: Dang, no errors but it seems to do double damage so long as we're facing the same direction
 
Last edited:
This is a modified version of brutal strike but I think this is what your looking for
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
setCombatParam(combat, COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid):getDirection()
    local monster = Player(cid):getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, getPlayerLevel(cid) / 5
    local moredmg = 2
    -- 0 north, 1 east, 2 south, 3 west
    if (player ==  0 and monster == 2) or (player ==  2 and monster == 0) or (player ==  1 and monster == 3) or (player ==  3 and monster == 1) then
        -- double dmg
        return -((((skillTotal * 0.02) + 4) + (levelTotal)) * moredmg), -((((skillTotal * 0.04) + 9) + (levelTotal)) * moredmg)
    else
        -- regular dmg
        return -(((skillTotal * 0.02) + 4) + (levelTotal)), -(((skillTotal * 0.04) + 9) + (levelTotal))
    end
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end

I am apologizing in advance for the mess you're about to read but here we go.

I think you got the directions wrong + you need a location check to make sure the player is behind his target
let me put a map for you to explain it.

the letter "o" is you the player, and "x" is the target
in every situation where you want to get behind the target, you will be always facing the same way as it does. like so

o-> x->
or
<-x <-o
same for vertical positions

the problem is, if you only check directions for the double damage, then the player can exploit it to be INFRONT of the target and looking away and still do the double damage, like so:

x-> o->
or
<-o <-x

Also if you end up doing position checks, it would be a lot better to use only 1 axis. that way you don't limit the player from doing double damage by standing behind the target but diagonally like so:

o->
....x->
 
@Jotran
Yes, your would work fine. But i would done something like this:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_USECHARGES, 1)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid)
    local myDirection, targetDirection = player:getDirection(), player:getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, player:getLevel() / 5
    local bonusDamage = 2
    if myDirection == targetDirection then
        -- double dmg
        return -((((skillTotal * 0.02) + 4) + (levelTotal)) * bonusDamage), -((((skillTotal * 0.04) + 9) + (levelTotal)) * bonusDamage)
    else
        -- regular dmg
        return -(((skillTotal * 0.02) + 4) + (levelTotal)), -(((skillTotal * 0.04) + 9) + (levelTotal))
    end
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
 
don't we need a posistion check though? if both people face the same direction it will do double dmg now even if the caster is infront of the target
 
I am apologizing in advance for the mess you're about to read but here we go.

I think you got the directions wrong + you need a location check to make sure the player is behind his target
let me put a map for you to explain it.

the letter "o" is you the player, and "x" is the target
in every situation where you want to get behind the target, you will be always facing the same way as it does. like so

o-> x->
or
<-x <-o
same for vertical positions

the problem is, if you only check directions for the double damage, then the player can exploit it to be INFRONT of the target and looking away and still do the double damage, like so:

x-> o->
or
<-o <-x

Also if you end up doing position checks, it would be a lot better to use only 1 axis. that way you don't limit the player from doing double damage by standing behind the target but diagonally like so:

o->
....x->
You're right :( I didn't think about checking that...If I were to make the spell a 1x1beam infront of the caster would this script work?
 
yea, the 1 beam infront of the caster would work just fine, it will make the position check redundant :)
I tried making it 1x1beam but I'm not having the best time haha..I can't seem to make it only hit the ground and not cast on the target. It always applies no dmg or double dmg from every direction depending on how I change it.. Sorry for being a super noob
 
in spells.xml make sure you don't have casterTargetorDirection="1" or needtarget="1" then add direction="1"

should work i think.
 
Here's the script and xml:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

AREA_BEAM1 = {
{1},
{3}
}

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid)
    local myDirection, targetDirection = player:getDirection(), player:getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, player:getLevel() / 5
    local bonusDamage = 2
    if myDirection == targetDirection then
        -- double dmg
        return -((((skillTotal * 0.02) + 4) + (levelTotal)) * bonusDamage), -((((skillTotal * 0.04) + 9) + (levelTotal)) * bonusDamage)
    else
        -- regular dmg
        return -(((skillTotal * 0.02) + 4) + (levelTotal)), -(((skillTotal * 0.04) + 9) + (levelTotal))
    end
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

Code:
<instant group="attack" spellid="404" name="Back Stab" words="exori stab" lvl="45" mana="100" Direction="1" exhaustion="2000" groupcooldown="2000" needlearn="0" script="custom/backstab.lua">
        <vocation name="Assassin"/>
        <vocation name="Rogue"/>
 </instant>
 
i believe you forgot to add this line before function onGetFormulaValues

combat:setArea(AREA_BEAM1)

and in xml, direction="1" with no capital letters
 
i believe you forgot to add this line before function onGetFormulaValues

combat:setArea(AREA_BEAM1)

and in xml, direction="1" with no capital letters
Hahaha, I'm so dumb. Thanks man! It works now

EDIT: Hmmm, is there a way to make it so that I dont have to be targetting the creature/player for the spell to do damage?
 
Last edited:
So if I'm not targeting someone and I use the spell where they're standing I get this error:
Code:
Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/custom/backstab.lua:onGetFormulaValues
(Unknown scriptfile)
data/spells/scripts/custom/backstab.lua:11: attempt to index a nil value
Any ideas on what I should change? Any help is greatly appreciated!

This is my current spell:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

local area = createCombatArea(AREA_BEAM1)
combat:setArea(area)

function onGetFormulaValues(cid, skill, attack, factor)
    local player = Player(cid)
    local myDirection, targetDirection = player:getDirection(), player:getTarget():getDirection()
    local skillTotal, levelTotal = skill * attack, player:getLevel() / 5
    local bonusDamage = 2
    if myDirection == targetDirection then
        -- double dmg
        return -((((skillTotal * 0.3) + 40) + (levelTotal / 2)) * bonusDamage), -((((skillTotal * 0.55) + 80) + (levelTotal / 2)) * bonusDamage)
    else
        -- regular dmg
        return -(((skillTotal * 0.25) + 20) + (levelTotal / 3)), -(((skillTotal * 0.45) + 40) + (levelTotal / 3))
    end
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
 
Back
Top