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

Lua talkaction teleport player to temple (comand to gm)

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
931
Solutions
7
Reaction score
127
Location
Brazil
YouTube
caruniawikibr
Does anyone have a talkaction where I put it for example /teleport "player" so it is sent to your temple? tfs 1.5
 
Solution
Lua:
local talkaction = TalkAction("/t")

local effect = CONST_ME_TELEPORT

function talkaction.onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if param == '' then
        player:teleportTo(player:getTown():getTemplePosition())
        player:getPosition():sendMagicEffect(effect)
    end
    local target = Player(param)
    if not target then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end
    target:teleportTo(player:getTown():getTemplePosition())
    target:getPosition():sendMagicEffect(effect)
    target:sendTextMessage(MESSAGE_INFO_DESCR, 'You have been teleported from ['..player:getName()..'] to temple.')...
Lua:
local talkaction = TalkAction("/t")

local effect = CONST_ME_TELEPORT

function talkaction.onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if param == '' then
        player:teleportTo(player:getTown():getTemplePosition())
        player:getPosition():sendMagicEffect(effect)
    end
    local target = Player(param)
    if not target then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end
    target:teleportTo(player:getTown():getTemplePosition())
    target:getPosition():sendMagicEffect(effect)
    target:sendTextMessage(MESSAGE_INFO_DESCR, 'You have been teleported from ['..player:getName()..'] to temple.')
    return false
end

talkaction:separator(" ")
talkaction:register()

You can use this as default /t so if you write /t you get teleported and if you write /t name then player gets teleported
 
Last edited:
Solution
ty friend :)
Post automatically merged:

Taking advantage of the momentum, here is a /tp all to send all online players to their home temple.

Lua:
local teleportAllAction = TalkAction("/tp all")
local effect = CONST_ME_TELEPORT

function teleportAllAction.onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    for _, onlinePlayer in ipairs(Game.getPlayers()) do
        local templePosition = onlinePlayer:getTown():getTemplePosition()
        onlinePlayer:teleportTo(templePosition)
        onlinePlayer:getPosition():sendMagicEffect(effect)
        onlinePlayer:sendTextMessage(MESSAGE_STATUS_WARNING, "You have been teleported to your temple by " .. player:getName() .. ".")
    end

    return false
end

teleportAllAction:register()


and here in your code, the player was sent to the adm's temple, now he goes to his temple.

Lua:
local talkaction = TalkAction("/t")
local effect = CONST_ME_TELEPORT

function talkaction.onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    
    if param == '' then
        player:sendCancelMessage("Usage: /t <player name>")
        return false
    end

    local target = Player(param)
    if not target then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end

    local townId = target:getTown():getId()
    local templePosition = Town(townId):getTemplePosition()

    target:teleportTo(templePosition)
    target:getPosition():sendMagicEffect(effect)
    target:sendTextMessage(MESSAGE_STATUS_WARNING, "You have been teleported from " .. player:getName() .. " to your temple.")

    return false
end

talkaction:separator(" ")
talkaction:register()
 
Last edited:
Back
Top