29.10.2013, 22:07
(
Последний раз редактировалось Keyhead; 06.11.2013 в 12:02.
)
Simple ZCMD Commands (Using sscanf)
Firstly, the plugins and includes you will need and that we will be using are listed below:
(Installation instructions on detailed on their threads)
Now you have the includes and plugins. Let's begin.
You'll have to include both of the includes you have just downloaded.
(Don't forget to include a_samp)
For the purpose of this tutorial, I am only going to use two colours. You'll have to define them.
The first command we're going to create is a simple announce command. It'll display some text to all of the players currently playing in your server for a set amount of time.
Now, Let's break it down.
Firstly, This if statement is telling the script that if the parameters are left blank then it should send a message to the player executing the command telling him how to execute it correctly. The 's' in "s[128]" is called a specifier. It specifies that the text in the parameters is a string. The 128 is the length of the said string.
This will send the text you have put into command and display it to everyone who is currently connected to your server. It will stay on their screen for 10000 milliseconds. The 0 is the GameText Type. For different types,
Visit - GameText Styles
Now that we have finished that simple announcement command. Lets move on to something different.
And again, We will break it down. So you actually understand it.
Add this stock at the bottom of your gamemode. It's creating a stock function. All it will do is retrieve the name of the players, So then we don't have to write the same line over and over again.
We create two new variables. A Text variable and a string. They're both 128 characters in length.
As you may noticed, sscanf is a useful tool when producing commands. Again, It's telling the script to
send us a message if the parameters are not filled correctly. The "s[128]" specifies it's a string and it's 128 characters long, just like before.
Here we format the string. This is the format of which the information you have put into the command will be displayed. The "((%s:%s)) part of the line is specifying two string variables. We then define them. One of them is defined as a player name and the other is defined as the text.
This will send the message to all the players logged in. The color is yellow, Which we have previously defined earlier in this tutorial. str is the string we previously formatted.
Now, Lets move on to toggling the OOC Chat channel on and off. This can come in handy when you do not want people spamming.
Now we explain.
Firstly, You need to add this to the top of your script.
This is a bool. A bool can only ever be true or false. That makes it perfect for what we're doing. We set the bool to false every time the server starts.
This if statement is telling the script that if the variable is set to false, then the OOC Channel is to be activated.
Now, When it activates. We send a message to all the online players, telling them that it is activated and now accessible. Once it's activated, We need to set the variable to true. So we can toggle it off again.
Now we check if it's set to true already, Meaning it's activated. Meaning the channel is set to be de-activated.
So we send a message, notifying every player online and now set it back to false so you can toggle it back on when you feel the need.
Now we have the toggle feature scripted. We now need to implement it into our current command.
I'll explain the changes.
We can use the variable we created earlier, and utilize it so that we can make the OOC Chat channel unavailable when toggled off.
When it's unavailable. The script will send this message to the player trying to use the command.
When it's available however, You can continue to script the command as normal.
Unnecessary Extras
If you do not want everyone to be able to toggle your OOC command. You can add this line.
This will make it so only people logged into the RCON can access the command.
Also, Some command shortcuts can be made:
The "return cmd_announce(playerid, params);" is telling the script it's the same command under a different name.
I hope this tutorial was helpful to you new scripters.
Credits
a_samp by the SA-MP team.
ZCMD - The command processor used. Created by Zeex.
sscanf - Created by ******
This tutorial - Created by Keyhead
Firstly, the plugins and includes you will need and that we will be using are listed below:
(Installation instructions on detailed on their threads)
Now you have the includes and plugins. Let's begin.
You'll have to include both of the includes you have just downloaded.
(Don't forget to include a_samp)
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
pawn Код:
#define RED 0xFF0000AA
#define YELLOW 0xFFFF00AA
The first command we're going to create is a simple announce command. It'll display some text to all of the players currently playing in your server for a set amount of time.
pawn Код:
CMD:announce(playerid, params[])//This is the command.
{
new text[128];
if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid, RED, "(([!]Syntax:/announce[text]))");
GameTextForAll(text, 10000,0);
return 1;//Here we return the command.
}//Closing the brackets end the command.
pawn Код:
if(sscanf(params,"s",params)) return SendClientMessage(playerid, RED, "(([!]Syntax:/announce[text]))");
pawn Код:
GameTextForAll(text, 10000,0);
Visit - GameText Styles
Now that we have finished that simple announcement command. Lets move on to something different.
pawn Код:
CMD:ooc(playerid, params[])
{
new text[128], str[128];
if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid, RED, "(([!]Syntax:/ooc[text]))");
format(str, 128, "((%s:%s))", PlayerName(playerid), text);
SendClientMessageToAll(YELLOW, str);
return 1;//Now we return our command.
}//Close the brackets.
pawn Код:
stock PlayerName(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
return pName;
}
pawn Код:
new text[128], str[128];
pawn Код:
if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid, RED, "(([!]Syntax:/ooc[text]))");
send us a message if the parameters are not filled correctly. The "s[128]" specifies it's a string and it's 128 characters long, just like before.
pawn Код:
format(str, 128, "((%s:%s))", PlayerName(playerid), text);
pawn Код:
SendClientMessageToAll(YELLOW, str);
Now, Lets move on to toggling the OOC Chat channel on and off. This can come in handy when you do not want people spamming.
pawn Код:
CMD:toggleooc(playerid, params[])//This command will utilize a new variable.
{
if(toggleooc == false)//This is the variable.
{
SendClientMessageToAll(YELLOW, "((The OOC Chat Channel Has Been Activated!))");
toggleooc = true;
}
else if(toggleooc == true)
{
SendClientMessageToAll(YELLOW, "((The OOC Chat Channel Has Been Disabled!))");
toggleooc = false;
}
return 1;//we return the command
}//Close the brackets.
Firstly, You need to add this to the top of your script.
pawn Код:
new bool:toggleooc = false;
pawn Код:
if(toggleooc == false)//This is the variable.
pawn Код:
SendClientMessageToAll(YELLOW, "((The OOC Chat Channel Has Been Activated!))");
toggleooc = true;
pawn Код:
else if(toggleooc == true)
pawn Код:
SendClientMessageToAll(YELLOW, "((The OOC Chat Channel Has Been Disabled!))");
toggleooc = false;
Now we have the toggle feature scripted. We now need to implement it into our current command.
pawn Код:
CMD:ooc(playerid, params[])
{
new text[128];// We define a new text variable with the size of 128.
if(toggleooc == false)//We can use the variable we created earlier, and utilize it so that we can make the OOC
//Chat channel unavailable when toggled off.
{
SendClientMessage(playerid, RED, "((The OOC Chat Channel is not activated!))");
return 1;
//When it's unavailable. The script will send this message to the player trying to use the command.
}
if(toggleooc == true)//When it's available however, You can continue to script the command as normal.
{
if(sscanf(params, "s[128]",text)) return SendClientMessage(playerid, RED, "(([!]Syntax:/ooc[text]))");
SendClientMessageToAll(YELLOW,text);
return 1;
}
return 1;//Return the command
}//Close the brackets
pawn Код:
if(toggleooc == false)
pawn Код:
SendClientMessage(playerid, RED, "((The OOC Chat Channel is not activated!))");
return 1;
pawn Код:
if(toggleooc == true)
{
if(sscanf(params, "s[128]",text)) return SendClientMessage(playerid, RED, "(([!]Syntax:/ooc[text]))");
SendClientMessageToAll(YELLOW,text);
return 1;
}
Unnecessary Extras
If you do not want everyone to be able to toggle your OOC command. You can add this line.
pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "(([!]You cannot access this command as you're not admin!))");
if(IsPlayerAdmin(playerid))
{
Command here...
}
Also, Some command shortcuts can be made:
pawn Код:
CMD:o(playerid, params[])
{
return cmd_ooc(playerid, params);
}
CMD:an(playerid, params[])
{
return cmd_announce(playerid, params);
}
I hope this tutorial was helpful to you new scripters.
Credits
a_samp by the SA-MP team.
ZCMD - The command processor used. Created by Zeex.
sscanf - Created by ******
This tutorial - Created by Keyhead