[Tutorial] How to make a /ad cmd[YCMD]
#1

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:
pawn Код:
#include <a_samp>
#include <YSI\y_commands>
Now, we need to create a variable that will help us later. We give it the "0" value.
pawn Код:
new adtimer = 0;
OK, we got the variable, now let's create the cmd:
pawn Код:
YCMD:ad(playerid, params[], help)
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:
pawn Код:
if(isnull(params))
    {
        SendClientMessage(playerid, 0x503000FF, "Usage : /ad [advertise text]");
    }
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.
pawn Код:
else
    {
        if(adtimer == 0)
        {
Done, now we have to create a 128 characters lenght:
pawn Код:
new str[128];
After that, let's find out the player's name using GetPlayerName function:
pawn Код:
GetPlayerName(playerid, str, sizeof(str));
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:
pawn Код:
format(str, sizeof(str), "{00FFFF}<Advertise> {FF0000}%s {00FFFF}: {FFFFFF}%s.", str, params);
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:
pawn Код:
SendClientMessageToAll(0xFFFFFFFF, str);
Now we have to set the variable we created for the timer to 1.
pawn Код:
adtimer = 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:
pawn Код:
SetTimer("AdTimer", 60000, 0);
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:
pawn Код:
else if(adtimer == 1)
        {
            SendClientMessage(playerid, 0xFF0000FF, "You must wait 1 minute between advertises");
        }
    }
    return 1;
}
Of course, the timer part won't work if we don't do the right function for it. First, let's forward it:
pawn Код:
forward AdTimer();
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:
pawn Код:
public AdTimer()
{
    adtimer = 0;
    return 1;
}
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 ******.
Reply


Messages In This Thread
How to make a /ad cmd[YCMD] - by DiGiTaL_AnGeL - 05.02.2013, 20:11
Respuesta: How to make a /ad cmd[YCMD] - by ThePhenix - 05.02.2013, 20:15
Re: How to make a /ad cmd[YCMD] - by DiGiTaL_AnGeL - 06.02.2013, 11:50
Re: How to make a /ad cmd[YCMD] - by Astrais - 06.02.2013, 12:00
Re: How to make a /ad cmd[YCMD] - by [GF]Logic - 06.02.2013, 12:51
Re: How to make a /ad cmd[YCMD] - by gtakillerIV - 06.02.2013, 12:53
Re: How to make a /ad cmd[YCMD] - by RajatPawar - 06.02.2013, 12:55
Re: How to make a /ad cmd[YCMD] - by DiGiTaL_AnGeL - 06.02.2013, 12:55

Forum Jump:


Users browsing this thread: 1 Guest(s)