05.02.2013, 20:11
(
Последний раз редактировалось DiGiTaL_AnGeL; 06.02.2013 в 11:40.
)
Hi! Today I'm going to teach you how to make a /ad command. If you read this tutorial well, you'll understand how to use strings, timers and how to work with YCMD too. So, here we go. Firts we need to include the samp library and ******'s command processor, YCMD:
Now, we need to create a variable that will help us later. We give it the "0" value.
OK, we got the variable, now let's create the cmd:
Now, we need to give the player's some informations about the cmd. Firstly, we check if there are no parameters, and then we send a message to him:
OK, we finished that, now we need to check if there are params. We do this with "else". After that, we check the variable we've created. This variable will help us to set a timer for the cmd, so players can acces it once a minute. It should look like this.
Done, now we have to create a 128 characters lenght:
After that, let's find out the player's name using GetPlayerName function:
OK, we got the player's name, now let's format that string created earlier. Remember, %s is used for letters, %d for numbers and %f for floats. We'll use %s cause we want only the player's name and his message:
That was easy. Now, we've created the string, let's send it to everybody. For that, we use the SendClientMessageToAll function, that sends a message to all the players online:
Now we have to set the variable we created for the timer to 1.
If the variable's value is 1, it means no one can advertise anything. But we don't want to be like this forever. So, we use a timer for that:
We have set the timer, now a part of the cmd is done. Now let's check if the advertise timer is active. If it's true, we'll tell the player that:
Of course, the timer part won't work if we don't do the right function for it. First, let's forward it:
OK, the forward part is done, let's do it. In the public we will set the variable "adtimer" to 0. When we've set the timer, we set it to 60 seconds. After 60 seconds, the public will be activated and the variable will be set again to 0, so players can advertise:
This was the tutorial, I hope I helped you, and remember : YSI is the fastest and the easiest way to script, and all because of ******.
pawn Код:
#include <a_samp>
#include <YSI\y_commands>
pawn Код:
new adtimer = 0;
pawn Код:
YCMD:ad(playerid, params[], help)
pawn Код:
if(isnull(params))
{
SendClientMessage(playerid, 0x503000FF, "Usage : /ad [advertise text]");
}
pawn Код:
else
{
if(adtimer == 0)
{
pawn Код:
new str[128];
pawn Код:
GetPlayerName(playerid, str, sizeof(str));
pawn Код:
format(str, sizeof(str), "{00FFFF}<Advertise> {FF0000}%s {00FFFF}: {FFFFFF}%s.", str, params);
pawn Код:
SendClientMessageToAll(0xFFFFFFFF, str);
pawn Код:
adtimer = 1;
pawn Код:
SetTimer("AdTimer", 60000, 0);
pawn Код:
else if(adtimer == 1)
{
SendClientMessage(playerid, 0xFF0000FF, "You must wait 1 minute between advertises");
}
}
return 1;
}
pawn Код:
forward AdTimer();
pawn Код:
public AdTimer()
{
adtimer = 0;
return 1;
}