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

Help with this teleport movement script

wafuboe

Member
Joined
Dec 24, 2010
Messages
881
Solutions
2
Reaction score
22
Hello Otland!

I have this script im using TFS 1.3 supposedly the script works like there are different teleports in lets say 4 cities that teleport you to a lobby with teleports and a Single Teleport will take you back depending the teleport you use in which city.

so i use actionid 1001 for the teleport to send to the lobby for X city and single teleport with actionid 1000 in the lobby to take you back to the temple you came from.\


But it doesnt work no error on console, am i doing things right?

TY!

heres the script
Code:
local teleports = {
    [1001] = {pos = {x = 1093, y = 747, z = 13}, value = 1},
    [1002] = {pos = {x = 1000, y = 1000, z = 7}, value = 2},
    [1003] = {pos = {x = 1000, y = 1000, z = 7}, value = 3}
}

local temples = {
    [1] = {x = 433, y = 504, z = 7}, --Storage value 1 with bring them to this temple
    [2] = {x = 1000, y = 1000, z = 7}, -- Storage value 2 will bring them to this one
    [3] = {x = 1000, y = 1000, z = 7} -- Storage value 3 will bring them to this one
}

local storage = 16000
local aid = 1000
local portalId = 1367

function onStepIn(creature, item, position, fromPosition)
    if item.itemid ~= portalId then return true end
    if not creature:isPlayer() then return true end
  
    local TELEPORT = teleports[item:getActionId()]
  
    if not TELEPORT then
        if item:getActionId() == 1000 then
            local TEMPLE = temples[creature:getStorageValue(storage)]
            if not TEMPLE then return true end
          
            creature:teleportTo(TEMPLE)
            Position(creature:getPosition()):sendMagicEffect(CONST_ME_TELEPORT)
        end
    else
        creature:teleportTo(TELEPORT.pos)
        creature:setStorageValue(storage, TELEPORT.value)
        Position(creature:getPosition()):sendMagicEffect(CONST_ME_TELEPORT)
    end
return true
end

i put this on movement.xml
Code:
<movevent event="StepIn" fromaid="1000" toaid="1009" script="tplobby.lua" />
 
Since clean TFS basically don't have option to save strings in storage we must split pos.X,pos.Y,pos.Z into three different storages.
It can be shorten when you can add in sources option to save strings in storage (to save position in one storage instead of three),
but there we go (tested and working):

movements/scripts/Lobby_teleport.LUA
Lua:
local STORAGE_BACKPOSX = 260011
local STORAGE_BACKPOSY = 260012
local STORAGE_BACKPOSZ = 260013

local LobbyTeleportPos = Position(363,510,7) -- Item Position of Lobby EXIT teleport
local TeleportToLobby = Position(363,511,7) -- Position, where player appear in Lobby

local function cleanBackPos(cid)
    cid:setStorageValue(STORAGE_BACKPOSX, 0)
    cid:setStorageValue(STORAGE_BACKPOSY, 0)
    cid:setStorageValue(STORAGE_BACKPOSZ, 0)
end

function onStepIn(creature, item, position, fromPosition)

    local player = creature:getPlayer()
    if not player then
        return true
    end

    local pstorX = getPlayerStorageValue(player, STORAGE_BACKPOSX)
    local pstorY = getPlayerStorageValue(player, STORAGE_BACKPOSY)
    local pstorZ = getPlayerStorageValue(player, STORAGE_BACKPOSZ)

    if position == LobbyTeleportPos then
        print("Teleport back to saved position in storages and clean storages (saved positions)")
        player:teleportTo(Position(pstorX, pstorY, pstorZ))
        cleanBackPos(player)
    else
        print("Teleports to Lobby and Save entered position in storages")
        player:setStorageValue(STORAGE_BACKPOSX, fromPosition.x)
        player:setStorageValue(STORAGE_BACKPOSY, fromPosition.y)
        player:setStorageValue(STORAGE_BACKPOSZ, fromPosition.z)
        player:teleportTo(TeleportToLobby, true)
    end
  
    return true
end

movements/Movements.XML
Lua:
<movevent event="StepIn" actionid="30011" script="lobby_teleport.lua" />

Put in map editor on your teleports (all entrances to lobby and lobby exit) actionid from movements.xml.
Remember to change storages and position to your own ones.


Cheers,
Fresh.
 
Back
Top