Multiple parameter help (sscanf)
#1

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

   
    if( strcmp( params, "policecap", false ) == 0 )
    {
        if( plStats [ playerid ] [ HasAPoliceCap ] == 1 )
        {
            SetPlayerAttachedObject( playerid, 0, 18636, 2 );
            EditAttachedObject( playerid, 0 );
        }
        else return ShowPlayerErrorMessage( playerid, "You don't have a \"Police Cap\"!" );
    }
    if( strcmp( params, "beret", false ) == 0 )
    {
        new
            colour [ 32 ];
               
        strdel( params, 0, 5 );
        if( sscanf( params, "s[32]", colour ) )
            return SendClientMessage( playerid, Colour_RankOrange, "HELP: "#Int_White"/wear beret [ colour (red, black, blue, army) ]" );
               
        if( strcmp( colour, "red", false ) == 0 )
        {
            SetPlayerAttachedObject( playerid, 0, 18922, 2 );
            EditAttachedObject( playerid, 0 );
        }
        else return ShowPlayerErrorMessage( playerid, "Invalid colour!" );
    }
    return true;
}
I had this working a while ago, problem is, now it's not lol. The problem is located in the 'beret' part of this, and I'm assuming has something to do with my strdel. Any ideas?
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)