Multiple Param Commands with SSCANF
#1

So, i've been trying to work out how to use multiple param commands, heres my code
pawn Код:
else if(!strcmp(option, "uninvite"))
    {
        if(sscanf(params, "{s[35]}r", pID)) return SendClientMessage(playerid, COLOR_GM, "USAGE: /faction uninvite [playerid]");
        print("Uninvite");
        printf("DEBUG 'uninvite' ID: %d", pID);
    }
But if there is a "pID" value inserted, it wont pass through, any idea?
Reply
#2

Those parameters are expecting 2 variables, but you've only got one variable (pID) in there...
EDIT: Show the whole command, I expect you're having 2 issues here.
Reply
#3

pawn Код:
CMD:faction(playerid, params[])
{
    new string[128], pID, rank, option[35], msgbox[128];
    if(PlayerInfo[playerid][Faction] == 0) return SendClientMessage(playerid, COLOR_ADMIN_GM, "You aren't in any faction!");
    if(sscanf(params, "s[128]", option)) return SendClientMessage(playerid, COLOR_ADMIN_GM, "USAGE: /faction [params]");
    if(!strcmp(option, "invite"))
    {
        if(sscanf(params, "{s[10]}r", pID)) return SendClientMessage(playerid, COLOR_ADMIN_GM, "USAGE: /faction invite [playerid]");
        else if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_ADMIN_GM, "Error: 65535 Invalid playerid!");
        else
        {
        printf("Debug, 'invite' pID: %s", pID);
        }
    }
    else if(!strcmp(option, "uninvite"))
    {
       if(sscanf(params, "{s[10]}r", pID)) return SendClientMessage(playerid, COLOR_ADMIN_GM, "USAGE: /faction uninvite [playerid]");
        else if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_ADMIN_GM, "Error: 65535 Invalid playerid!");
        else
        {
        print("Uninvite");
        printf("DEBUG 'uninvite' ID: %d", pID);
        }
    }
    return 1;
}
Reply
#4

As the guy with the family guy avatar said, also why are you using {s[10]} those brackets? (actual question not trying to sound smart or teach how to make simpler code) because I don't know if you can do like that, unsure! Uhm' I do not have the time atm to go on samp wiki and check what "r" next to {s[10]} stands for but I am always using "u" if it's an ID. If you use "u" the user can type in both an ID or part of the player name (not both at same time of course).

I have honestly never done the option param thing in commands yet but I have asked about it before. What I am reading is that you're going to pick a option string in your first sscanf ("s[128]") and based on that, it will compare "option" with "invite" aka if the player typed in "invite". Then you are asking the player if he typed in another string in your second sscanf. A string and an "r". I think a r/u would have been enough there. And that is what I think is the problem.
Reply
#5

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
As the guy with the family guy avatar said, also why are you using {s[10]} those brackets? (actual question not trying to sound smart or teach how to make simpler code) because I don't know if you can do like that, unsure! Uhm' I do not have the time atm to go on samp wiki and check what "r" next to {s[10]} stands for but I am always using "u" if it's an ID. If you use "u" the user can type in both an ID or part of the player name (not both at same time of course).

I have honestly never done the option param thing in commands yet but I have asked about it before. What I am reading is that you're going to pick a option string in your first sscanf ("s[128]") and based on that, it will compare "option" with "invite" aka if the player typed in "invite". Then you are asking the player if he typed in another string in your second sscanf. A string and an "r". I think a r/u would have been enough there. And that is what I think is the problem.
"r" is same as "u" but it excludes bots, and for the {s[10]} it leaves the "invite" for example checked, but not stored, that's what I read.
Reply
#6

Hehe good to know, thanks!
Reply
#7

Bumping
Reply
#8

If you use sscanf the paramter 's' will get the whole string if no other parameter is passed
That would be the solution stated in the sscanf topic
pawn Код:
if(sscanf(params, "s[128] ", option)) {}
Reply
#9

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
If you use sscanf the paramter 's' will get the whole string if no other parameter is passed
That would be the solution stated in the sscanf topic
pawn Код:
if(sscanf(params, "s[128] ", option)) {}
Read above.

I suggest you use y_stringhash it's easier and faster, also not suggesting you to use isnull but it's only a string there's no integer or float so I'd rather use isnull anyways, try this command, make sure sure have #include <YSI\y_stringhash>

pawn Код:
CMD:faction(playerid, params[])
{
    new
        string[ 128 ], pID, rank, msgbox[128];

    if( PlayerInfo[ playerid ][ Faction ] == 0 )
        return SendClientMessage( playerid, COLOR_ADMIN_GM, "You aren't in any faction!" );

    if( isnull( params ) )
        return SendClientMessage( playerid, COLOR_ADMIN_GM, "USAGE: /faction [params]" );

    switch( YHash( params ) )
    {
        case _H< invite >:
        {
            if( sscanf ( params, "u", pID ) )
                return SendClientMessage(playerid, COLOR_ADMIN_GM, "USAGE: /faction invite [Player Name/ID]" );

            if( !IsPlayerConnected( pID ) )
                return SendClientMessage(playerid, COLOR_ADMIN_GM, "Error: 65535 Invalid playerid!" );
           
            print( "Invite" );
            printf( "Debug, 'invite' pID: %s", pID );
           
        }
        case _H< uninvite >:
        {
            if( sscanf( params, "u", pID ) )
                return SendClientMessage( playerid, COLOR_ADMIN_GM, "USAGE: /faction uninvite [Player Name/ID]" );

            if( !IsPlayerConnected( pID ) )
                return SendClientMessage( playerid, COLOR_ADMIN_GM, "Error: 65535 Invalid playerid!" );
           
            print( "Uninvite" );
            printf( "DEBUG 'uninvite' ID: %d", pID );
           
        }
    }  
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)