20.05.2012, 04:10
Introduction:
I have decided to start making tutorials on this forum and thought it would be best to start with something simple, yet useful to anybody.
Today i am going to show you how to make command timers with "tickcount()" using two simple steps, eliminating the need for actual timers.
(Please forgive me if this tutorial is already covered, i did not find any during my search.)
Step 1 - Creating the timer data variable/s:
I am going to show you how to do this using an enum so it will be alot easier for you to add more command timers in future, and it will be alot better then making an individual player variable for each command.
Step 2 - Creating the timer/s for your command/s:
Now basically, all we have to do is set the player variable for the command to the tickcount() after the command is used, then when the command is used again, check if the tickcount() minus w/e time we restrict is less then the player variable(tickcount()), if so they have used the command within the restricted time frame and we simply tell them "Please wait before using this command again.", simple or what?
And it is as simple as that, i hope this tutorial helps you understand there is always a better way to do something.
I have decided to start making tutorials on this forum and thought it would be best to start with something simple, yet useful to anybody.
Today i am going to show you how to make command timers with "tickcount()" using two simple steps, eliminating the need for actual timers.
(Please forgive me if this tutorial is already covered, i did not find any during my search.)
Step 1 - Creating the timer data variable/s:
I am going to show you how to do this using an enum so it will be alot easier for you to add more command timers in future, and it will be alot better then making an individual player variable for each command.
pawn Code:
enum timer_data//creating the enum
{
CMD_yourcommand//creating the data value for the command
}
new TimerInfo[MAX_PLAYERS][timer_data];//creating the player variable
Now basically, all we have to do is set the player variable for the command to the tickcount() after the command is used, then when the command is used again, check if the tickcount() minus w/e time we restrict is less then the player variable(tickcount()), if so they have used the command within the restricted time frame and we simply tell them "Please wait before using this command again.", simple or what?
pawn Code:
//under the command you want to add a timer to
{
new time = tickcount() - 60000;//we set our new variable(time) to the tickcount() minus 1 minute(Example time frame)
if(time < TimerInfo[playerid][CMD_yourcommand]) return SendClientMessage(playerid, -1, "Please wait before using this command again.");//if our new variable(explained above) is less then our player variable(tickcount()), the server has not lapsed the amount of the time frame, so tell them to wait.
//else it has lapsed meaning the player has waited the amount of the time frame, let them continue with the command
TimerInfo[playerid][CMD_yourcommand] = tickcount();//and set there player variable to the new tickcount()
//command code starts here...
return 1;
}