[Tutorial] How to create easy commands for newbie scripters[Part1]
#1

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.

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;
}
So, here's the analysing part:
pawn Code:
COMMAND:healme(playerid, params[]) // or CMD:healme(playerid, params[])
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)
pawn Code:
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, COLOR_BLUE, "You have healed yourself, your health is now 100.");
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.

pawn Code:
new string[128];
new pName[MAX_PLAYER_NAME];
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 )

pawn Code:
GetPlayerName(playerid, pName, sizeof(pName));
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.

pawn Code:
format(string, sizeof(string), "** %s has just healed himself, his health is now 100.", pName);
SendClientMessageToAll(COLOR_YELLOW, string);
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".

pawn Code:
return 1;
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.
Reply
#2

Nice tutorial!
Reply
#3

Dude, there are tons of these. I would like to see something more complex other than a rather easy command such as /healme since everyone knows how...

https://sampforum.blast.hk/showthread.php?tid=319000
https://sampforum.blast.hk/showthread.php?tid=327201
https://sampforum.blast.hk/showthread.php?tid=324389
https://sampforum.blast.hk/showthread.php?tid=319452
Reply
#4

Quote:
Originally Posted by Edward156
View Post
Dude, there are tons of these. I would like to see something more complex other than a rather easy command such as /healme since everyone knows how...

https://sampforum.blast.hk/showthread.php?tid=319000
https://sampforum.blast.hk/showthread.php?tid=327201
https://sampforum.blast.hk/showthread.php?tid=324389
https://sampforum.blast.hk/showthread.php?tid=319452
I'm working on part 2, 3, 4 for NEWBIES, which will have only a few simple commands to get the basics in.
Then I'mma start working on advanced tutorials, where enums, variables, global variables, and many other functions come to play.
Reply
#5

Thanks bro your the best at this
Reply
#6

ZCMD is most easy than strcmp?. I'd strcmp for me it is more easier. I like your style to create tutorials, You can do tutorials about how create admin system or register system or another thing for newbies how us (only newbies say I).
Reply
#7

Nice one. But keep in mind that you have to define "COLOUR_YELLOW".
On top of your script:
#define COLOUR_YELLOW 0xFFFF00AA
Reply
#8

Quote:
Originally Posted by Rayco
View Post
ZCMD is most easy than strcmp?. I'd strcmp for me it is more easier. I like your style to create tutorials, You can do tutorials about how create admin system or register system or another thing for newbies how us (only newbies say I).
Will do right now, boss
Reply
#9

strcmp a.k.a string comparing is easy but its slow and old.
i rather recommend to use rCMD, zCMD, yCMD etc...
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)