SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/05/2020, 01:24 PM   #1
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default 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
Calinut200 is offline   Reply With Quote
Old 28/05/2020, 01:52 PM   #2
hopeonxanny
Huge Clucker
 
hopeonxanny's Avatar
 
Join Date: Apr 2020
Location: SA-MP Awesomeness: 1998
Posts: 238
Reputation: 4
Default Re: How to activate a timer

You mean server variable or player variable?
__________________
hopeonxanny is offline   Reply With Quote
Old 28/05/2020, 02:00 PM   #3
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,089
Reputation: 126
Default 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
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!


Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Discord - Website
jasperschellekens is online now   Reply With Quote
Old 28/05/2020, 02:23 PM   #4
SharpenBlade
Huge Clucker
 
Join Date: May 2020
Posts: 201
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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activate Windows 7 32 Bit Bruno Pereira Everything and Nothing 1 23/10/2011 06:40 PM
Can some1 activate me [P].atriick General 3 14/11/2010 07:08 PM
Activate Function Using A Key MummyKillerSLO Help Archive 1 22/05/2010 09:36 AM
[SOLVED]activate npc using cmd troy52192 Help Archive 1 06/11/2009 11:30 AM
Activate NOS DragoNuno Help Archive 7 02/10/2009 08:48 PM


All times are GMT. The time now is 05:32 PM.


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