Teleport to player spell

Tbol

Member
Joined
Apr 7, 2019
Messages
71
Reaction score
6
Hello i need spell for tfs 1.2 that teleport next to a player when you target him
Should have: You cannot use this spell in protecion zone
You cannot enter to protection zone
Wont let to teleport trough doors and any other item that is not passable

bump

bump

bump

bump

bump

bump
 

calidacs

New Member
Joined
Feb 19, 2013
Messages
8
Reaction score
1
Hope that will help you.

Lua:
function onCastSpell(cid, var)
local pos1 = getCreaturePosition(cid)
local target = getCreatureTarget(cid)
local pos2 = getCreaturePosition(target)
if target == isCreature then
doTeleportThing(cid,pos2)
doSendMagicEffect(pos1, 2) //here you set your effect after teleport, since its a spell i though u might need an effect aswell.
else
doPlayerSendTextMessage(cid,20,'Select your target.')
end
end
also if you will want to add tp to monsters aswell just edit this lane :
Lua:
if target ==isCreature then
to this:
Lua:
if target == isMonster or isCreature then
 
Last edited:

oen432

Intermediate OT User
Joined
Oct 3, 2014
Messages
373
Reaction score
347
Location
Poland
Hope that will help you.

Lua:
function onCastSpell(cid, var)
local pos1 = getCreaturePosition(cid)
local target = getCreatureTarget(cid)
local pos2 = getCreaturePosition(target)
if target == isCreature then
doTeleportThing(cid,pos2)
doSendMagicEffect(pos1, 2) //here you set your effect after teleport, since its a spell i though u might need an effect aswell.
else
doPlayerSendTextMessage(cid,20,'Select your target.')
end
end
also if you will want to add tp to monsters aswell just edit this lane :
Lua:
if target ==isCreature then
to this:
Lua:
if target == isMonster or isCreature then
Did you read what he needs?
Should have: You cannot use this spell in protecion zone
You cannot enter to protection zone
Wont let to teleport trough doors and any other item that is not passable
 

calidacs

New Member
Joined
Feb 19, 2013
Messages
8
Reaction score
1
Did you read what he needs?
All he have to do is make sure to add in spells.xml in the spell line this:
Code:
needtarget="1" blockwalls="1"
i though thats obvious that you cant cast this spell in pz since you cant have a toggled target in pzzone lol
 

oen432

Intermediate OT User
Joined
Oct 3, 2014
Messages
373
Reaction score
347
Location
Poland
All he have to do is make sure to add in spells.xml in the spell line this:
Code:
needtarget="1" blockwalls="1"
i though thats obvious that you cant cast this spell in pz since you cant have a toggled target in pzzone lol
"teleport next to a player", not at his position. You have to check if there is a free space to teleport to so player won't get stuck.
 
Last edited by a moderator:
OP
Tbol

Tbol

Member
Joined
Apr 7, 2019
Messages
71
Reaction score
6
"teleport next to a player", not at his position. You have to check if there is a free space to teleport to so player won't get stuck.
Yea its true now it teleport on player not next to him
 

Sleet

Member
Joined
Sep 3, 2016
Messages
107
Reaction score
7
Sorry for the wait

Here's the code:

data/spells/spells.xml

XML:
    <instant group="support" name="Player teleport" words="utito hur" level="0" mana="0" premium="0" aggressive="1" blockwalls="1" needtarget="1" cooldown="0" groupcooldown="0" needlearn="0" script="support/player_teleport.lua">
        <vocation name="Sorcerer"/>
        <vocation name="Master Sorcerer"/>
        <vocation name="Druid"/>
        <vocation name="Elder Druid"/>
    </instant>
data/spells/scripts/support/player_teleport.lua

Lua:
local function teleportPos(ppos, tpos)
    local pdiff = {
    x = ppos.x - tpos.x,
    y = ppos.y - tpos.y
    }
    if pdiff.x > 0 then
        tpos.x = tpos.x + 1
    elseif pdiff.x < 0 then
        tpos.x = tpos.x - 1
    elseif pdiff.y > 0 then
        tpos.y = tpos.y + 1
    elseif pdiff.y < 0 then
        tpos.y = tpos.y - 1
    end
    return tpos
end

local function checkPos(tgtpos, telpos)
    local tile = Tile(telpos)
    local rtile = {
        {-1, -1}, {0, -1}, {1, -1},
        {-1,  0},          {1,  0},
        {-1,  1}, {0,  1}, {1,  1}
    }
    local finalpos = tgtpos
    local i = 1  
    math.randomseed(os.time())
    while i < 9 do
        if not tile:getGround() or tile:getCreatureCount() > 0 or tile:hasFlag(bit.bor(TILESTATE_IMMOVABLEBLOCKSOLID, TILESTATE_IMMOVABLEBLOCKPATH, TILESTATE_FLOORCHANGE, TILESTATE_PROTECTIONZONE, TILESTATE_TELEPORT)) then
            local j = math.random(i, 8)
            finalpos = tgtpos
            finalpos.x = tgtpos.x + rtile[j][1]
            finalpos.y = tgtpos.y + rtile[j][2]
            rtile[j], rtile[i] = rtile[i], rtile[j]
            tile = Tile(finalpos)
            i = i + 1
        else
            return finalpos
        end
    end
    return false
end

function onCastSpell(creature, variant)
    local tgtpos = creature:getTarget():getPosition()
    local telpos = teleportPos(creature:getPosition(), tgtpos)
    local checkpos = checkPos(tgtpos, telpos)
    if creature:getTarget() ~= isCreature then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        creature:sendCancelMessage("You can only teleport to other players")
        return false
    elseif not checkpos then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        creature:sendCancelMessage("Not enough room")
        return false
    else
        creature:teleportTo(checkpos)
        creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    end
    return false
end
 
Top