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

Simple teleport script

Mimicando

New Member
Joined
Mar 20, 2022
Messages
3
Reaction score
1
Hello, I need to create a very simple teleport when using this mechanism it should take me in a marked square, I have tried to do it by myself many times, but it doesn't work.

useful information:
  • mechanism id - 8616
  • action id - 60000
  • target position - x = 423, y = 198, z = 5

I have script like this:
Lua:
local gatemechanism = {
[60000] = {pos = {x = 423, y = 198, z = 5}}
}

local gatemechanism = Action()
function gatemechanism.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if(gatemechanism[item.uid]) then
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:teleportTo(gatemechanism[item.uid].pos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    end
    return true
end

gatemechanism:id(8616)
gatemechanism:register()
 
Solution
On line 5 you are over-writing your table by using the same local variable gatemechanism.
In your table you are using the deprecated position system.

I'd also suggest not binding an entire itemId to a single script unless you absolutely need to.

Put the actionId 60000 on the Gate Mechanism in the map editor
and try this script.
Lua:
local gateMechanism = {
  --[actionId] = {pos = Position(1000, 1000, 7)}
    [60000] = {pos = Position(423, 198, 5)}
}

local Action_GateMechanism = Action()

function Action_GateMechanism.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(gateMechanism[item:getActionId()].pos)...
On line 5 you are over-writing your table by using the same local variable gatemechanism.
In your table you are using the deprecated position system.

I'd also suggest not binding an entire itemId to a single script unless you absolutely need to.

Put the actionId 60000 on the Gate Mechanism in the map editor
and try this script.
Lua:
local gateMechanism = {
  --[actionId] = {pos = Position(1000, 1000, 7)}
    [60000] = {pos = Position(423, 198, 5)}
}

local Action_GateMechanism = Action()

function Action_GateMechanism.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(gateMechanism[item:getActionId()].pos)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end

for v, k in pairs(gateMechanism) do
    Action_GateMechanism:aid(v)
end
Action_GateMechanism:register()
 
Solution
On line 5 you are over-writing your table by using the same local variable gatemechanism.
In your table you are using the deprecated position system.

I'd also suggest not binding an entire itemId to a single script unless you absolutely need to.

Put the actionId 60000 on the Gate Mechanism in the map editor
and try this script.
Lua:
local gateMechanism = {
  --[actionId] = {pos = Position(1000, 1000, 7)}
    [60000] = {pos = Position(423, 198, 5)}
}

local Action_GateMechanism = Action()

function Action_GateMechanism.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(gateMechanism[item:getActionId()].pos)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end

for v, k in pairs(gateMechanism) do
    Action_GateMechanism:aid(v)
end
Action_GateMechanism:register()
hello good and is it possible to do this as a stone? That is to say, a rune that when used on yourself sends you to the temple but it is spent I am trying but I don't know what are the functions to send a player to the temple without asking for coordinates I tried to search in the sources but I really don't know what I have to look for
 
hello good and is it possible to do this as a stone? That is to say, a rune that when used on yourself sends you to the temple but it is spent I am trying but I don't know what are the functions to send a player to the temple without asking for coordinates I tried to search in the sources but I really don't know what I have to look for

Lua:
player:teleportTo(player:getTown():getTemplePosition())

If is an action with "Use with" to target others players(like runes), try using target instead of player
 
Back
Top