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);
}
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;
}
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. |
if(sscanf(params, "s[128] ", option)) {}
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 Код:
|
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;
}