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

save position

andree

New Member
Joined
Feb 19, 2014
Messages
70
Reaction score
4
hey guys. teleports me in the designated position, after a moment teleports in the former position. the question is how to save the old storage position to be able to return there?

Code:
function back(cid, var)
local playerPosition = getCreaturePosition(cid)
doCreatureSetStorage(cid, 5421, '_' .. playerPosition.x .. '_' .. playerPosition.y .. '_' .. playerPosition.z)
local playerPosFromStorage = getCreatureStorage(cid, 5421):explode('_')
doTeleportThing(cid, {x = playerPosFromStorage[1], y = playerPosFromStorage[2], z = playerPosFromStorage[3]})
end

function onCastSpell(cid, var)
local target = getCreatureTarget(cid)
local pos = {x=910, y=897, z=7}
if target == isMonster or isPlayer then
doTeleportThing(cid, pos)
doTeleportThing(target, pos)
end
addEvent(back, 1000, cid)
end
 
use:
Code:
addEvent(back, 1000, cid, pos)

You don't have to use storages.

Example (your code), you can use it. This is final code.
Code:
local function back(cid, target, oldPos, oldTos)
    if isCreature(cid) == true then
        doTeleportThing(cid, oldPos)
    end
    if isCreature(target) == true then
        doTeleportThing(target, oldTos)
    end
    return true
end

function onCastSpell(cid, var)
    local target = getCreatureTarget(cid)
    local pos = {x=910, y=897, z=7}
    local oldPos = getCreaturePosition(cid)
    local oldTos = getCreaturePosition(target)

    if isCreature(target) == true then
        doTeleportThing(cid, pos)
        doTeleportThing(target, pos)
    end
    addEvent(back, 1000, cid, target, oldPos, oldTos)
    return true
end

Pic:
Bez tytułu.png

And:
Code:
if target == isMonster or isPlayer then
is exactly the same as this:
Code:
if isCreature(target) == true then

@EDIT
If you are using addEvent(callback...) that callback function should be a local function.
Remembet to add return true before every last end in a function. Example:
Code:
function blablabla(blabla, bla)
     ...blabla
     return true
end
- that's important! If your spell haven't return true at the end ppl might be casting that spell without mana cost and without exhoust!
 
Last edited:
Back
Top