Global Timer
#1

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

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.
Reply
#3

Thanks and rep xD thanks alot man that really helped me
Reply
#4

One question: how to make check if timer is running(being active) using IF
Reply
#5

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;

Reply
#6

Like this ?

Code:
new timerblabla;
Code:
lmaolmao = SetTimer(); timerblabla++;
Code:
public YourTimerFunction()
{
    timerblabla--;
}
Now check if timer running

Code:
if(timerblabla)
Reply
#7

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;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)