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

Action [TFS 1.2] Teleport Scroll

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,643
Solutions
559
Reaction score
3,949
Description
Teleports player to default town position, creates a teleport near the player (that only the player can see).
The player has 30 seconds to enter the teleport to get back to their previous position.​

S0LeodT.png
Y3hJ96I.png

If you don't understand from the screenshots, here is a video

actions.xml

XML:
<action itemid="1953" script="tp scroll.lua"/>

actions/scripts/tp scroll.lua
Lua:
savePos = {}

local function sendEffects(pos, eff, pid)
    if savePos[pid] then
        local player = Player(pid)
        if isPlayer(player) then
            pos:sendMagicEffect(eff, player)
            addEvent(sendEffects, 400, pos, eff, pid)
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pid   = player:getId()
    if not player:isPzLocked() then
        if not savePos[pid] then
            savePos[pid] = {player:getPosition()}
            player:teleportTo(player:getTown():getTemplePosition())
            local pos = player:getPosition()
            local randpos = Position(pos.x+math.random(3), pos.y+math.random(2), pos.z)
            savePos[pid] = {savePos[pid][1], randpos}
            local cache  = savePos[pid]
            sendEffects(cache[2], 12, pid)
            sendEffects(cache[1], 35, pid)
            local item = Item(Tile(randpos):getGround().uid)
            item:setActionId(3006)
            addEvent(function()
                        if item:getActionId(3006) then
                            item:removeAttribute('aid')
                            savePos[pid] = nil
                        end
                    end, 30000)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    end
    return true
end


movements.xml
XML:
<movevent event="StepIn" actionid="3006" script="tpscroll.lua"/>

movements/scripts/tpscroll.lua
Lua:
function onStepIn(creature, item, position, fromPosition)
    local pid = creature:getId()
    local pos = savePos[pid]
    if pos and pos[2] then
        creature:teleportTo(pos[1])
        pos[2]:sendMagicEffect(CONST_ME_STUN)
        pos[1]:sendMagicEffect(CONST_ME_STUN)
        item:removeAttribute('aid')
        savePos[pid] = nil
    end
    return true
end


creaturescripts.xml
XML:
<event type="logout" name="Script Logut" script="Script Logout.lua"/>

creaturescripts/scripts/Script Logout.lua
Lua:
function onLogout(player)
local pid = player:getId()
    if savePos[pid] then
        Item(Tile(savePos[pid][2]):getGround().uid):removeAttribute('aid')
        savePos[pid] = nil
    end
    return true
end
 
Last edited by a moderator:
So i tried this a few days ago on TFS 1.2 and it wont load the server, i added everything 100% has anyone else tested this yet?
 
So i tried this a few days ago on TFS 1.2 and it wont load the server, i added everything 100% has anyone else tested this yet?
might have been because I didn't define pid in the logout for whatever reason, updated
let me know if it still doesn't work.
 
Wouldn't there be a problem if multiple people used the portal at the same time? It would create multiple portals on the same spot.
 
Wouldn't there be a problem if multiple people used the portal at the same time? It would create multiple portals on the same spot.
no, it saves position to savePos with cid and checks if the table exists in the movement for the cid, then uses it

edit: misunderstood your question, it randomly generates position each time it's used so its not always the exact same position for every player
 
Randomly seems like there is still a possibility of that problem coming up. Unless you are only planning on capping around 100 players. It would be better if you had specific positions set up that can be use and the script will check to see if they are being used already or not.

In addition, I would add text on top of the teleport that states the teleport owners name.

Lastly, I would take out the return magic effect. Meaning (where the player will go back too should not have a magic effect going).

Here is one example of why it might be bad to do it this way:
Lets say a player is hunting a spawn and I notices traces of another player hunting there. He didn't have any supplies with him for a fight so he uses the teleport
and goes and supplies up really fast. Then when he comes back there are 10 players waiting at his save spot and inta-kill him as he comes back through.

