• 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] Teleport Command - !tp <dest>

Sarah Wesker

ƐƖєgαηт Sуηтαx ❤
Staff member
TFS Developer
Support Team
Joined
Mar 16, 2017
Messages
1,418
Solutions
155
Reaction score
1,973
Location
London
GitHub
MillhioreBT
Twitch
millhiorebt
data/scripts/teleportcommand.lua
Lua:
local destinations = {
    -- please use lower case names
    --["place name"] = { position=Position(100, 100, 7), inPz=true, level=100, infight=false }
    ["temple"] = { position=Position(3191, 1809, 7) },
    ["depot"] = { position=Position(3190, 1800, 7) },
    ["house"] = { house=true, infight=false }
}

local destString = "Available destinations:"
for name, _ in pairs(destinations) do
    destString = string.format("%s %s%s", destString, name, (next(destinations, name) and ',' or '.'))
end

local talkAction = TalkAction("!tp")

function talkAction.onSay(player, words, param, type)
    local destName = param:trim()
    local destination = destinations[destName] or destinations[destName:lower()]
    if not destination then
        player:sendCancelMessage(string.format("Destination %s does not exists.", destName))
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, destString)
        return false
    end

    local tile
    if destination.house then
        local house = player:getHouse()
        if not house then
            player:sendCancelMessage("You not have a house.")
            return false
        end

        tile = Tile(house:getExitPosition())
    else
        tile = Tile(destination.position)
    end

    if not tile then
        print(string.format("Destination %s dont have a correct position.", destName))
        player:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        return false
    end

    local playerPos = player:getPosition()
    if destination.inPz and not playerPos:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage(string.format("Destination %s require you in PZ.", destName))
        return false
    end

    if destination.level and player:getLevel() < destination.level then
        player:sendCancelMessage(string.format("Destination %s only enabled for players level %d or higher.", destName, destination.level))
        return false
    end

    if not destination.infight and player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendCancelMessage(string.format("Destination %s only work witout fight.", destName))
        return false
    end

    local destPos = tile:getPosition()
    playerPos:sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(destPos, false)
    destPos:sendMagicEffect(CONST_ME_TELEPORT)
    player:sendCancelMessage("Teleported successfully!")
    return false
end

talkAction:separator(" ")
talkAction:register()
 
some named places taken from cipfiles
Lua:
local destinations = {
    ["thais"] = {position = Position(32369,32215,7)},
    ["carlin"] = {position = Position(32341,31789,7)},
    ["ab'dendriel"] = {position = Position(32661,31687,7)},
    ["rookgaard"] = {position = Position(32097,32207,7)},
    ["fibula"] = {position = Position(32176,32437,7)},
    ["kazordoon"] = {position = Position(32632,31916,8)},
    ["senja"] = {position = Position(32125,31667,7)},
    ["folda"] = {position = Position(32046,31582,7)},
    ["vega"] = {position = Position(32027,31692,7)},
    ["havoc"] = {position = Position(32783,32243,6)},
    ["orc"] = {position = Position(32901,31771,7)},
    ["minocity"] = {position = Position(32404,32124,1)},
    ["minoroom"] = {position = Position(32139,32109,1)},
    ["desert"] = {position = Position(32653,32117,7)},
    ["swamp"] = {position = Position(32724,31976,6)},
    ["home"] = {position = Position(32316,31942,7)},
    ["mists"] = {position = Position(32854,32333,6)},
    ["fibuladungeon"] = {position = Position(32189,32426,9)},
    ["dragonisle"] = {position = Position(32781,31603,7)},
    ["hellsgate"] = {position = Position(32675,31648,1)},
    ["necropolis"] = {position = Position(32786,31683,1)},
    ["trollcaves"] = {position = Position(32493,32259,8)},
    ["elvenbane"] = {position = Position(32590,31657,7)},
    ["fieldofglory"] = {position = Position(32430,31671,7)},
    ["hills"] = {position = Position(32553,31827,6)},
    ["sternum"] = {position = Position(32463,32077,7)},
    ["northport"] = {position = Position(32486,31610,7)},
    ["greenshore"] = {position = Position(32273,32053,7)},
    ["edron"] = {position = Position(33191,31818,7)},
    ["stonehome"] = {position = Position(33319,31766,7)},
    ["camp"] = {position = Position(32655,32208,7)},
    ["cormaya"] = {position = Position(33302,31970,7)},
    ["darashia"] = {position = Position(33224,32428,7)},
    ["drefia"] = {position = Position(32996,32417,7)},
    ["venore"] = {position = Position(32955,32076,6)},
    ["ghostship"] = {position = Position(33325,32173,6)},
    ["venoredragons"] = {position = Position(32793,32155,8)},
    ["shadowthorn"] = {position = Position(33086,32157,7)},
    ["amazons"] = {position = Position(32839,31925,7)},
    ["kingsisle"] = {position = Position(32174,31940,7)},
    ["ghostlands"] = {position = Position(32223,31831,7)},
    ["ankrahmun"] = {position = Position(33162,32802,7)},
    ["oasis"] = {position = Position(33132,32661,7)},
    ["marid"] = {position = Position(33103,32539,6)},
    ["efreet"] = {position = Position(33053,32622,6)},
    ["porthope"] = {position = Position(32623,32753,7)},
    ["banuta"] = {position = Position(32812,32559,7)},
    ["chor"] = {position = Position(32956,32843,7)},
    ["trapwood"] = {position = Position(32709,32901,8)},
    ["eremo"] = {position = Position(33323,31883,7)}
}
 
