04.06.2012, 23:26
(
Last edited by Sandiel; 17/07/2012 at 10:42 PM.
)
Creating Commands
using ZCMD, sscanf
Description:
Good day, I'am Sandiel, and this is a tutorial on how to make easy and simple-to-understand commands using ZCMD, and sscanf.
I've seen many people, including myself, as we started learning the Pawn language, struggeling for help, serious tutorial-like help. Well, that's what I'm offering you right now, a decent good and simple tutorial on making commands in Pawn.
Requirments:
-ZCMD, by Zeex (Found here)
-sscanf 2.6, by ****** (Found here)
-IQ of over 50 (404 not found, derp)
Let's Begin:
First of all, I have to say, most simple command that ever existed has to be: /healme
Here is the full command, then we'll analyse it bit by bit.
So, here's the analysing part:
What is this? this is defining the command, and naming it. (Notice there is no "/" in here, it's auto-put in the ZCMD command processor)
So, SetPlayerHealth, is what is basicly written, sets a player health to whatever. Playerid means the player who /healme'd, and 100.0 is the health we want him to have.
SendClientMessage, means sending a message to a specific player. Playerid, means, yet again, the player that we written the command (/healme), COLOR_WHITE is the color we want the message to be in (HEX code: 0xFFFFFFAA) and then the text between the "" is the message we want him to see.
new is a statement in the Pawn language which indicates we are defining a new variable. "String" is the variable we are creating, it just a variable that holds information (usualy text/message) you can rename it to whatever you like. the array "128" is the size of the variable.
Now, "pName" is a variable that I made to hold the player's name, and we will use it later in the command. (Name is editable, it can be pName, playername, bullshit, shit, crap, penis anything you like )
The function GetPlayerName explains itself, doesn't it?
"Playerid" means, yet again, the player who typed in the command (/healme)
pName, is the variable we made to hold the player's name, and display it whenever we want.
"sizeof(pName)" is the size of the player's name, again, this explains itself.
This is where the variable "string" that we defined earlier comes to play, you see, "format" stands for the format of the message that is going to be send (usualy used for messages, others are advanced pawno stuff, don't mind them, you'll hardly see them)
"sizeof(string)" is just like "sizeof(pName)", it just defines how large is the name/message.
the text between "" is the message itself that is going to be sent.
Notice it has "%s" in it, %s stands for "string" (text, name, sentence, words)
We define the %s with "pName", so now it's the player's name, which means the text in-game should be:
"** "pName" has just healed himself, his health is now 100."
Now, SendClientMessageToAll means we are going to send a message to everyone in the server.
COLOR_YELLOw, is just the color of the message (HEX code: 0xFFFF00AA)
"string" means the message will be the content of the string which we defined earlier, and that we set it's "format".
This means the command "Healme" will return a value, that value is "1" which stands for "true".
If the value is true, the command will run, if it is "0" it will not run as it will stand for "false".
The End:
Well, that's about it, the whole tutorial is based on one command, it's easy, and simple, but it's the basic concept of using commands with ZCMD. As you see, this is part 1 of the newbie tutorial for ZCMD commands, a part 2 will be provided soon and maybe even part 3 and part 4, alongside an advanced tutorial for ZCMD commands, I'm Sandiel, and I approve this message, cheers.
Good day, I'am Sandiel, and this is a tutorial on how to make easy and simple-to-understand commands using ZCMD, and sscanf.
I've seen many people, including myself, as we started learning the Pawn language, struggeling for help, serious tutorial-like help. Well, that's what I'm offering you right now, a decent good and simple tutorial on making commands in Pawn.
Requirments:
-ZCMD, by Zeex (Found here)
-sscanf 2.6, by ****** (Found here)
-IQ of over 50 (404 not found, derp)
Let's Begin:
First of all, I have to say, most simple command that ever existed has to be: /healme
Here is the full command, then we'll analyse it bit by bit.
pawn Code:
COMMAND:healme(playerid, params[]) // or CMD:healme(playerid, params[])
{
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, COLOR_BLUE, "You have healed yourself, your health is now 100.");
new string[128];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "** %s has just healed himself, his health is now 100.", pName);
SendClientMessageToAll(COLOR_YELLOW, string);
return 1;
}
pawn Code:
COMMAND:healme(playerid, params[]) // or CMD:healme(playerid, params[])
pawn Code:
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, COLOR_BLUE, "You have healed yourself, your health is now 100.");
SendClientMessage, means sending a message to a specific player. Playerid, means, yet again, the player that we written the command (/healme), COLOR_WHITE is the color we want the message to be in (HEX code: 0xFFFFFFAA) and then the text between the "" is the message we want him to see.
pawn Code:
new string[128];
new pName[MAX_PLAYER_NAME];
Now, "pName" is a variable that I made to hold the player's name, and we will use it later in the command. (Name is editable, it can be pName, playername, bullshit, shit, crap, penis anything you like )
pawn Code:
GetPlayerName(playerid, pName, sizeof(pName));
"Playerid" means, yet again, the player who typed in the command (/healme)
pName, is the variable we made to hold the player's name, and display it whenever we want.
"sizeof(pName)" is the size of the player's name, again, this explains itself.
pawn Code:
format(string, sizeof(string), "** %s has just healed himself, his health is now 100.", pName);
SendClientMessageToAll(COLOR_YELLOW, string);
"sizeof(string)" is just like "sizeof(pName)", it just defines how large is the name/message.
the text between "" is the message itself that is going to be sent.
Notice it has "%s" in it, %s stands for "string" (text, name, sentence, words)
We define the %s with "pName", so now it's the player's name, which means the text in-game should be:
"** "pName" has just healed himself, his health is now 100."
Now, SendClientMessageToAll means we are going to send a message to everyone in the server.
COLOR_YELLOw, is just the color of the message (HEX code: 0xFFFF00AA)
"string" means the message will be the content of the string which we defined earlier, and that we set it's "format".
pawn Code:
return 1;
If the value is true, the command will run, if it is "0" it will not run as it will stand for "false".
The End:
Well, that's about it, the whole tutorial is based on one command, it's easy, and simple, but it's the basic concept of using commands with ZCMD. As you see, this is part 1 of the newbie tutorial for ZCMD commands, a part 2 will be provided soon and maybe even part 3 and part 4, alongside an advanced tutorial for ZCMD commands, I'm Sandiel, and I approve this message, cheers.