SA-MP Forums Archive
Better way then strcmp? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Better way then strcmp? (/showthread.php?tid=325307)



Better way then strcmp? - Abreezy - 12.03.2012

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 =]


Re: Better way then strcmp? - Roko_foko - 12.03.2012

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.