How could I apply this so that it is not a command and is used with an item
 
I think it can work for TFS 1.2, do the test and if you get any error let me know
Hi :)

I am getting this error:
Lua Script Error: [Test Interface]
data/talkactions/scripts/teleportcommand.lua
data/talkactions/scripts/teleportcommand.lua:64: attempt to call global 'TalkAction' (a nil value)
stack traceback:
[C]: in function 'TalkAction'
data/talkactions/scripts/teleportcommand.lua:64: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/teleportcommand.lua
 
Hi :)

I am getting this error:
Your TFS version has no support for revscripts

Remove those lines
Lua:
local talkAction = TalkAction("!tp")
talkAction:separator(" ")
talkAction:register()

Replace this
Lua:
function talkAction.onSay(player, words, param, type)

With
Lua:
function onSay(player, words, param)

Talkactions.xml
Lua:
<talkaction words="!tp" separator=" " script="script_name.lua" />
 
What is the point of using this if you have already in luascript.cpp function:
Lua:
getWaypointPositionByName(name)
which is getting waypoint from g_game.map.waypoints which is used to read waypoints created straight in RME Map Editor?
 
Your TFS version has no support for revscripts

Remove those lines
Lua:
local talkAction = TalkAction("!tp")
talkAction:separator(" ")
talkAction:register()

Replace this
Lua:
function talkAction.onSay(player, words, param, type)

With
Lua:
function onSay(player, words, param)

Talkactions.xml
Lua:
<talkaction words="!tp" separator=" " script="script_name.lua" />
Works perfectly thank you :)
 
Hello i found one error in your script desc., if someone want add pz check in position before teleport you need use "inpz" not "inPz"

ex.
data/scripts/teleportcommand.lua
Lua:
local destinations = {
    -- please use lower case names
    --["place name"] = { position=Position(100, 100, 7), inPz=true, level=100, infight=false }

you need to use
Code:
["place name"] = { position=Position(100, 100, 7), inpz=true, level=100, infight=false }
because ex. position didn't work, and pz check didnt work too.

+ if you want change pz delay on teleport after come to pz room open config.lua

and change: ex. pzLocked = 1500

Thanks for this scripts, amazing <3
 
Last edited:
not true, renaming it to inpz will always mean its null/false, and it will never check for the pz tile flag.

It needs to be inPz, if you are getting any errors with it like this, paste them here.
 
How can u add this so only God/Gamemasters can use this command !TP? Atm it works for everyone.
 
Back
Top