How do I make a 'mullti' cmd?
#1

Well like the title say. In zcmd and sscanf, how do I make a cmd like this, /take [item]?
Examples: /take key, /take phone, /take watch etc.. ?
I only know the strcmp way but since zcmd and sscanf is supose to make it faster i figgured that doing it the strcmp way would slow it down making it useless to even upgrade to sscanf and zcmd in the first place..
So please give me some small code so I can understand.
Reply
#2

strcmp is not a command processor, it's a function to check equality between two strings. What the strcmp command method does is compares what the player has typed at OnPlayerCommandText and check if there's a match for that command;

With that being said, zcmds and sscanf make that check faster and more efficent. You still need to compare if what the player types matches what you want for them to take from the inventory with strcmp.

pawn Код:
new item[32];
sscanf(params, "s[32]",item);

if(strcmp(item,"Keys",true) == 0)
{
   //player has typed "Keys" as first parameter of the command
}
else if(strcmp(item,"Phone",true) == 0)
{
   //...
}
In a command it could look like this:

pawn Код:
CMD:take(playerid, params[])
{
    new item[32];
    if(sscanf(params,"s[32]",item))
        return SendClientMessage(playerid,0xFF0000FF,"ERROR: Unknown syntax (/take <item> is the correct).");
       
    if(strcmp(item,"Keys",true) == 0)
    {
        //..
    }
    else if(strcmp(item,"Phone",true) == 0)
    {
        //..
    }
    //.....
    return 1;
}
Reply
#3

I downloaded another GM wthat uses zcmd and sscanf to see if I could get a tip from there.
pawn Код:
CMD:sign(playerid, params[])
{
    new
    give[5];

    if(sscanf(params, "s[5]", give)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /sign [1-4]");
    if(!strcmp(give, "1", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign2", 4.1, 1, 1, 1, 1, 1, 1);
    }
    else if(!strcmp(give, "2", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign3", 4.1, 1, 1, 1, 1, 1, 1);
    }
    else if(!strcmp(give, "3", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign5", 4.1, 1, 1, 1, 1, 1, 1);
    }
    else if(!strcmp(give, "4", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign4LH", 4.1, 1, 1, 1, 1, 1, 1);
    }
    return 1;
}
Is this really how you do it?? Then why do you use zcmd and sscanf if you still gonna use strcmp in the command?? Or am I missing something??

EDIT: Saw what you said now and understand why strcmp is being used. Thanks!
Reply
#4

Quote:
Originally Posted by Don_Cage
Посмотреть сообщение
I downloaded another GM wthat uses zcmd and sscanf to see if I could get a tip from there.
pawn Код:
CMD:sign(playerid, params[])
{
    new
    give[5];

    if(sscanf(params, "s[5]", give)) return SendClientMessage(playerid, COLOR_GREY, "[Usage]: /sign [1-4]");
    if(!strcmp(give, "1", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign2", 4.1, 1, 1, 1, 1, 1, 1);
    }
    else if(!strcmp(give, "2", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign3", 4.1, 1, 1, 1, 1, 1, 1);
    }
    else if(!strcmp(give, "3", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign5", 4.1, 1, 1, 1, 1, 1, 1);
    }
    else if(!strcmp(give, "4", true))
    {
        ApplyAnimation(playerid, "GHANDS", "gsign4LH", 4.1, 1, 1, 1, 1, 1, 1);
    }
    return 1;
}
Is this really how you do it?? Then why do you use zcmd and sscanf if you still gonna use strcmp in the command?? Or am I missing something??

EDIT: Saw what you said now and understand why strcmp is being used. Thanks!
Not exactly. That code is really badly made.

The command checks for strings when it should check for an integer: "[Usage]: /sign [1-4]" 1-4 is a numeric input, therefor sscanf should read an integer, not a string:

pawn Код:
new anim;
sscanf(params,"i",anim);
then what number can be easily checked with if(anim == 1) .. else if(anim == 2) or even with switch statements.

strcmp is for strings, (str prefix (string), cmp suffix (compare)), it essentialy compares two strings. That command should be done with integers, not with strings.
Reply
#5

Quote:
Originally Posted by CuervO
Посмотреть сообщение
Not exactly. That code is really badly made.

The command checks for strings when it should check for an integer: "[Usage]: /sign [1-4]" 1-4 is a numeric input, therefor sscanf should read an integer, not a string:

pawn Код:
new anim;
sscanf(params,"i",anim);
then what number can be easily checked with if(anim == 1) .. else if(anim == 2) or even with switch statements.

strcmp is for strings, (str prefix (string), cmp suffix (compare)), it essentialy compares two strings. That command should be done with integers, not with strings.
Yes that I know, the GM was made while he was learning so he was sure there where many badly made codes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)