How to make a /ad cmd[YCMD] -
DiGiTaL_AnGeL - 05.02.2013
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.
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:
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.
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:
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 ******.
Respuesta: How to make a /ad cmd[YCMD] -
ThePhenix - 05.02.2013
Quote:
Originally Posted by DiGiTaL_AnGeL
Hi! Today I'm going to learn you
|
Did you mean "teach you"?
Re: How to make a /ad cmd[YCMD] -
DiGiTaL_AnGeL - 06.02.2013
Yeah, thanks for notifying.
Re: How to make a /ad cmd[YCMD] -
Astrais - 06.02.2013
You should add a cost for the ad, like whenever someone creates an ad it costs like 2500
Re: How to make a /ad cmd[YCMD] -
[GF]Logic - 06.02.2013
Quote:
Originally Posted by Astrais
You should add a cost for the ad, like whenever someone creates an ad it costs like 2500
|
// add this
PHP код:
else
{
if(adtimer == 0)
{
if(GetPlayerMoney(playerid) > "Your cost")
{
//The ad lines
GivePlayerMoney(playerid, -"Your cost");
}
}
Re: How to make a /ad cmd[YCMD] -
gtakillerIV - 06.02.2013
Not bad, but it's not good for newbies. If it's your first tutorial then it's not bad for a first one.
You should really ident your codes.
Re: How to make a /ad cmd[YCMD] -
RajatPawar - 06.02.2013
Good, quite good for beginners. Try adding some more things, like, say, choosing your frequency of display of the ad, which varies with money!
Re: How to make a /ad cmd[YCMD] -
DiGiTaL_AnGeL - 06.02.2013
Quote:
Originally Posted by gtakillerIV
Not bad, but it's not good for newbies. If it's your first tutorial then it's not bad for a first one.
You should really ident your codes.
|
Actually it's my 2nd tutorial. And I'll edit it later, will post at the end the full code.