• 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 1.3 pushTarget & pullTarget

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,756
Solutions
578
Reaction score
5,305
push_pull_target.gif
Lua:
-- pushTarget(creatureId, creatureId, 1+, true/false)
function pushTarget(creatureId, targetId, amount, dynamic) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y 
        nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x - (x ~= 0 and 0 or x), targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end
Lua:
-- pullTarget(creatureId, creatureId, 1+, true/false)
function pullTarget(creatureId, targetId, amount, dynamic) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        if creaturePosition:getDistance(targetCurrentPosition) == 1 then
            return
        end
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y   
        nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x + (x ~= 0 and 0 or x), targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end

single target spell example
area target spell example
 
Last edited:
sorry that I'm a noob, but where do I install this?
Should it be installed inside the spell?
 
sorry that I'm a noob, but where do I install this?
Should it be installed inside the spell?
as example

data/lib/core/core.lua
Lua:
dofile('data/lib/core/xikiniCustomFunctions&Libs.lua')

data/lib/core/xikiniCustomFunctions&Libs.lua
Lua:
put the functions in here
 
as example

data/lib/core/core.lua
Lua:
dofile('data/lib/core/xikiniCustomFunctions&Libs.lua')

data/lib/core/xikiniCustomFunctions&Libs.lua
Lua:
put the functions in here
ok, doing it now, thanks
 
tim burton batman GIF
 
View attachment 55892
Lua:
-- pushTarget(creatureId, creatureId, 1+, true/false)
function pushTarget(creatureId, targetId, amount, dynamic) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y
        nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x - (x ~= 0 and 0 or x), targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end
Lua:
-- pullTarget(creatureId, creatureId, 1+, true/false)
function pullTarget(creatureId, targetId, amount, dynamic) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        if creaturePosition:getDistance(targetCurrentPosition) == 1 then
            return
        end
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y  
        nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x + (x ~= 0 and 0 or x), targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end

single target spell example
area target spell example
Is there a chance you could implement 'ignore mob name' for training monks and such? ❤️
 
Is there a chance you could implement 'ignore mob name' for training monks and such? ❤️
Lua:
-- pushTarget(creatureId, creatureId, 1+, true/false[, table])
function pushTarget(creatureId, targetId, amount, dynamic, ignoredCreatures) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    if ignoredCreatures and table.contains(ignoredCreatures, target:getName():lower()) then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y
        nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x - (x ~= 0 and 0 or x), targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end
Lua:
-- pullTarget(creatureId, creatureId, 1+, true/false[, table])
function pullTarget(creatureId, targetId, amount, dynamic, ignoredCreatures) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    if ignoredCreatures and table.contains(ignoredCreatures, target:getName():lower()) then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        if creaturePosition:getDistance(targetCurrentPosition) == 1 then
            return
        end
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y   
        nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x + (x ~= 0 and 0 or x), targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end

Example: pullTarget(creatureId, targetId, 1, true, {"training monk", "rat", "demon"})
 
Great release! @Xikini !
How about pushing into House's / Protection Zones?
I'm not seeing an condition about that in those functions.
 
Great release! @Xikini !
How about pushing into House's / Protection Zones?
I'm not seeing an condition about that in those functions.
Didn't test, but this should fix that issue.
Lua:
-- pushTarget(creatureId, creatureId, 1+, true/false[, table])
function pushTarget(creatureId, targetId, amount, dynamic, ignoredCreatures) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    if ignoredCreatures and table.contains(ignoredCreatures, target:getName()) then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y 
        nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x - (x ~= 0 and 0 or x), targetCurrentPosition.y - y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x - x, targetCurrentPosition.y - (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end
Lua:
-- pullTarget(creatureId, creatureId, 1+, true/false[, table])
function pullTarget(creatureId, targetId, amount, dynamic, ignoredCreatures) -- dynamic means it'll look for extra squares
    local creature = Creature(creatureId)
    local target = Creature(targetId)
    if not creature or not target or creature == target then
        return false
    end
    if ignoredCreatures and table.contains(ignoredCreatures, target:getName():lower()) then
        return false
    end
    local creaturePosition = creature:getPosition()
    local targetInitialPosition = target:getPosition()
    if creaturePosition.z ~= targetInitialPosition.z then
        return false
    end
    local nextPosition
    local targetCurrentPosition
    local x, y, x_temp, y_temp
    local tile
    for i = 1, amount do
        targetCurrentPosition = target:getPosition()
        if creaturePosition:getDistance(targetCurrentPosition) == 1 then
            return
        end
        x_temp = targetCurrentPosition.x - creaturePosition.x
        y_temp = targetCurrentPosition.y - creaturePosition.y
        x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
        y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
        x_temp = x_temp > 0 and x_temp * -1 or x_temp
        y_temp = y_temp > 0 and y_temp * -1 or y_temp
        x = x_temp > y_temp and 0 or x
        y = y_temp > x_temp and 0 or y   
        nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
        tile = Tile(nextPosition)
        if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
            target:teleportTo(nextPosition)
        elseif dynamic then
            x_temp = targetInitialPosition.x - creaturePosition.x
            y_temp = targetInitialPosition.y - creaturePosition.y
            x = x_temp < 0 and 1 or x_temp == 0 and 0 or -1
            y = y_temp < 0 and 1 or y_temp == 0 and 0 or -1
            for n = 1, 4 do
                if n == 1 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 2 then
                    nextPosition = Position(targetCurrentPosition.x + (x ~= 0 and 0 or x), targetCurrentPosition.y + y, creaturePosition.z)
                elseif n == 3 then
                    nextPosition = Position(targetCurrentPosition.x + x, targetCurrentPosition.y + (y ~= 0 and 0 or y), creaturePosition.z)
                else
                    return
                end
                tile = Tile(nextPosition)
                if tile and tile:isWalkable() and not Creature(tile:getTopCreature()) and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
                    target:teleportTo(nextPosition)
                    break
                end
            end
        else
            return
        end
    end
end
 
Back
Top