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

TFS 1.X+ tfs 1.2, how can i save player pos?

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
Hello, I use tfs 1.2 and I'm creating a magic.
When using the spell, the position of the player should be saved. When using the spell again, it must be teleported to this saved position.
 
Hello, I use tfs 1.2 and I'm creating a magic.
When using the spell, the position of the player should be saved. When using the spell again, it must be teleported to this saved position.
Made it with 1.3 but it should work.
LUA:
local combat = Combat()
local storage = {}

function onCastSpell(creature, variant)
    local player = creature:getPlayer()
    if not player then
        return false
    end

    if combat:execute(creaure, variant) then
        local guid = player:getGuid()
        if storage[guid] then
            player:teleportTo(storage[guid])
            storage[guid]:sendMagicEffect(CONST_ME_TELEPORT)
            storage[guid] = nil
        else
            storage[guid] = player:getPosition()
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Teleport position set.")
        end
        return true
    end
    return false
end
 
@Apollos how can i add "You must use it within 5 sec"?
If the person not use it within 5 second he can't get tpd to the pos.
LUA:
local combat = Combat()
local storage = {}

function onCastSpell(creature, variant)
    local player = creature:getPlayer()
    if not player then
        return false
    end

    if combat:execute(creaure, variant) then
        local guid = player:getGuid()
        if storage[guid] then
            player:teleportTo(storage[guid].pos)
            storage[guid].pos:sendMagicEffect(CONST_ME_TELEPORT)
            stopEvent(storage[guid].event)
            storage[guid] = nil
        else
            storage[guid] = {
                pos = player:getPosition(),
                event = addEvent(function()
                    storage[guid] = nil
                end, 5 * 1000)
            }
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Teleport position set. You must use again within 5 seconds.")
        end
        return true
    end
    return false
end
 
Back
Top