SetTimer and SetTimerEx
#2

Timers have absolutely nothing to do with loops whatsoever. It all depends on what you're doing in the callback. SetTimerEx differs from SetTimer only in that it can pass additional parameters to the callback. These paremeters do not necessarily need to include a playerid, although they usually do.

If a timer is pertaining to an individual player then SetTimerEx is used and if it's a timer that potentially needs to be killed later then the id of that timer is stored in a player-array. Repeating timers are usually killed in the callback that they first called although this does not have to be the case. One example is holding a key for at least 5 seconds:
PHP Code:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_SPRINT))
    {
        
gKeyTimer[playerid] = SetTimerEx("KeyHeldAction"5000false"i"playerid);
    }
    if(
RELEASED(KEY_SPRINT))
    {
        
KillTimer(gKeyTimer[playerid]);
    }
    return 
1;
}
public 
KeyHeldAction(playerid)
{
    
SendClientMessage(playerid, -1"You held ~k~~PED_SPRINT~ for 5 seconds!");
    return 
1;

If the player first presses the key down the timer gets activated. If the player releases the key before the time is up the timer will be killed and the callback will not be called.
Reply


Messages In This Thread
SetTimer and SetTimerEx - by Penguin1997 - 14.08.2016, 20:39
Re: SetTimer and SetTimerEx - by Vince - 14.08.2016, 20:56
Re: SetTimer and SetTimerEx - by Penguin1997 - 15.08.2016, 10:50
Re: SetTimer and SetTimerEx - by Stinged - 15.08.2016, 11:46
Re: SetTimer and SetTimerEx - by Logic_ - 15.08.2016, 15:40
Re: SetTimer and SetTimerEx - by Penguin1997 - 15.08.2016, 16:18
Re: SetTimer and SetTimerEx - by Stinged - 15.08.2016, 17:26
Re: SetTimer and SetTimerEx - by Kar - 18.08.2016, 00:30
Re: SetTimer and SetTimerEx - by Mister0 - 19.08.2016, 11:28
Re: SetTimer and SetTimerEx - by WhiteGhost - 19.08.2016, 12:06

Forum Jump:


Users browsing this thread: 2 Guest(s)