View Single Post
Old 28/05/2020, 02:23 PM   #4
SharpenBlade
Huge Clucker
 
Join Date: May 2020
Posts: 202
Reputation: 25
Default Re: How to activate a timer

Quote:
Originally Posted by Calinut200 View Post
How to activate a timer like that only if a variable is 1;
PHP Code:
ptask name[1000](playerid
{
    
// my code

This is the timer from YNI includes, i wanna work only work if a variable test[playerid] = 1;
how to make that? I don't wanna to work in background each second and do nothing
You could create a player timer then.
PHP Code:
new Timer:mytimer[MAX_PLAYERS] = {Timer:-1, ...}; 
In your function, where you set that variable to 1 you should set the timer also.
PHP Code:
if(MyVariable[playerid] == 1)
    
mytimer[playerid] = repeat MyFunction(playerid); 
OnPlayerDisconnect, or when you put that variable on 0:
PHP Code:
if(mytimer[playerid] != Timer:-1)
{
    
stop mytimer[playerid];
    
mytimer[playerid] = Timer:-1;

SharpenBlade is offline   Reply With Quote