Multiple parameter help (sscanf)
#2

pawn Код:
CMD:wear( playerid, params[] )
{
    /*
        Slot 0 - Hats, caps.
    */

   new colour[32], object[40];
   if(!sscanf(params, "s[40]S[32], object, colour)) {
        if(!strcmp(object, "
policecap")) {
             if( plStats [ playerid ] [ HasAPoliceCap ] == 1 )
            {
                SetPlayerAttachedObject( playerid, 0, 18636, 2 );
                EditAttachedObject( playerid, 0 );
            }
            else return ShowPlayerErrorMessage( playerid, "
You don't have a \"Police Cap\"!" );
        } elseif(!strcmp(object, "beret")) {
           if(strlen(colour) == 0) return SendClientMessage( playerid, Colour_RankOrange, "HELP: "#Int_White"/wear beret [ colour (red, black, blue, army) ]" );
           if(!strcmp(colour, "red")) {
                SetPlayerAttachedObject( playerid, 0, 18922, 2 );
                EditAttachedObject( playerid, 0 );
           }
           else return ShowPlayerErrorMessage( playerid, "Invalid colour!" );
        }
   }
   return true;
}
This reduces your code a huge bit. Explanation:

s[40]S[32] - a capital s is an optional string. It can be taken in at your beret colour.

Then we check the object (which we took from the first param) and enter the code. Then checking the length of colour. if it is 0, then no colour is given and thus we throw the error, else,, you continue with your own code. For the rest, I didn't come across anything else that looked a little dodgey
Reply


Messages In This Thread
Multiple parameter help (sscanf) - by 2KY - 30.09.2012, 17:02
Re: Multiple parameter help (sscanf) - by mamorunl - 30.09.2012, 17:55

Forum Jump:


Users browsing this thread: 1 Guest(s)