Misterion
New Member
- Joined
- Jan 24, 2014
- Messages
- 52
- Reaction score
- 4
EDIT: I forgot, im using TFS 0.3.6
I know it sounds like a simple question but it's for a custom spell, where the caster becomes invisible and sneaks up on the enemy when he clicks to attack. I wonder if there is any function to activate this only if the enemy is melee.
Explaining the spell: Conjuring it works like a utana vid for a short period, in case you attack someone you move behind the target and cause damage. I wish I had a way to limit this distance so it would not become a spell where the user could cross walls.
Here is the script
Thanks for listening
I know it sounds like a simple question but it's for a custom spell, where the caster becomes invisible and sneaks up on the enemy when he clicks to attack. I wonder if there is any function to activate this only if the enemy is melee.
Explaining the spell: Conjuring it works like a utana vid for a short period, in case you attack someone you move behind the target and cause damage. I wish I had a way to limit this distance so it would not become a spell where the user could cross walls.
Here is the script
Code:
local condition = createConditionObject(CONDITION_INVISIBLE)
setConditionParam(condition, CONDITION_PARAM_TICKS, 5000)
local function isWalkable(cid, pos)
pos.stackpos = 253
if doTileQueryAdd(cid, pos) == 1 then -- checks if we can add cid to a position of choice
return true
end
return false
end
local function jumpBehindTarget(cid, target)
local tPos = getCreaturePosition(target)
local tPositions = {
north = {x = tPos.x, y = tPos.y - 1, z = tPos.z},
east = {x = tPos.x + 1, y = tPos.y, z = tPos.z},
west = {x = tPos.x - 1, y = tPos.y, z = tPos.z},
south = {x = tPos.x, y = tPos.y + 1, z = tPos.z}
}
local tDir = getPlayerLookDir(target)
if tDir == NORTH then
dir = tPositions.south
elseif tDir == EAST then
dir = tPositions.west
elseif tDir == WEST then
dir = tPositions.east
elseif tDir == SOUTH then
dir = tPositions.north
end
return dir
end
local function checkHasTarget(cid, count, oldPos)
local target = getCreatureTarget(cid)
if target ~= 0 then
local behindTarget = jumpBehindTarget(cid, target)
if isWalkable(cid, behindTarget) then
doTeleportThing(cid, behindTarget)
--addEvent(doTeleportThing, 100, cid, oldPos)
else
doTeleportThing(cid, getCreaturePosition(target))
--addEvent(doTeleportThing, 100, cid, oldPos)
end
doCreatureSetLookDir(cid, getPlayerLookDir(target))
doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -20, -100, CONST_ME_FIREATTACK)
doRemoveCondition(cid, CONDITION_INVISIBLE)
return true
end
addEvent(checkHasTarget, 100, cid, count - 1, getCreaturePosition(cid))
end
function onCastSpell(cid, var)
local pPos = getCreaturePosition(cid)
doSendMagicEffect(pPos, CONST_ME_POFF)
doAddCondition(cid, condition)
addEvent(checkHasTarget, 50, cid, 50, pPos)
return true
end
Thanks for listening
Last edited: