19.12.2016, 17:15
Quote:
What is the correct way of checking that a timer is active?
After doing Код:
Player[playerid][LoginTimer] = defer OnLoginTimeout(playerid); Код:
if (Player[playerid][LoginTimer]) { // Timer active } else { // Timer not active } Код:
stop Player[playerid][LoginTimer]; // is this enough? Player[playerid][LoginTimer] = 0; // or do I also have to do this? |
PHP код:
/* Set all cells to -1 */
new Timer:myTimer[MAX_PLAYERS] = {Timer:-1, ...};
/* Start the timer */
CMD:mycommand(playerid, params[])
{
myTimer[playerid] = repeat MyOwnFunction(playerid);
/* MyOwnFunction will be called 1 second after we type the
command, due the delay parameter from timer, that's how it works. */
return 1;
}
/* Declare MyOwnFunction as a timer */
timer MyOwnFunction[1000](playerid)
{
printf("The player who started timer %d has the ID %d.", _:myTimer[playerid], playerid);
// This function will print the same message every second.
}
/* Stop the timer */
COMMAND:stoptimer(playerid, params[])
{
if(myTimer[playerid] != Timer:-1)
{
stop myTimer[playerid];
myTimer[playerid] = Timer:-1;
}
else
{
// The timer isn't running.
}
return 1;
}