Global Timer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Global Timer (
/showthread.php?tid=630822)
Global Timer -
ElMaestro123 - 18.03.2017
How to make global timer for every player so when someone performs a certain command,a timer will be created and the others wont be abled to perform it while the timer doesnt end?
And how to kill timer after certain period?
I'm willing to give rep to someone that can explain it to me. I'm new to pawn.
Re: Global Timer -
Toroi - 18.03.2017
A timer is a timer. The timer is your 'certain period'.
Create a global variable somewhere on the top of your gamemode, under your includes.
https://sampwiki.blast.hk/wiki/Scripting_Basics#Declaration
Create a function to handle your timer, in this case you can make a short function to set the value of your new variable to zero.
https://sampwiki.blast.hk/wiki/Scripting_Basics#Functions
Now, everytime a player issues your command, check with conditional statements if the value of your variable is 1, if it is, return an error message of your likes. If the value of the variable is zero, change it to 1 and run your function with the use of
SetTimer and set whatever time you want.
https://sampwiki.blast.hk/wiki/SetTimer
Also, omg rep! I couldn't be more pleased to help you. In fact i wouldnt if you wouldnt give reputation, its the most important thing in this world.
A simple 'thanks' is better than that tho.
Re: Global Timer -
ElMaestro123 - 19.03.2017
Thanks and rep xD thanks alot man that really helped me
Re: Global Timer -
ElMaestro123 - 19.03.2017
One question: how to make check if timer is running(being active) using IF
Re: Global Timer -
Toroi - 19.03.2017
There's no direct way to do that, however you can make a boolean variable and set it to true everytime you start the timer, inside the timer function set it to false.
Functions that you call with timers get called once the time ends, as an example:
PHP Code:
new bool:IsTimerRunnin;
forward taimer();
public taimer()
{
IsTimerRunnin = false; // set the boolean value to false, indicating that the timer just stopped and the function was executed
// rest of your functions
}
// This is only an example, i'm using zcmd
CMD:timerstaruto(playerid)
{
if(IsTimerRunnin == true) return SendClientMessage(playerid,color,"The timer is already runnin!"); // if the timer is running, stop the function here and return a message
IsTimerRunnin = true; // set the boolean of the timer to true, indicating that the timer is running
SetTimer("taimer",3000,false); // The function inside the taimer callback will get executed after 3 seconds
return 1;
}
Re: Global Timer -
Bolex_ - 19.03.2017
Like this ?
Code:
lmaolmao = SetTimer(); timerblabla++;
Code:
public YourTimerFunction()
{
timerblabla--;
}
Now check if timer running
Re: Global Timer -
Logic_ - 19.03.2017
Use gettime instead, it's optimized than using timer.
PHP Code:
new time;
CMD:command(playerid)
{
if(gettime() <= time) return //
time = gettime() + /* seconds after you want the command to be accessible */
return 1;
}