[Tutorial] Simple Command [ZCMD] [Explained] [Better]
#1

Welcome!

I, For many who do not know am Silentzx, i have been scripting for quite a while now and recently been given the rights to Incorporated Roleplay, and for most of you who understand the crappy edit will properly hate me, However as i am now the owner of the Incorporated Role-Play i am going to be scripting a new GM, However thats off topic.

Okay, Firstly i would like to say that these will start simple becoming harder as we progress.

Simple Commands we shall do today:
Simple: Kill
Simple: Healme
Simple: Heal

Okay so to start.

Most of you will have used strcmp before, this is the basic command processor SA:MP gives you, However, there are loads more, better, faster command processors out there.

I personally prefer ZCMD.

So this is what we shall be using today.

To explain:

in the next commands we shall be using the SetPlayerHealth function. Basically it has to parameters:
Code:
playerid(the player who enters the command)
And the Float which in this case will be health.
This is a very simple command to script and can be easily modified I will attach my version of this command at the bottom.

Okay so to start you will need the ZCMD.inc from Zeex I will not attach a download link as i do not have the permission from the rightful owner.

So, at the top of your script add the following:
pawn Code:
#include <zcmd>
This, if you don't already know is adding new functions to your script, instead of the stock <a_samp> which you will still need.

Now the way zcmd works is it does all the work for you, so all you have to add is this:
pawn Code:
CMD:kill(playerid,params[]); // CMD, can be cmd, command, COMMAND, or CMD. then the command name, which is what a player enters after the "/" ingame, This however unlike strcmp is not needed due to the CMD, or how ever you want to put it.
{
     return 1; // We set it as this so that the server knows it is a valid command and wont return 0 in your commands causing - depending on how you have formatted it - SERVER:Unknown Command.
}
Thats the basic format for ZCMD, however now we can enter our parameters for example SetPlayerHealth.

So remembering what we discussed before about the floats and playerid, we can add this:
pawn Code:
CMD:kill(playerid,params[]); // CMD, can be cmd, command, COMMAND, or CMD. then the command name, which is what a player enters after the "/" ingame, This however unlike strcmp is not needed due to the CMD, or how ever you want to put it.
{
     SetPlayerHealth(playerid,0); // of course you want this set as 0 otherwise the player will no die.
     return 1; // We set it as this so that the server knows it is a valid command and wont return 0 in your commands causing - depending on how you have formatted it - SERVER:Unknown Command.
}
Thats the basic command done, but its rather boring don't you think?

Okay so here is another version:
[pawn]
pawn Code:
CMD:kill(playerid,params[]); // CMD, can be cmd, command, COMMAND, or CMD. then the command name, which is what a player enters after the "/" ingame, This however unlike strcmp is not needed due to the CMD, or how ever you want to put it.
{
     SetPlayerHealth(playerid,0); // of course you want this set as 0 otherwise the player will no die.
     GameTextForPlayer(playerid,"Wasted",3000,1);
     return 1; // We set it as this so that the server knows it is a valid command and wont return 0 in your commands causing - depending on how you have formatted it - SERVER:Unknown Command.
}
As you may see i have added game text, for who don't know this is very similar to SendClientMessage, but it displays on screen hense the name "GameText"

GameTextForPlayer Explained.
Code:
GameTextForPlayer(playerid,const string[],time,style);
playerid - The player you want to send to.
const string[] - The text you want your player to see in " "marks
time - Time the text is displayed.
Style - The style you want it displayed.
So that it is for the kill command now onto the healme.

Now this is also very simple.

Basically you are just doing the complete opposite of the kill command.

So once again we shall be using the SetPlayerHealth function.
So set up your command again

pawn Code:
CMD:healme(playerid,params[])
{
      return 1;
}
To speed things up slightly i shall not explain as much as the CMD:kill because all you need to do is change 0 to 100 and if you use the version with the game text then "Wasted" to "Healed" or what ever you want it to say.

pawn Code:
CMD:healme(playerid,params[])
{
     SetPlayerHealth(playerid,100);
     GameTextForPlayer(playerid,"Healed",1000,1);
     return 1;
}
And that is it again , Also i forgot to mention about changing colors in GameTextForPlayer or GameTextForAll
Code:
~r~ - Red
~g~ - Green
~y~ - Yellow
~b~ - Blue
~w~ - White
~p~ - Purple

