• 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!
 
I have this spell from my Original Species RPG.
The Elf Assassin used it.

It is very simple, but I don't script in TFS 1.X so someone can translate:

I just spent a few minutes looking through TFS 1.X luafunctions.cpp trying to find the functions needed to do this, and I give up. (This is why I use TFS 0.3.6).

Basically you do this:
Code:
function onGetFormulaValues(cid, skill, attack, factor)
   local newpos = getPositionByDirection(getCreaturePosition(cid), getCreatureLookDirection(cid), 1)--Get the position in front of the player
   local target = getTopCreature(pos) --Get the top creature at that position
  local bonusDamage = 1 -- Set Damage Multiplier to 1
   if isCreature(target) then --if there is a Top Creature
     local dir = getCreatureLookDirection(cid)+2 -- Get the opposite Direction
     if dir > 3 then dir = dir - 4 end -- correct if you are facing south or west
     local tdir = getCreatureLookDirection(target) -- get Targets Look Direction
     if  tdir = dir then -- See if Target is facing away from you
       bonusDamage = 2 -- Set Damage Multiplier to 2
     end
   end
  local skillTotal, levelTotal = skill * attack, player:getLevel() / 5
  return -(((skillTotal * 0.25) + 20) + (levelTotal / 3)), -(((skillTotal * 0.45) + 40) + (levelTotal / 3))
end

Even with this you have a big problem.
  • If more than 1 person is on the Damage Tile then only the top person is used to determine double damage (but everyone on the tile will be hit).
 
This will resolve the non-target issue
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 = player:getDirection()
    -- are we targeting anything?
    local targetDirection = (player:getTarget() ~= nil) and player:getTarget():getDirection() or nil
    local skillTotal, levelTotal = skill * attack, player:getLevel() / 5
    local bonusDamage = 2
    -- make sure we have a target & are facing the opposite direction
    if targetDirection ~= nil and 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
 
Just add tag for needTarget and you do not then need to check for target in the script:
Code:
<instant group="attack" spellid="404" name="Back Stab" words="exori stab" lvl="45" mana="100" needtarget="1" exhaustion="2000" groupcooldown="2000" needlearn="0" script="custom/backstab.lua">
        <vocation name="Assassin"/>
        <vocation name="Rogue"/>
</instant>
 
So I'm using what Jotran posted, I can cast the spell without a target and it deals damage with no errors...but it doesn't calculate the damage amplification if I'm not targetting the creature. Thanks to everyone for the help so far, you guys are the best!
 
Back
Top