• 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 Confused about this spell following target.

Werewolf

Forbidden Ascension
Joined
Jul 15, 2012
Messages
886
Reaction score
123
TFS 0.3.6
When i cast this spell, it targets the monster and goes through the frames, but it constantly follows the monster and then hits it directly, even if its running around.

I want the spell to target the monster, but stay in the spot were the monster originally was, so that if the monster runs away, it could avoid being hit by the spell.

Spells.xml
Code:
<instant name="crush" words="exoricru" lvl="35" mana="40" prem="0" range="10" casterTargetOrDirection="1" blockwalls="0" exhaustion="4000" groups="1,1000" icon="107" needlearn="0" event="script" value="crush.lua">
     <vocation id="58"/>
     <vocation id="59"/>
     <vocation id="60"/>
     <vocation id="61"/>
     <vocation id="62"/>
   </instant>





This is the example spell that im using for this post.



crush.lua

Code:
local combat0_Brush = createCombatObject()
setCombatParam(combat0_Brush, COMBAT_PARAM_EFFECT, CONST_ME_GROUNDSHAKER)
setCombatParam(combat0_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatArea(combat0_Brush,createCombatArea({{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0}}))
-- Areas/Combat for 100ms
local combat1_Brush = createCombatObject()
setCombatParam(combat1_Brush, COMBAT_PARAM_EFFECT, CONST_ME_GROUNDSHAKER)
setCombatParam(combat1_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatArea(combat1_Brush,createCombatArea({{0, 0, 1, 1, 0, 1, 1, 0, 0},
{0, 1, 1, 0, 0, 0, 1, 1, 0},
{1, 1, 0, 0, 0, 0, 0, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 2, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 0, 1, 1},
{0, 1, 1, 0, 0, 0, 1, 1, 0},
{0, 0, 1, 1, 0, 1, 1, 0, 0}}))
-- Areas/Combat for 1000ms
local combat2_Brush = createCombatObject()
setCombatParam(combat2_Brush, COMBAT_PARAM_EFFECT, CONST_ME_GROUNDSHAKER)
setCombatParam(combat2_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatArea(combat2_Brush,createCombatArea({{0, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 0, 1, 1, 0, 0},
{0, 1, 1, 0, 0, 0, 1, 1, 0},
{1, 1, 0, 0, 2, 0, 0, 1, 1},
{0, 1, 1, 0, 0, 0, 1, 1, 0},
{0, 0, 1, 1, 0, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0}}))
-- Areas/Combat for 2000ms
local combat3_Brush = createCombatObject()
setCombatParam(combat3_Brush, COMBAT_PARAM_EFFECT, CONST_ME_GROUNDSHAKER)
setCombatParam(combat3_Brush, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatArea(combat3_Brush,createCombatArea({{0, 0, 1, 0, 0},
{0, 1, 1, 1, 0},
{1, 1, 3, 1, 1},
{0, 1, 1, 1, 0},
{0, 0, 1, 0, 0}}))
-- =============== CORE FUNCTIONS ===============
local function RunPart(c,cid,var,dirList,dirEmitPos) -- Part
   if (isCreature(cid)) then
     doCombat(cid, c, var)
     if (dirList ~= nil) then -- Emit distance effects
       local i = 2;
       while (i < #dirList) do
         doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList,y=dirEmitPos.y-dirList[i+1],z=dirEmitPos.z},dirList[1])
         i = i + 2
       end 
     end
   end
end
function onCastSpell(cid, var)
   local startPos = getCreaturePosition(cid)
   RunPart(combat0_Brush,cid,var)
   addEvent(RunPart,100,combat1_Brush,cid,var)
   addEvent(RunPart,1000,combat2_Brush,cid,var)
   addEvent(RunPart,2000,combat3_Brush,cid,var)
   return true
end
 
Last edited:
That is a really ugly spell... I'll take a look at it though, you should use code tags tho when posting code.
 
That is a really ugly spell... I'll take a look at it though, you should use code tags tho when posting code.

There i changed it.

also this is just an example spell, i used some random spell maker to generate. my real concern is that when i make multi-frame spells like this one, it will follow the target no matter how far it runs.

i want the spell to cast at target, but then stay in that spot.
 
There i changed it.

also this is just an example spell, i used some random spell maker to generate. my real concern is that when i make multi-frame spells like this one, it will follow the target no matter how far it runs.

i want the spell to cast at target, but then stay in that spot.
If we review the sources we can see the definition of doCombat
cid is the creature
combat is what the name implies
& var is the position of the creature so send startPos instead of var as your argument & see how it goes.
 
However I would use a table because of the callback
Code:
local startPos = {}
function onCastSpell(cid, var)
if next(startPos) == nil then
   startPos = getCreaturePosition(cid)
end
 
Ok i got it now,
Code:
function onCastSpell(cid, var)
var.pos = {x = getCreaturePosition(cid).x, y = getCreaturePosition(cid).y, z = getCreaturePosition(cid).z}
then just pass var
so much for that theory.. o well

Hey any answer is better then no answer :D
 
Last edited:
Ok i got it now,
Code:
function onCastSpell(cid, var)
var.pos = {x = getCreaturePosition(cid).x, y = getCreaturePosition(cid).y, z = getCreaturePosition(cid).z}
then just pass var
so much for that theory.. o well

Hey any answer is better then no answer :D



i dont know what you mean by Pass Var
 
This is pretty easy.

What you need to do is grab the position of the target in onCastSpell(cid, var), and use that.

So basically this.
Code:
function onCastSpell(cid, var)
local startPos = getCreaturePosition(cid)
local target = variantToNumber(var)
if isCreature(target) then
local pos = getCreaturePosition(target)
var = positionToVariant({x=pos.x,y=pos.y,z=pos.z})
end
RunPart(combat0_Brush,cid,var)
addEvent(RunPart,100,combat1_Brush,cid,var)
addEvent(RunPart,1000,combat2_Brush,cid,var)
addEvent(RunPart,2000,combat3_Brush,cid,var)
return true
end

  1. You convert var into a creature using variantToNumber(var) (you have this set as casterDirectionorTarget so you have to make sure the variant is a creature before moving to step 2).
  2. Then you grab the targets position using getCreaturePosition(target).
  3. Then you convert that position into the variant using positionToVariant(pos), so instead of targeting the creature, it is targeting that creatures position.
I think the above should work if you replace it in your original spell. There are other ways to do it, but without changing your spell much this was the easiest way.
 
This is pretty easy.

What you need to do is grab the position of the target in onCastSpell(cid, var), and use that.

So basically this.
Code:
function onCastSpell(cid, var)
local startPos = getCreaturePosition(cid)
local target = variantToNumber(var)
if isCreature(target) then
local pos = getCreaturePosition(target)
var = positionToVariant({x=pos.x,y=pos.y,z=pos.z})
end
RunPart(combat0_Brush,cid,var)
addEvent(RunPart,100,combat1_Brush,cid,var)
addEvent(RunPart,1000,combat2_Brush,cid,var)
addEvent(RunPart,2000,combat3_Brush,cid,var)
return true
end

  1. You convert var into a creature using variantToNumber(var) (you have this set as casterDirectionorTarget so you have to make sure the variant is a creature before moving to step 2).
  2. Then you grab the targets position using getCreaturePosition(target).
  3. Then you convert that position into the variant using positionToVariant(pos), so instead of targeting the creature, it is targeting that creatures position.
I think the above should work if you replace it in your original spell. There are other ways to do it, but without changing your spell much this was the easiest way.



Thank you! very much, it works perfectly.
 
This is pretty easy.

What you need to do is grab the position of the target in onCastSpell(cid, var), and use that.

So basically this.
Code:
function onCastSpell(cid, var)
local startPos = getCreaturePosition(cid)
local target = variantToNumber(var)
if isCreature(target) then
local pos = getCreaturePosition(target)
var = positionToVariant({x=pos.x,y=pos.y,z=pos.z})
end
RunPart(combat0_Brush,cid,var)
addEvent(RunPart,100,combat1_Brush,cid,var)
addEvent(RunPart,1000,combat2_Brush,cid,var)
addEvent(RunPart,2000,combat3_Brush,cid,var)
return true
end

  1. You convert var into a creature using variantToNumber(var) (you have this set as casterDirectionorTarget so you have to make sure the variant is a creature before moving to step 2).
  2. Then you grab the targets position using getCreaturePosition(target).
  3. Then you convert that position into the variant using positionToVariant(pos), so instead of targeting the creature, it is targeting that creatures position.
I think the above should work if you replace it in your original spell. There are other ways to do it, but without changing your spell much this was the easiest way.
This is really good info thanks a lot @Flatlander
 
Back
Top