SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   How to activate a timer (https://forum.sa-mp.com/showthread.php?t=676044)

Calinut200 28/05/2020 01:24 PM

How to activate a timer
 
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

hopeonxanny 28/05/2020 01:52 PM

Re: How to activate a timer
 
You mean server variable or player variable?

jasperschellekens 28/05/2020 02:00 PM

Re: How to activate a timer
 
pawn Code:
if(test[playerid] == 1) // Run the timer here, e.g SetTimer and the timer is only activated when player var is 1

SharpenBlade 28/05/2020 02:23 PM

Re: How to activate a timer
 
Quote:

Originally Posted by Calinut200 (Post 4148421)
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;




All times are GMT. The time now is 02:57 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.