How to activate a timer
#1

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
Reply
#2

You mean server variable or player variable?
Reply
#3

pawn Code:
if(test[playerid] == 1) // Run the timer here, e.g SetTimer and the timer is only activated when player var is 1
Reply
#4

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;

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)