Idk how your server is set up but these are my thoughts.

(anyone)
If you are having problem figuring out how to make the script I can help you. (for 1.2)
 
Randomly seems like there is still a possibility of that problem coming up. Unless you are only planning on capping around 100 players. It would be better if you had specific positions set up that can be use and the script will check to see if they are being used already or not.

In addition, I would add text on top of the teleport that states the teleport owners name.

Lastly, I would take out the return magic effect. Meaning (where the player will go back too should not have a magic effect going).

Here is one example of why it might be bad to do it this way:
Lets say a player is hunting a spawn and I notices traces of another player hunting there. He didn't have any supplies with him for a fight so he uses the teleport
and goes and supplies up really fast. Then when he comes back there are 10 players waiting at his save spot and inta-kill him as he comes back through.

Idk how your server is set up but these are my thoughts.

(anyone)
If you are having problem figuring out how to make the script I can help you. (for 1.2)
no one but the player that clicked the scroll may see the teleport, since it's an effect, I used the second arg to send effects to only that player
 
Okay after actually reading the code I see only 1 problem. Though it probably would never come up.

If two players used the TP scroll and it randomly gave them both the same tile to return back to their previous location. Once one of the players used that tile the other one wouldn't be able to return back to his position because the AID would be removed.
 
Okay after actually reading the code I see only 1 problem. Though it probably would never come up.

If two players used the TP scroll and it randomly gave them both the same tile to return back to their previous location. Once one of the players used that tile the other one wouldn't be able to return back to his position because the AID would be removed.
yeah, but it's unlikely to happen
ill look into fixing it when I can test everything.
 
Script installed flawlessly, worked perfectly... and I appreciate the work that went into it.

Didnt wanna hit and run,

Thanks again
 
if not player:isPzLocked() then how can I change it to, if player is on battle?

All players when someone going pk use it and going temple without die.
 
Hello,

Im trying to add something like that;

Code:
if not player:isPzLocked() and player:getCondition(CONDITION_INFIGHT) then

Cuz when you are in fighting by monsters for exemple you can teleport...

some help ?
 
use this
Lua:
if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
    player:sendCancelMessage('You cannot use this while in a fight.')
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end
 
use this
Lua:
if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
    player:sendCancelMessage('You cannot use this while in a fight.')
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end


Ty love you!
 
use this
Lua:
if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
    player:sendCancelMessage('You cannot use this while in a fight.')
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end
in which file to add it?
 
The line they are referencing is actions/scripts/tp scroll.lua line 15
you mean replace the "if" in line 15 to what they wrote here?
because i tried to put it in every place in the file and in a fight it still work..
can you please rewrite it for me with this new code part?
 
you mean replace the "if" in line 15 to what they wrote here?
because i tried to put it in every place in the file and in a fight it still work..
can you please rewrite it for me with this new code part?
Lua:
savePos = {}

local function sendEffects(pos, eff, pid)
    if savePos[pid] then
        local player = Player(pid)
        if isPlayer(player) then
            pos:sendMagicEffect(eff, player)
            addEvent(sendEffects, 400, pos, eff, pid)
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendCancelMessage('You cannot use this while in a fight.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end
    local pid = player:getId()
    if not savePos[pid] then
        savePos[pid] = {player:getPosition()}
        player:teleportTo(player:getTown():getTemplePosition())
        local pos = player:getPosition()
        local randpos = Position(pos.x+math.random(3), pos.y+math.random(2), pos.z)
        savePos[pid] = {savePos[pid][1], randpos}
        local cache  = savePos[pid]
        sendEffects(cache[2], 12, pid)
        sendEffects(cache[1], 35, pid)
        local item = Item(Tile(randpos):getGround().uid)
        item:setActionId(3006)
        addEvent(function()
            if item:getActionId(3006) then
                item:removeAttribute('aid')
                savePos[pid] = nil
            end
        end, 30000)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
    end
    return true
end
 
Back
Top