Better way then strcmp?
#1

I currently do stuff like this:

pawn Код:
CMD:give(playerid, params[])
{
    new give[24], id, amount, string[128];
    if(sscanf(params, "is[24]d", id,give,amount)) return SendClientMessage(playerid, COLOR_RED, "[SERVER] /give playerid (money/weapon) amount");
    if(!strcmp(give, "money", true))
    {
      // money stuff
    }
    else if(!strcmp(give, "weapon", true))
    {
       // weapon stuff
    }
    return 1;
}
Is there any better way to do? Also I noticed I couldn't do this when I tried:

pawn Код:
CMD:give(playerid, params[])
{
    new give[24], id, amount, string[128];
    if(sscanf(params, "is[24]", id,give)) return SendClientMessage(playerid, COLOR_RED, "[SERVER] /give playerid (money/weapon)");
    if(!strcmp(give, "money", true))
    {
            if(sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOR_RED, "[SERVER] /give playerid money amount");
           // rest of code
    }
    else if(!strcmp(give, "weapon", true))
    {
       // weapon stuff
    }
    return 1;
}

If I tried doing that sscanf in the strcmp, it would just auto use amount at 0, without showing the error message. So is there any better then strcmp? If not, how could I use sscanf under strcmp?

Thanks in advance, will rep anyone who gives a valid reply =]
Reply
#2

I wouldn't say that the problem is in strcmp. It doesn't change variables. I don't know how is sscanf working. If i were you I would manually split the params to 3 variables and than use them.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)