[Tutorial] Full usage of dcmd!
#1

Hey guys! I am new here, but I already know how to use dcmd. In this case, I am going to make my first tutorial. I'll be posting many tutorials in *******, but for now, I hope you enjoy!

What's dcmd?:

dcmd is one of the fastest executing "plugin". The fastest one is zcmd, but dcmd is more professional and doesn't needs downloads. Now, dcmd has a better usage with sscanf. You can download sscanf here:
http://www.sendspace.com/file/4liijz

Now, extract the files, and take the sscanf2 include file, and put it into ...pawno/includes. And the other sscanf file into Plugins folder. Now, open server.cfg and add a line.

Code:
plugins sscanf
That's all for this "chapter"

Defines

Now, for the define, you only need a line!

pawn Code:
#include <a_samp>
#include <sscanf2>

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

#define COLOR_PINK              0xFFC0CBFF
#define COLOR_RED               0xFF0000FF
#define COLOR_GREEN             0x008000FF
#define COLOR_DARKBLUE          0x00008BFF
#define COLOR_CADETBLUE         0x5F9EA0FF
#define COLOR_LIGHTBLUE         0xADD8E6FF
#define COLOR_YELLOW            0xECD400F6
#define COLOR_LIGHTGREEN        0x90EE90FF
#define COLOR_PEACHPUFF         0xFFDAB9FF
#define LIGHTBLUE2              0xF6BB0AA
#define COLOR_GREY              0x808080FF
#define COLOR_ORANGE            0xFFA500FF
#define COLOR_BISQUE            0xFFE4C4FF
#define COLOR_BLANCHEDALMOND    0xFFEBCDFF
Now, let me explain that.

pawn Code:
#include <a_samp>
#include <sscanf2>
These are the two includes that you need. a_samp and sscanf2 (these MUST be in includes folder as an .ini file)

pawn Code:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
The dcmd include line. That's all for the dcmd define

pawn Code:
#define COLOR_PINK              0xFFC0CBFF
#define COLOR_RED               0xFF0000FF
#define COLOR_GREEN             0x008000FF
#define COLOR_DARKBLUE          0x00008BFF
#define COLOR_CADETBLUE         0x5F9EA0FF
#define COLOR_LIGHTBLUE         0xADD8E6FF
#define COLOR_YELLOW            0xECD400F6
#define COLOR_LIGHTGREEN        0x90EE90FF
#define COLOR_PEACHPUFF         0xFFDAB9FF
#define LIGHTBLUE2              0xF6BB0AA
#define COLOR_GREY              0x808080FF
#define COLOR_ORANGE            0xFFA500FF
#define COLOR_BISQUE            0xFFE4C4FF
#define COLOR_BLANCHEDALMOND    0xFFEBCDFF
Color defines. Very helpful!

How to use dcmd

Now, using dcmd is a little "busy". Follow me to a normal /pay cmd.

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(pay, 3, cmdtext); // this is the format that you will need to use. number 3 is for the characters of the word pay, "p" "a" "y"
    return 1;
}

