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

Solved Teleport script add more locations

shivaria

Active Member
Joined
Sep 2, 2009
Messages
158
Reaction score
36
I have a teleport script working but its getting too difficult to add more teleport locations. I just made another teleport spot (desertisland) but havent added it due to things getting difficult to read and add. Can anyone help?

Code:
function onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
local cid = player
    local defaultport = {x=977, y=1017, z=7}
    local starrynight = {x=1056, y=998, z=7}
    local skyvale = {x=1113, y=822, z=4}
    local eravae = {x=1203, y=847, z=7}
    local gatepos = {x=977, y=1017, z=7}
    local desertisland = {x=1252, y=1062, z=4}  ---- Havent Added Below Yet -----
 
    local eravaeStorage = 6661
    local starryStorage = 6662
    local skyvaleStorage = 6663
    local desertislandStorage = 6664
 
    local function doTeleport(cid, count)


            if player:getStorageValue(eravaeStorage) == 1 then
            gatepos = {defaultport, eravae}
                ----------------------------------------------------------------
                if player:getStorageValue(starryStorage) == 1 then
                gatepos = {eravae, starrynight}
                    if player:getStorageValue(skyvaleStorage) == 1 then
                    gatepos = {eravae, starrynight, skyvale}
                    end
                ---------------------------------------------------------------- 
                elseif    player:getStorageValue(skyvaleStorage) == 1 then
                gatepos = {defaultport, eravae, skyvale} 
                    if player:getStorageValue(starryStorage) == 1 then
                    gatepos = {eravae, starrynight, skyvale}
                    end
                ---------------------------------------------------------------- 
                end 
             
            elseif player:getStorageValue(starryStorage) == 1 then
            gatepos = {starrynight}
                    ----------------------------------------------------------------
                    if player:getStorageValue(skyvaleStorage) == 1 then
                    gatepos = {defaultport, eravae, skyvale}
                        if player:getStorageValue(eravaeStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ---------------------------------------------------------------- 
                    elseif    player:getStorageValue(eravaeStorage) == 1 then
                    gatepos = {eravae, starrynight} 
                        if player:getStorageValue(skyvaleStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ---------------------------------------------------------------- 
                    end 
                 
            elseif player:getStorageValue(skyvaleStorage) == 1 then
            gatepos = {defaultport, skyvale}
                    ----------------------------------------------------------------
                    if player:getStorageValue(starryStorage) == 1 then
                    gatepos = {skyvale, starrynight}
                        if player:getStorageValue(eravaeStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ---------------------------------------------------------------- 
                    elseif    player:getStorageValue(eravaeStorage) == 1 then
                    gatepos = {defaultport, eravae, skyvale} 
                        if player:getStorageValue(starryStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ---------------------------------------------------------------- 
                    end
                 
                 
                 
                 
                 
                 
                 
                 
                    ----------------------------------------------------------------
                    else
                    gatepos = {defaultport, defaultport}
            end
             
             
 
    if not creature:isPlayer() then
        return false
    end
        doSendMagicEffect(getCreaturePosition(cid), 48)
        if (count == 1) then
            return  doTeleportThing(cid, gatepos[math.random(#gatepos)]) ,
            doSendMagicEffect(gatepos[math.random(#gatepos)], 48)
        else
            addEvent(doTeleport, 500, cid, count + 1)
        end
        return true
    end
return doTeleport(cid, 0)
end
 
Start the script all over again, but this time, make the function to take all the static* values from table.

static values* - numbers and strings you use in statements.
 
I have a teleport script working but its getting too difficult to add more teleport locations. I just made another teleport spot (desertisland) but havent added it due to things getting difficult to read and add. Can anyone help?

Code:
function onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
local cid = player
    local defaultport = {x=977, y=1017, z=7}
    local starrynight = {x=1056, y=998, z=7}
    local skyvale = {x=1113, y=822, z=4}
    local eravae = {x=1203, y=847, z=7}
    local gatepos = {x=977, y=1017, z=7}
    local desertisland = {x=1252, y=1062, z=4}  ---- Havent Added Below Yet -----

    local eravaeStorage = 6661
    local starryStorage = 6662
    local skyvaleStorage = 6663
    local desertislandStorage = 6664

    local function doTeleport(cid, count)


            if player:getStorageValue(eravaeStorage) == 1 then
            gatepos = {defaultport, eravae}
                ----------------------------------------------------------------
                if player:getStorageValue(starryStorage) == 1 then
                gatepos = {eravae, starrynight}
                    if player:getStorageValue(skyvaleStorage) == 1 then
                    gatepos = {eravae, starrynight, skyvale}
                    end
                ----------------------------------------------------------------
                elseif    player:getStorageValue(skyvaleStorage) == 1 then
                gatepos = {defaultport, eravae, skyvale}
                    if player:getStorageValue(starryStorage) == 1 then
                    gatepos = {eravae, starrynight, skyvale}
                    end
                ----------------------------------------------------------------
                end
            
            elseif player:getStorageValue(starryStorage) == 1 then
            gatepos = {starrynight}
                    ----------------------------------------------------------------
                    if player:getStorageValue(skyvaleStorage) == 1 then
                    gatepos = {defaultport, eravae, skyvale}
                        if player:getStorageValue(eravaeStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    elseif    player:getStorageValue(eravaeStorage) == 1 then
                    gatepos = {eravae, starrynight}
                        if player:getStorageValue(skyvaleStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    end
                
            elseif player:getStorageValue(skyvaleStorage) == 1 then
            gatepos = {defaultport, skyvale}
                    ----------------------------------------------------------------
                    if player:getStorageValue(starryStorage) == 1 then
                    gatepos = {skyvale, starrynight}
                        if player:getStorageValue(eravaeStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    elseif    player:getStorageValue(eravaeStorage) == 1 then
                    gatepos = {defaultport, eravae, skyvale}
                        if player:getStorageValue(starryStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    end
                
                
                
                
                
                
                
                
                    ----------------------------------------------------------------
                    else
                    gatepos = {defaultport, defaultport}
            end
            
            

    if not creature:isPlayer() then
        return false
    end
        doSendMagicEffect(getCreaturePosition(cid), 48)
        if (count == 1) then
            return  doTeleportThing(cid, gatepos[math.random(#gatepos)]) ,
            doSendMagicEffect(gatepos[math.random(#gatepos)], 48)
        else
            addEvent(doTeleport, 500, cid, count + 1)
        end
        return true
    end
return doTeleport(cid, 0)
end

This is an example from the Orts datapack of the path I believe you want to go down:
https://github.com/orts/server/blob...cripts/quests/killing in the name of/boss.lua
 
I have a teleport script working but its getting too difficult to add more teleport locations. I just made another teleport spot (desertisland) but havent added it due to things getting difficult to read and add. Can anyone help?

Code:
function onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
local cid = player
    local defaultport = {x=977, y=1017, z=7}
    local starrynight = {x=1056, y=998, z=7}
    local skyvale = {x=1113, y=822, z=4}
    local eravae = {x=1203, y=847, z=7}
    local gatepos = {x=977, y=1017, z=7}
    local desertisland = {x=1252, y=1062, z=4}  ---- Havent Added Below Yet -----

    local eravaeStorage = 6661
    local starryStorage = 6662
    local skyvaleStorage = 6663
    local desertislandStorage = 6664

    local function doTeleport(cid, count)


            if player:getStorageValue(eravaeStorage) == 1 then
            gatepos = {defaultport, eravae}
                ----------------------------------------------------------------
                if player:getStorageValue(starryStorage) == 1 then
                gatepos = {eravae, starrynight}
                    if player:getStorageValue(skyvaleStorage) == 1 then
                    gatepos = {eravae, starrynight, skyvale}
                    end
                ----------------------------------------------------------------
                elseif    player:getStorageValue(skyvaleStorage) == 1 then
                gatepos = {defaultport, eravae, skyvale}
                    if player:getStorageValue(starryStorage) == 1 then
                    gatepos = {eravae, starrynight, skyvale}
                    end
                ----------------------------------------------------------------
                end
            
            elseif player:getStorageValue(starryStorage) == 1 then
            gatepos = {starrynight}
                    ----------------------------------------------------------------
                    if player:getStorageValue(skyvaleStorage) == 1 then
                    gatepos = {defaultport, eravae, skyvale}
                        if player:getStorageValue(eravaeStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    elseif    player:getStorageValue(eravaeStorage) == 1 then
                    gatepos = {eravae, starrynight}
                        if player:getStorageValue(skyvaleStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    end
                
            elseif player:getStorageValue(skyvaleStorage) == 1 then
            gatepos = {defaultport, skyvale}
                    ----------------------------------------------------------------
                    if player:getStorageValue(starryStorage) == 1 then
                    gatepos = {skyvale, starrynight}
                        if player:getStorageValue(eravaeStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    elseif    player:getStorageValue(eravaeStorage) == 1 then
                    gatepos = {defaultport, eravae, skyvale}
                        if player:getStorageValue(starryStorage) == 1 then
                        gatepos = {eravae, starrynight, skyvale}
                        end
                    ----------------------------------------------------------------
                    end
                
                
                
                
                
                
                
                
                    ----------------------------------------------------------------
                    else
                    gatepos = {defaultport, defaultport}
            end
            
            

    if not creature:isPlayer() then
        return false
    end
        doSendMagicEffect(getCreaturePosition(cid), 48)
        if (count == 1) then
            return  doTeleportThing(cid, gatepos[math.random(#gatepos)]) ,
            doSendMagicEffect(gatepos[math.random(#gatepos)], 48)
        else
            addEvent(doTeleport, 500, cid, count + 1)
        end
        return true
    end
return doTeleport(cid, 0)
end

Well If even you don't understand it, how are we going to?
Should be easier if you detailed what the script does.
 
Try something like this:

Code:
local gates = {
    {position = Position(977, 1017, 7), storage = nil},     -- Default
    {position = Position(1203, 847, 7), storage = 6661},     -- Eravae
    {position = Position(1056, 998, 7), storage = 6662},     -- Starry Night
    {position = Position(1113, 822, 4), storage = 6663},     -- Skyvale
    {position = Position(1252, 1062, 4), storage = 6664},     -- DesertIsland
}

function onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if not player then
        creature:teleportTo(fromPosition, false)
        return true
    end

    local discoveredGates = { }
    for _, gate in ipairs(gates) do
        if not gate.storage or (player:getStorageValue(gate.storage) == 1) then
            table.insert(discoveredGates, gate.position)
        end
    end

    position:sendMagicEffect(48)   
    local destiny = discoveredGates[math.random(#discoveredGates)]
    player:teleportTo(destiny, false)
    destiny:sendMagicEffect(48)

    return true
end
 
Code:
-- use tables, for clarity and easy editing or updating
-- set the locations with these numbers as action id's
local locations = {
    [6660] = {x = 977, y = 1017, z = 7}, -- defaultport
    [6661] = {x = 1056, y = 998, z = 7}, -- starrynight
    [6662] = {x = 1113, y = 822, z = 4}, -- skyvale
    [6663] = {x = 1203, y = 847, z = 7}, -- eravae
    [6664] = {x = 977, y = 1017, z = 7}, -- gatepos
    [6665] = {x = 1252, y = 1062, z = 4} -- desertisland
}

local exhaust = 6666
local exhaustTime = 3

-- creature is the same thing as using player
function onStepIn(player, item, position, fromPosition)
    if not isPlayer(player:getId()) then
        return true
    end
  
    if player:getStorageValue(exhaust) > 0 then
        return true
    end
  
    local function isLocation()
        for aid, pos in ipairs(locations) do
            if aid == item.actionid and player:getStorageValue(aid) > 0 then
                return true, pos
            end
        end
        return false
    end

    local condition, destination = isLocation()
    if condition then
        position:sendMagicEffect(48)
        player:teleportTo(destination, false)
    else
        player:teleportTo(fromPosition, false)
    end
    return true
end

function onStepOut(player, item, position, fromPosition)
    player:setStorageValue(exhaust, exhaustTime)
    cid = player:getId()
    addEvent(
        function(cid)
            if isPlayer(cid) then
                Player(cid):setStorageValue(exhaust, 0)
            end
        end,
    exhaustTime * 1000,
    cid)
end
 
Last edited:
Well If even you don't understand it, how are we going to?
Should be easier if you detailed what the script does.
you walk in, theres a couple seconds delay, teleports you randomly to a location you unlocked. if no unlocks then default pos, if all then random between all

Try something like this:

Code:
local gates = {
    {position = Position(977, 1017, 7), storage = nil},     -- Default
    {position = Position(1203, 847, 7), storage = 6661},     -- Eravae
    {position = Position(1056, 998, 7), storage = 6662},     -- Starry Night
    {position = Position(1113, 822, 4), storage = 6663},     -- Skyvale
    {position = Position(1252, 1062, 4), storage = 6664},     -- DesertIsland
}

function onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if not player then
        creature:teleportTo(fromPosition, false)
        return true
    end

    local discoveredGates = { }
    for _, gate in ipairs(gates) do
        if not gate.storage or (player:getStorageValue(gate.storage) == 1) then
            table.insert(discoveredGates, gate.position)
        end
    end

    position:sendMagicEffect(48)  
    local destiny = discoveredGates[math.random(#discoveredGates)]
    player:teleportTo(destiny, false)
    destiny:sendMagicEffect(48)

    return true
end
worked perfectly thanks!

Code:
-- use tables, for clarity and easy editing or updating
-- set the locations with these numbers as action id's
local locations = {
    [6660] = {x = 977, y = 1017, z = 7}, -- defaultport
    [6661] = {x = 1056, y = 998, z = 7}, -- starrynight
    [6662] = {x = 1113, y = 822, z = 4}, -- skyvale
    [6663] = {x = 1203, y = 847, z = 7}, -- eravae
    [6664] = {x = 977, y = 1017, z = 7}, -- gatepos
    [6665] = {x = 1252, y = 1062, z = 4} -- desertisland
}

local exhaust = 6666
local exhaustTime = 3

-- creature is the same thing as using player
function onStepIn(player, item, position, fromPosition)
    if not isPlayer(player:getId()) then
        return true
    end
 
    if player:getStorageValue(exhaust) > 0 then
        return true
    end
 
    local function isLocation()
        for aid, pos in ipairs(locations) do
            if aid == item.actionid and player:getStorageValue(aid) > 0 then
                return true, pos
            end
        end
        return false
    end

    local condition, destination = isLocation()
    if condition then
        position:sendMagicEffect(48)
        player:teleportTo(destination, false)
    else
        player:teleportTo(fromPosition, false)
    end
    return true
end

function onStepOut(player, item, position, fromPosition)
    player:setStorageValue(exhaust, exhaustTime)
    cid = player:getId()
    addEvent(
        function(cid)
            if isPlayer(cid) then
                Player(cid):setStorageValue(exhaust, 0)
            end
        end,
    exhaustTime * 1000,
    cid)
end
thanks, u guys are awesome!
 
Last edited by a moderator:
Back
Top