• 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.X+ tfs 1.3 doubt with a lua script (teleport for the position that enter)

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
Hi, i created this code, player use a spell and create a teleport below himself (teleport remove after 5s). [this script is ok]
all players entering teleport are taken to an area (teleport destination), in that area there is a teleport for the player to leave.

I need, if a player entered in teleport, to leave, he will be teleported to the place where the teleport was when he entered, how to do that?
spell.lua (all OK)

LUA:
function tpCreate(position)
    Game.createItem(1387, 1, position):setDestination(Position(1000, 1000, 7))
end

function tpRemove(position)
    position:getTile():getItemById(9485):remove()
end

function onCastSpell(creature, variant)
    tpCreate(creature:getPosition())
    addEvent(tpRemove, 5000, creature:getPosition())

    return combat:execute(creature, variant)

end

teleportBACK.lua [HERE I NEED HELP]
LUA:
function onStepIn(creature, item, position, fromPosition)
    creature:teleportTo(????)
    return true
end

how can i make teleport back to POS, where the teleport created by spell was?
 
Last edited:
Solution
i have this code made in 0.4, i think is a little better, because use only 1 storage, can u help to pass it for 1.x?

Can u help me to pass to 1.x? i really dont understand this functions yet, "sub" "explode" "string.gsub"

Here save a stor
LUA:
local s = 5678

function onStepIn(cid, item, pos)
local mystr = "return {x=xx,y=yy,z=zz}"
local mystr = string.gsub(mystr, "xx", pos.x)
local mystr = string.gsub(mystr, "yy", pos.y)
local mystr = string.gsub(mystr, "zz", pos.z)

setPlayerStorageValue(cid, s, mystr)
doSendMagicEffect(mystr, 75)
return true
end

and here check for a storage and tp
LUA:
function onStepIn(cid)
    local new_pos = getPlayerStorageValue(cid, 5678):sub(2):explode(",")
    doTeleportThing(cid, {x =...
You can use something like this:
LUA:
function Player.savePosition(self)
    local position = self:getPosition()
    self:setStorageValue(99990, position.x)
    self:setStorageValue(99991, position.y)
    self:setStorageValue(99992, position.z)
end

function Player.getSavedPosition(self)
    local x = self:getStorageValue(99990)
    local y = self:getStorageValue(99991)
    local z = self:getStorageValue(99992)
    return Position(x, y, z)
end

All you have to do is save the pos at some point, then later use player:teleportTo(player:getSavedPosition())
 
You can use something like this:
All you have to do is save the pos at some point, then later use player:teleportTo(player:getSavedPosition())

i have this code made in 0.4, i think is a little better, because use only 1 storage, can u help to pass it for 1.x?

Can u help me to pass to 1.x? i really dont understand this functions yet, "sub" "explode" "string.gsub"

Here save a stor
LUA:
local s = 5678

function onStepIn(cid, item, pos)
local mystr = "return {x=xx,y=yy,z=zz}"
local mystr = string.gsub(mystr, "xx", pos.x)
local mystr = string.gsub(mystr, "yy", pos.y)
local mystr = string.gsub(mystr, "zz", pos.z)

setPlayerStorageValue(cid, s, mystr)
doSendMagicEffect(mystr, 75)
return true
end

and here check for a storage and tp
LUA:
function onStepIn(cid)
    local new_pos = getPlayerStorageValue(cid, 5678):sub(2):explode(",")
    doTeleportThing(cid, {x = new_pos[1], y = new_pos[2], z = new_pos[3]})
    return true
end
 
i have this code made in 0.4, i think is a little better, because use only 1 storage, can u help to pass it for 1.x?

Can u help me to pass to 1.x? i really dont understand this functions yet, "sub" "explode" "string.gsub"

Here save a stor
LUA:
local s = 5678

function onStepIn(cid, item, pos)
local mystr = "return {x=xx,y=yy,z=zz}"
local mystr = string.gsub(mystr, "xx", pos.x)
local mystr = string.gsub(mystr, "yy", pos.y)
local mystr = string.gsub(mystr, "zz", pos.z)

setPlayerStorageValue(cid, s, mystr)
doSendMagicEffect(mystr, 75)
return true
end

and here check for a storage and tp
LUA:
function onStepIn(cid)
    local new_pos = getPlayerStorageValue(cid, 5678):sub(2):explode(",")
    doTeleportThing(cid, {x = new_pos[1], y = new_pos[2], z = new_pos[3]})
    return true
end
You can't, that's why I gave you the previous code; storages don't take string values anymore.
 
Solution
i have this code made in 0.4, i think is a little better, because use only 1 storage, can u help to pass it for 1.x?

Can u help me to pass to 1.x? i really dont understand this functions yet, "sub" "explode" "string.gsub"

Here save a stor
LUA:
local s = 5678

function onStepIn(cid, item, pos)
local mystr = "return {x=xx,y=yy,z=zz}"
local mystr = string.gsub(mystr, "xx", pos.x)
local mystr = string.gsub(mystr, "yy", pos.y)
local mystr = string.gsub(mystr, "zz", pos.z)

setPlayerStorageValue(cid, s, mystr)
doSendMagicEffect(mystr, 75)
return true
end

and here check for a storage and tp
LUA:
function onStepIn(cid)
    local new_pos = getPlayerStorageValue(cid, 5678):sub(2):explode(",")
    doTeleportThing(cid, {x = new_pos[1], y = new_pos[2], z = new_pos[3]})
    return true
end
You can use this: [LIB] Storing Information and use one special storage to save your position as string.
As Delusion said, without this, u can only save integer values in storages.

--Edit
When i was writing the post, he marked as solved, i hope don't have problem.
 
You can use this: [LIB] Storing Information and use one special storage to save your position as string.
As Delusion said, without this, u can only save integer values in storages.

--Edit
When i was writing the post, he marked as solved, i hope don't have problem.
thx for answer, but i think the better way is the method that @Delusion saied.
 
Back
Top