dcmd_pay(playerid, params[])
{
    new targetid, value;
    if(sscanf(params, "ui", targetid, value)) return SendClientMessage(playerid, COLOR_RED, "ERROR: /pay [playerid] [amount]");
    else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
    else if(value > GetPlayerMoney(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You can't afford that much");
    else
    {
        GivePlayerMoney(targetid, value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You received %i from %u");
        GivePlayerMoney(playerid, 0- value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You transfered %i to %u");
    }
    return 1;
} // these are all the basics. if(sscanf... is the useage of sscanf. check it out!
Now, there is a problem. Many new users make mistakes in using multi cmds with dcmd. Why? Because dcmd it's different from zcmd and it needs some defines (like forward or dcmd())first. Now, let me make a multi command.
We will try the command pay and sethealth(admin cmd):

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(pay, 3, cmdtext); // this is the format that you will need to use. number 3 is for the characters of the word pay, "p" "a" "y"
    return 1;
}

dcmd_pay(playerid, params[])
{
    new targetid, value;
    if(sscanf(params, "ui", targetid, value)) return SendClientMessage(playerid, COLOR_RED, "ERROR: /pay [playerid] [amount]");
    else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
    else if(value > GetPlayerMoney(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You can't afford that much");
    else
    {
        GivePlayerMoney(targetid, value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You received %i from %u");
        GivePlayerMoney(playerid, 0- value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You transfered %i to %u");
    }
    return 1;
} // these are all the basics. if(sscanf... is the useage of sscanf. check it out!
This was the first cmd: pay. Now, for the second cmd sethealth we will add another line like this:

pawn Code:
dcmd(sethealth, 8, cmdtext); // this is a sethealth include. sethealth has 8 characters, so we put an 8
Where we will put this line? Close to the last one (define line). just like this:

pawn Code:
dcmd(pay, 3, cmdtext); // this is the format that you will need to use. number 3 is for the characters of the word pay, "p" "a" "y"
dcmd(sethealth, 8, cmdtext); // this is a sethealth include. sethealth has 8 characters, so we put an 8
Okay, so now we will make a sethealth cmd (admin only):

pawn Code:
dcmd_sethealth(playerid, params[])
{
    new targetid, value;
    if(sscanf(params, "ui", targetid, value)) return SendClientMessage(playerid, COLOR_RED, "ERROR: /sethealth [playerid] [amount]");
    else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
    else if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You have no access to that command");
    else
    {
        SetPlayerHealth(targetid, value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You succesfuly healed %u");
    }
    return 1;
}
Now, if you don't understand this command, just post here OR (better) PM me! Let's end this:

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(pay, 3, cmdtext); // this is the format that you will need to use. number 3 is for the characters of the word pay, "p" "a" "y"
    dcmd(sethealth, 8, cmdtext); // this is a sethealth include. sethealth has 8 characters, so we put an 8
    return 1;
}

dcmd_pay(playerid, params[])
{
    new targetid, value;
    if(sscanf(params, "ui", targetid, value)) return SendClientMessage(playerid, COLOR_RED, "ERROR: /pay [playerid] [amount]");
    else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
    else if(value > GetPlayerMoney(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You can't afford that much");
    else
    {
        GivePlayerMoney(targetid, value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You received %i from %u");
        GivePlayerMoney(playerid, 0- value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You transfered %i to %u");
    }
    return 1;
} // these are all the basics. if(sscanf... is the useage of sscanf. check it out!

dcmd_sethealth(playerid, params[])
{
    new targetid, value;
    if(sscanf(params, "ui", targetid, value)) return SendClientMessage(playerid, COLOR_RED, "ERROR: /sethealth [playerid] [amount]");
    else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
    else if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You have no access to that command");
    else
    {
        SetPlayerHealth(targetid, value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You succesfuly healed %u");
    }
    return 1;
}
This is our full command. Best wishes from Don!

P.s.: Any questions? Anything that I should post? PM me!
Reply


Messages In This Thread
Full usage of dcmd! - by Rivera - 13.03.2011, 22:02
Re: Full usage of dcmd! - by Montis123 - 13.03.2011, 22:54
Re: Full usage of dcmd! - by Snipa - 13.03.2011, 23:02
Re: Full usage of dcmd! - by randomkid88 - 13.03.2011, 23:03
Re: Full usage of dcmd! - by 1337connor - 13.03.2011, 23:10
Re: Full usage of dcmd! - by randomkid88 - 13.03.2011, 23:15
Re: Full usage of dcmd! - by Kyosaur - 14.03.2011, 08:30
Re: Full usage of dcmd! - by Calgon - 14.03.2011, 08:34
Re: Full usage of dcmd! - by Rivera - 14.03.2011, 08:52
Re: Full usage of dcmd! - by Kyosaur - 14.03.2011, 12:53
Re: Full usage of dcmd! - by Rivera - 14.03.2011, 14:09
Re: Full usage of dcmd! - by Montis123 - 14.03.2011, 15:15
Re: Full usage of dcmd! - by Davz*|*Criss - 14.03.2011, 16:48
Re: Full usage of dcmd! - by alpha500delta - 14.03.2011, 19:50
Re: Full usage of dcmd! - by deather - 15.03.2011, 13:37
Re: Full usage of dcmd! - by Dr.Ghost - 17.03.2011, 17:08
Re: Full usage of dcmd! - by MSam - 01.09.2018, 09:04
Re: Full usage of dcmd! - by CodeStyle175 - 01.09.2018, 09:57

Forum Jump:


Users browsing this thread: 2 Guest(s)