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

Teleport calculate pos to pos tfs 1.0

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,087
Solutions
15
Reaction score
379
Location
Sweden
YouTube
Joriku
Hello, i'm looking for something like a teleport with unq id for example if i enter a teleport from one position/temple then enter the tp back i get back but <- if i enter a tp from a diffrent place and enter the same tp back i get to the same temple i we're at.
 
Solution
Can also be done like this.
Lua:
local cityPos = Position(XXXX, YYYY, Z)
local storages = {
    ['x'] = 15000,
    ['y'] = 15001,
    ['z'] = 15002
}

local function telePosition(cid, p, aid)
    local player = Player(cid)
    if not player then
        return false
    end
  
    local set = aid == storages.x and true or false
    local method = set and setStorageValue or getStorageValue
    local newPos = {x = 0, y = 0, z = 0}
  
    for i, value in pairs(storages) do
        newPos[i] = player:method(value, p[i])
    end
    local destination = set and cityPos or newPos
    player:teleportTo(destination, true)
    destination:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

function onStepIn(creature, item, position...
Enter -> POS A | Exit -> POS B
Enter -> POS B | Exit -> POS A

Enter -> POS C | Exit -> POS B
Enter -> POS B | Exit -> POS C

Correct? or no?

Your explanation is confusing.
 
Enter -> POS A | Exit -> POS B
Enter -> POS B | Exit -> POS A

Enter -> POS C | Exit -> POS B
Enter -> POS B | Exit -> POS C

Correct? or no?

Your explanation is confusing.
yeah, like that sorry for my explanation
 
Hello, I hope this work for you, the code you want is something like this, no?

23622325_1612913365433146_5630575253292787850_n.jpg


In your map editor add the actionid '15000' to any teleport/ground/item you want, that teleport.
(PD. Add AcionID on ground because maybe if you put tpDestination on remeres, it can give debug.)

23561474_1612913335433149_8632799730741850646_n.jpg


Add in 'data/movements/movements.xml' this lines:
<movevent event="StepIn" actionid="15000" script="teleport_city.lua" /> -- or the name you what want.lua
<movevent event="StepIn" actionid="15001" script="teleport_city.lua" />

Create a file called: 'teleport_city.lua' in 'data/movements/movements/script/' and in file write copy-paste this lines:
Lua:
function onStepIn(creature, item, position, fromPosition)
    local cityPos = Position(XXXX, YYYY, Z)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end
    if item.actionid == 15000 then
        player:setStorageValue(15000, position.x)
        player:setStorageValue(15001, position.y)
        player:setStorageValue(15002, position.z)
        player:teleportTo(cityPos, true)
        cityPos:sendMagicEffect(CONST_ME_MAGIC_BLUE)       
    elseif item.actionid == 15001 then
        local x = player:getStorageValue(15000)
        local y = player:getStorageValue(15001)
        local z = player:getStorageValue(15002)
        local pos = {x=x, y=y, z=z}
        player:teleportTo(pos, true)
        pos:sendMagicEffect(CONST_ME_MAGIC_BLUE)       
    end   
    return true
end

Hope this work for you, regards.
 
Last edited:
There's a small bug in this code, lines 16 and 17 should be:
Lua:
local y = player:getStorageValue(15001)
local z = player:getStorageValue(15002)
 
Can also be done like this.
Lua:
local cityPos = Position(XXXX, YYYY, Z)
local storages = {
    ['x'] = 15000,
    ['y'] = 15001,
    ['z'] = 15002
}

local function telePosition(cid, p, aid)
    local player = Player(cid)
    if not player then
        return false
    end
  
    local set = aid == storages.x and true or false
    local method = set and setStorageValue or getStorageValue
    local newPos = {x = 0, y = 0, z = 0}
  
    for i, value in pairs(storages) do
        newPos[i] = player:method(value, p[i])
    end
    local destination = set and cityPos or newPos
    player:teleportTo(destination, true)
    destination:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

function onStepIn(creature, item, position, fromPosition)
    return telePosition(creature:getId(), position, item.actionid)
end
 
Solution
Back
Top