• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] player->TeleportTo with timer

Status
Not open for further replies.

callmephil

Respected Member
Anyone has an idea how to add a cooldown timer to the function
Code:
 player->TeleportTo
?


I'm pretty sure something like that is already in the core but can't find a way to apply it correctly

PS : i found this in player.cpp

Code:
//lets reset far teleport flag if it wasn't reset during chained teleports
        SetSemaphoreTeleportFar(false);
        //setup delayed teleport flag
        SetDelayedTeleportFlag(IsCanDelayTeleport());
        //if teleport spell is cast in Unit::Update() func
        //then we need to delay it until update process will be finished
        if (IsHasDelayedTeleport())
        {
            SetSemaphoreTeleportNear(true);
            //lets save teleport destination for player
            m_teleport_dest = WorldLocation(mapid, x, y, z, orientation);
            m_teleport_options = options;
            return true;
        }
 

Rochet2

Moderator / Eluna Dev
Why would one be in the core? Its all handled by spell cast times and other timers, not a coded timer.
And the delay talked about in source is a delayed teleport until the update ends, so it wont directly teleport when the function is called.
Its not a timed teleport, just postboned to be called later in the code.

To make a timed teleport, you are probably best off with using basic events:

Code:
#include "ScriptPCH.h"

class TimedTeleport : public BasicEvent
{
public:
    TimedTeleport(Player* _player, WorldLocation location, uint32 delayMS) : BasicEvent (), player(_player), loc(location), delay(delayMS)
    {
        _player->m_Events->ScheduleEvent(this, _player->m_Events->CalculateTime(delay));
    }

    bool Execute(uint64, uint32)
    {
        player->TeleportTo(loc);
        return true;
    }

    Player* player;
    WorldLocation loc;
    uint32 delay;
};

Usage:
new TimedTeleport(player, {map, x, y, z, o}, MINUTE*IN_MILLISECONDS);

Im currently installing VS so I cant use it.
I wrote the code in the reply box entirely so it doesnt probably work directly and some ingenuity is required
 

callmephil

Respected Member
thanks usefull and sorry for the delay i'm working on my repack and i'm working on alot of stuff in the same time ^^
 

Rochet2

Moderator / Eluna Dev
Btw, note that it is only safe to save the player pointer in it cause player event will only fire if the player exists.
Do not try to save a creature pointer in the timed event if you save the event for a player for example.

Find other players and creatures etc by their guid or other means.
 
Status
Not open for further replies.
Top