And many more
Now what about adding a second player to our command this time called Heal?

this is also very simple and there are many ways of this being done however i prefer pID, this can be anything, As it is infact not set as a variable.

I would recommend keeping it simple to begin with.

Okay so this is alot easier then many people will think.

if you where to just copy the command and change playerid, to pID, you would be correctish, however you would recieve errors about pID not being defined, this also very simple.

pawn Code:
CMD:heal(playerid,params[])  // This will never change
{
    new pID; // adding the new playerid, that is all there is to it :)
    SetPlayerHealth(pID,100); // yay you just healed him :)
    /* You could add game text here if you wish also */
    return 1;
}
However this command is not complete. As you notice with most multi player command they will give you an Error in game - Well most good scripts will

This is to allow the player to know what he/she has done wrong.

For this we shall use the isnull function. I my self have only just started using isnull as i mostly use sscanf but that is for a different tutorial

There are many ways for doing this.

I will state them bellow:

pawn Code:
if(isnull(params)) // this stays the same always. V1
{
   SendClientMessage(playerid,COLOR,"USAGE: /heal <playerid>");
}
// Or:
if(isnull(params)) return SendClientMessage(playerid,COLOR,"USAGE: /heal <playerid>");
Okay so as you can see we used the "SendClientMessage" function. This is very similar to gametext but you print the text inside the players chat box.

You should already now how this works if not go and watch a pawno basics video

Okay so now we shall add this to our command:
pawn Code:
CMD:heal(playerid,params[])  // This will never change
{
    new pID; // adding the new playerid, that is all there is to it :)
    if(isnull(params)) return SendClientMessage(playerid,COLOR,"USAGE: /heal <playerid>"); // I prefer to use this but there are many otherways.
    SetPlayerHealth(pID,100); // yay you just healed him :)
    /* You could add game text here if you wish also */
    return 1;
}
Thats it your all done you could always add fees to the heal command and lots more

As promised my stunt kill command
pawn Code:
/* I wont explain about this but give it time and you will be able to make something similar very easily */
CMD:kill(playerid,params[])
{
    GameTextForPlayer(playerid,"Death In 5 Seconds",5000,1);
    SetTimer("Death",5000,false);
    return 1;
}
forward Death(playerid);
public Death(playerid)
{
    new string[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    format(string,sizeof(string),"%s, Just committed suicide!",name);
    SendClientMessageToAll(-1,string);
    SetPlayerHealth(playerid,0);
    GameTextForPlayer(playerid,"Wasted!",5000,4);
    return 1;
}
So that is it, I decided to make this tutorial after seeing a crappy one before i hope this is better.

Thanks for reading, I hope i helped some of you.

Thanks to:
SA:MP,
Zeex,
SA:MP to Wiki for the GameText Styles

Mistakes?

Reply ASAP so i can fix them

I want to hear any comments good or bad so i can improve on this and ones in the future



Edit: All Comments Would Be Nice! If i helped you then please rep+ me Want to request more from me ? Reply! Errors ? Reply! Good,Bad Any Comments Please Reply!
Reply
#2

Good tutorial. Nice!
Reply
#3

pawn Code:
CMD:kill(playerid,params[])
{
    GameTextForPlayer(playerid,"Death In 5 Seconds",5000,1);
    SetTimer("Death",5000,false);
    return 1;
}
forward Death(playerid);
public Death(playerid)
{
    new string[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    format(string,sizeof(string),"%s, Just committed suicide!",name);
    SendClientMessageToAll(-1,string);
    SetPlayerHealth(playerid,0);
    GameTextForPlayer(playerid,"Wasted!",5000,4);
    return 1;
}
I believe you're saying that this tutorial is better than other command tutorials even though you're supplying code that will not work such as the one I've listed here. You can guess the problem there..
Reply
#4

Lorenc_ ... You can explain it too )

pawn Code:
SetTimerEx( "Death", 5000, false, #i, playerid );
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)