View Full Version : [SOLVED] player->TeleportTo with timer

08-31-2014, 03:12 PM
Anyone has an idea how to add a cooldown timer to the function
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

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

08-31-2014, 05:58 PM
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:

#include "ScriptPCH.h"

class TimedTeleport : public BasicEvent
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)
return true;

Player* player;
WorldLocation loc;
uint32 delay;

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

09-05-2014, 11:05 PM
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 ^^

09-06-2014, 10:38 AM
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.