SA-MP Forums Archive
Multiple Param Commands with SSCANF - 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: Multiple Param Commands with SSCANF (/showthread.php?tid=481816)



Multiple Param Commands with SSCANF - FalconWingsX - 17.12.2013

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?


Re: Multiple Param Commands with SSCANF - Joe Staff - 17.12.2013

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.


Re: Multiple Param Commands with SSCANF - FalconWingsX - 17.12.2013

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;
}



Re: Multiple Param Commands with SSCANF - Hansrutger - 17.12.2013

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.


Re: Multiple Param Commands with SSCANF - FalconWingsX - 17.12.2013

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.


Re: Multiple Param Commands with SSCANF - Hansrutger - 17.12.2013

Hehe good to know, thanks!


Re: Multiple Param Commands with SSCANF - FalconWingsX - 19.12.2013

Bumping


AW: Multiple Param Commands with SSCANF - Nero_3D - 19.12.2013

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)) {}



Re: AW: Multiple Param Commands with SSCANF - Patrick - 19.12.2013

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;
}