• 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 how make teleport change position?

Solution
Lua:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {
    {x = 1091, y = 1150, z = 7},
    {x = 1192, y = 1150, z = 7}
}

local i = 1
function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end

    local nextPosition = validPositions[i]
    doRemoveItem(oldTeleport.uid)
    doCreateTeleport(1387, nextPosition, tpPosition)
    i = i % #validPositions + 1
end
You can use a globalevent and use a table with positions and an initial position then you just use getTileItemByType(pos, ITEM_TYPE_TELEPORT) remove that old tp and create a new one in a new random position using doCreateTeleport(itemid, toPosition, fromPosition)
 
Last edited:
You can use a globalevent and use a table with positions and an initial position then you just use getTileItemByType(pos, ITEM_TYPE_TELEPORT) remove that old tp and create a new one in a new random position using doCreateTeleport(itemid, toPosition, fromPosition)
help me what i must write at script.
globalevent:
Code:
<globalevent name="teleporttime" interval="600000" event="script" value="teleporttime.lua"/>
teleporttime.lua:
 
help me what i must write at script.
globalevent:
Code:
<globalevent name="teleporttime" interval="600000" event="script" value="teleporttime.lua"/>
teleporttime.lua:
Lua:
local currentPosition = {x = 100, y = 100, z = 7}
local validPositions = {currentPosition, {x = 200, y = 200, z = 7}}
local destination = {x = 300, y = 300, z = 7}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(currentPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid ~= 0 then
        doRemoveItem(oldTeleport.uid)
    end

    local randomPosition = validPositions[math.random(#validPositions)]
    doCreateTeleport(1387, destination, randomPosition)
    currentPosition = randomPosition
end
 
Lua:
local currentPosition = {x = 100, y = 100, z = 7}
local validPositions = {currentPosition, {x = 200, y = 200, z = 7}}
local destination = {x = 300, y = 300, z = 7}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(currentPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid ~= 0 then
        doRemoveItem(oldTeleport.uid)
    end

    local randomPosition = validPositions[math.random(#validPositions)]
    doCreateTeleport(1387, destination, randomPosition)
    currentPosition = randomPosition
end
sorry i was make wrong description. Not teleport position. destination position changing every 10 min. Can you help with this?
 
sorry i was make wrong description. Not teleport position. destination position changing every 10 min. Can you help with this?
Lua:
local tpPosition = {x = 100, y = 100, z = 7}
local validPositions = {{x = 200, y = 200, z = 7}, {x = 300, y = 300, z = 7}}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end
 
    doRemoveItem(oldTeleport.uid)
    local randomPosition = validPositions[math.random(#validPositions)]
    doCreateTeleport(1387, randomPosition, tpPosition)
end
 
Lua:
local tpPosition = {x = 100, y = 100, z = 7}
local validPositions = {{x = 200, y = 200, z = 7}, {x = 300, y = 300, z = 7}}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end
 
    doRemoveItem(oldTeleport.uid)
    local randomPosition = validPositions[math.random(#validPositions)]
    doCreateTeleport(1387, randomPosition, tpPosition)
end
07/02/2017 20:33:49] [Error - LuaScriptInterface::loadFile] ...ryingdamson 0.3.6 (8.60) V8.2/data/globalevents/scripts/teleporttime.lua:2: '}' expected near 'z'
[07/02/2017 20:33:49] [Warning - Event::loadScript] Cannot load script (D:/Game/tibia own server/new 8.6/cryingdamson 0.3.6 (8.60) V8.2/data/globalevents/scripts/teleporttime.lua)
[07/02/2017 20:33:49] ...ryingdamson 0.3.6 (8.60) V8.2/data/globalevents/scripts/teleporttime.lua:2: '}' expected near 'z'


have error. not work. Maybe someting wrong?
 
07/02/2017 20:33:49] [Error - LuaScriptInterface::loadFile] ...ryingdamson 0.3.6 (8.60) V8.2/data/globalevents/scripts/teleporttime.lua:2: '}' expected near 'z'
[07/02/2017 20:33:49] [Warning - Event::loadScript] Cannot load script (D:/Game/tibia own server/new 8.6/cryingdamson 0.3.6 (8.60) V8.2/data/globalevents/scripts/teleporttime.lua)
[07/02/2017 20:33:49] ...ryingdamson 0.3.6 (8.60) V8.2/data/globalevents/scripts/teleporttime.lua:2: '}' expected near 'z'


have error. not work. Maybe someting wrong?
You made it wrong when modifing the script, I can't help you if you don't post your modified version.
 
You made it wrong when modifing the script, I can't help you if you don't post your modified version.
globalevents:
Code:
<globalevent name="teleporttime" interval="600000" event="script" value="teleporttime.lua"/>
scripts:
Code:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {{x = 1091, y = 1150, z = 7}, {x = 1192, y = 1150, z = 7}}
function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end
    doRemoveItem(oldTeleport.uid)
    local randomPosition = validPositions[math.random(#validPositions)]
    doCreateTeleport(1387, randomPosition, tpPosition)
end

i modifing script.
 
globalevents:
Code:
<globalevent name="teleporttime" interval="600000" event="script" value="teleporttime.lua"/>
scripts:
Code:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {{x = 1091, y = 1150, z = 7}, {x = 1192, y = 1150, z = 7}}
function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end
    doRemoveItem(oldTeleport.uid)
    local randomPosition = validPositions[math.random(#validPositions)]
    doCreateTeleport(1387, randomPosition, tpPosition)
end

i modifing script.

Tested the script online and there was no errors, try replacing it again and see if it works, I can't find any issues with it.

Lua:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {
    {x = 1091, y = 1150, z = 7},
    {x = 1192, y = 1150, z = 7}
}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end

    local randomPosition = validPositions[math.random(#validPositions)]
    doRemoveItem(oldTeleport.uid)
    doCreateTeleport(1387, randomPosition, tpPosition)
end

Cleaned the table atleast xD
 
Tested the script online and there was no errors, try replacing it again and see if it works, I can't find any issues with it.

Lua:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {
    {x = 1091, y = 1150, z = 7},
    {x = 1192, y = 1150, z = 7}
}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end

    local randomPosition = validPositions[math.random(#validPositions)]
    doRemoveItem(oldTeleport.uid)
    doCreateTeleport(1387, randomPosition, tpPosition)
end

Cleaned the table atleast xD
all work good. But i no need random position i need change position first then second and then third fourth fifth and sixth. After six will start first again.
 
try this
Lua:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {
    {x = 1091, y = 1150, z = 7},
    {x = 1192, y = 1150, z = 7}
}

nextPosition = 1 -- table index

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end

    doRemoveItem(oldTeleport.uid)
    doCreateTeleport(1387, validPositions[nextPosition], tpPosition)
    nextPosition = (validPositions[nextPosition + 1] and nextPosition + 1) or 1
    return true
end
 
all work good. But i no need random position i need change position first then second and then third fourth fifth and sixth. After six will start first again.

Lua:
local tpPosition = {x = 1090, y = 1150, z = 7}
local teleportPositions = {
    [1] = {x = 1091, y = 1150, z = 7},
    [2] = {x = 1192, y = 1150, z = 7}
}

function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end

    local storageValue = getGlobalStorageValue(13425)
    local nextValue = storageValue
    if nextValue == -1 then
        nextValue = 1
    else
        nextValue = storageValue == #teleportPositions and 1 or storageValue + 1
    end

    setGlobalStorageValue(13425, nextValue)
    doRemoveItem(oldTeleport.uid)

    doCreateTeleport(1387, teleportPositions[nextValue], tpPosition)
end

That should work, you can add as many tps as you wish.
 
Lua:
local tpPosition = {x = 1090, y = 1150, z = 7}
local validPositions = {
    {x = 1091, y = 1150, z = 7},
    {x = 1192, y = 1150, z = 7}
}

local i = 1
function onThink(interval, lastExecution, thinkInterval)
    local oldTeleport = getTileItemByType(tpPosition, ITEM_TYPE_TELEPORT)
    if oldTeleport.uid == 0 then
        return
    end

    local nextPosition = validPositions[i]
    doRemoveItem(oldTeleport.uid)
    doCreateTeleport(1387, nextPosition, tpPosition)
    i = i % #validPositions + 1
end
 
Solution
Back
Top