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

Teleport

kite28

Member
Joined
May 15, 2012
Messages
71
Reaction score
6
Hello, I need a script that should work, namely we have 2 cities and one destination, i.e

Home
Home1
T.C

If we enter the teleport in Home and go to TC, we return to Home, not Home1, and the same with home2, if we enter Home2 in the teleport and go to TC, we return to Home2.

TFS 1.2
 
XML:
<!-- StepIn for multiple action IDs leading to the PVP arena -->
<movevent event="StepIn" actionid="7400" script="arenaPVP.lua" />
<movevent event="StepIn" actionid="7401" script="arenaPVP.lua" />

<!-- StepIn for returning to the saved position -->
<movevent event="StepIn" actionid="7402" script="backsavedposition.lua" />

arenaPVP.lua
LUA:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local playerPosition = player:getPosition()

    player:setStorageValue(50001, playerPosition.x)  -- Save X position
    player:setStorageValue(50002, playerPosition.y)  -- Save Y position
    player:setStorageValue(50003, playerPosition.z)  -- Save Z position

    -- Teleport the player to the PVP area
    local pvpPosition = Position(158, 122, 7) -- Coordinates of the PVP area
    player:teleportTo(pvpPosition)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)

    player:sendTextMessage(MESSAGE_INFO_DESCR, "Welcome to the PVP area. Fight with honor!")

    return true
end

backsavedposition.lua
LUA:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local x = player:getStorageValue(50001)
    local y = player:getStorageValue(50002)
    local z = player:getStorageValue(50003)

    if x == -1 or y == -1 or z == -1 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Error: No original position found.")
        return true
    end

    y = y + 1

    local originalPosition = Position(x, y, z)

    player:teleportTo(originalPosition)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)

    return true
end

1726406388275.webp
 
XML:
<!-- StepIn for multiple action IDs leading to the PVP arena -->
<movevent event="StepIn" actionid="7400" script="arenaPVP.lua" />
<movevent event="StepIn" actionid="7401" script="arenaPVP.lua" />

<!-- StepIn for returning to the saved position -->
<movevent event="StepIn" actionid="7402" script="backsavedposition.lua" />

arenaPVP.lua
LUA:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local playerPosition = player:getPosition()

    player:setStorageValue(50001, playerPosition.x)  -- Save X position
    player:setStorageValue(50002, playerPosition.y)  -- Save Y position
    player:setStorageValue(50003, playerPosition.z)  -- Save Z position

    -- Teleport the player to the PVP area
    local pvpPosition = Position(158, 122, 7) -- Coordinates of the PVP area
    player:teleportTo(pvpPosition)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)

    player:sendTextMessage(MESSAGE_INFO_DESCR, "Welcome to the PVP area. Fight with honor!")

    return true
end

backsavedposition.lua
LUA:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local x = player:getStorageValue(50001)
    local y = player:getStorageValue(50002)
    local z = player:getStorageValue(50003)

    if x == -1 or y == -1 or z == -1 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Error: No original position found.")
        return true
    end

    y = y + 1

    local originalPosition = Position(x, y, z)

    player:teleportTo(originalPosition)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)

    return true
end

View attachment 87102
Thanks for help <3
 
Back
Top