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

TFS 0.X Spell get creature back

sabodden

Member
Joined
Sep 27, 2019
Messages
138
Reaction score
18
I have this spell, to teleport player to a target

Code:
<instant name="Jump Target" words="jump target" range="5" maglv="11" mana="100" prem="0" aggressive="0" needtarget="1" params="0" exhaustion="2000" needlearn="0" event="script" value="attack/jump target.lua">
        <vocation id="1"/>
        <vocation id="5"/>
    </instant>

Code:
local config = {
    effect = 65, -- efeito
}

function onCastSpell(cid, var)
    local target = variantToNumber(var)

    if isCreature(cid) and isCreature(target) then
        local lookingDirection = getCreatureLookDirection(target)
        print(lookingDirection)


        doSendMagicEffect(getThingPos(cid), config.effect)
        doTeleportThing(cid, getThingPos(target))
        doSendMagicEffect(getThingPos(cid), config.effect)
    end
    return true
end

But i would like to make some changes...
It teleport player to target position, i would like to teleport player to the target back

lookingDirection prints:
0 north, 2 south, 1 east, 3 west

But how to detect back target position, if is valid to teleport and teleport if it is?
 
Solution
Lua:
local config = {
    effect = 65, -- efeito
    dir = {
        [0] = 2,
        [1] = 3,
        [2] = 0,
        [3] = 1
    }
}

local function isWalkable(cid, pos)
    if isCreature(getTopCreature(pos).uid) then
        return true
    end

    if not pos or type(pos) ~= "table" then
        return false
    end
    pos.stackpos = 0
    if not getThingFromPos(pos) then
        return false
    end
    if getTileThingByPos(pos).uid ~= 0 then
    local n = getTileInfo(pos)
        if (doTileQueryAdd(cid, pos) == 1) then
            return true
        end
    return false
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if hasProperty(getThingFromPos(pos).uid, 2)...
Lua:
local config = {
    effect = 65, -- efeito
    dir = {
        [0] = 2,
        [1] = 3,
        [2] = 0,
        [3] = 1
    }
}

local function isWalkable(cid, pos)
    if isCreature(getTopCreature(pos).uid) then
        return true
    end

    if not pos or type(pos) ~= "table" then
        return false
    end
    pos.stackpos = 0
    if not getThingFromPos(pos) then
        return false
    end
    if getTileThingByPos(pos).uid ~= 0 then
    local n = getTileInfo(pos)
        if (doTileQueryAdd(cid, pos) == 1) then
            return true
        end
    return false
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if hasProperty(getThingFromPos(pos).uid, 2) then
            return false
        end
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if getTilePzInfo(pos) then  
            return false
        end
    end
    return true
end

function onCastSpell(cid, var)
local target = variantToNumber(var)
    if isCreature(cid) and isCreature(target) then
    local lookDir = getCreatureLookDirection(target)
    local jPos = getPositionByDirection(getThingPos(target), config.dir[lookDir], 1)
        if isWalkable(cid, jPos) then
            doSendMagicEffect(getThingPos(cid), config.effect)
            doTeleportThing(cid, jPos)
        end
    end
    return true
end
 
Solution
Lua:
local config = {
    effect = 65, -- efeito
    dir = {
        [0] = 2,
        [1] = 3,
        [2] = 0,
        [3] = 1
    }
}

local function isWalkable(cid, pos)
    if isCreature(getTopCreature(pos).uid) then
        return true
    end

    if not pos or type(pos) ~= "table" then
        return false
    end
    pos.stackpos = 0
    if not getThingFromPos(pos) then
        return false
    end
    if getTileThingByPos(pos).uid ~= 0 then
    local n = getTileInfo(pos)
        if (doTileQueryAdd(cid, pos) == 1) then
            return true
        end
    return false
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if hasProperty(getThingFromPos(pos).uid, 2) then
            return false
        end
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if getTilePzInfo(pos) then 
            return false
        end
    end
    return true
end

function onCastSpell(cid, var)
local target = variantToNumber(var)
    if isCreature(cid) and isCreature(target) then
    local lookDir = getCreatureLookDirection(target)
    local jPos = getPositionByDirection(getThingPos(target), config.dir[lookDir], 1)
        if isWalkable(cid, jPos) then
            doSendMagicEffect(getThingPos(cid), config.effect)
            doTeleportThing(cid, jPos)
        end
    end
    return true
end

it's working guys, perfect man, thank you so much!
 
Back
Top