Question - Sscanf
#1

such people ?,

my question is how to add an additional parameter after it has been verified with sscanf the first part, below I give you an example of the doubt.

Код:
CMD:test(playerid, params[])
{
   	if(sscanf(params, "i", params[0]))
 	{
		SCM(playerid, COLOR_LABELS, "/test [id test]");
		SCM(playerid, -1, "[ID test]: 1: test1 2: test2 3: test3");
		return 1;
  	}
	new helloworld;
	if(params[0] < 1 || params[1] > 3) return SendClientMessage(playerid, -1, "Error option.");
	switch(params[0]) {
		case 1: {
		    new player;
		    if(sscanf(params, "r", player))
		 	{
				SCM(playerid, COLOR_LABELS, "/test [id test] [player]");
				return 1;
		  	}
		    // How to add another parameter more here?, example: /test idtest player. "Player" would be the new parameter
		}	
		case 2: helloworld++;
		case 3: helloworld++;
	}
}
Reply
#2

You can add more parameters with ZCMD..
Reply
#3

In sscanf you make a parameter optional by adding (default_value_here) in front of format specifier in your case it would be something like this :
PHP код:
CMD:test(playeridparams[])
{
    new 
player;
       if(
sscanf(params"iu(-999)"params[0], player))// if playerid is not specified in command then 'player' will be equal to -999
     
{
        
SCM(playeridCOLOR_LABELS"/test [id test]");
        
SCM(playerid, -1"[ID test]: 1: test1 2: test2 3: test3");
        return 
1;
    }
    new 
helloworld;
    if(
params[0] < || params[1] > 3) return SendClientMessage(playerid, -1"Error option.");
    switch(
params[0]) {
        case 
1: {
            
            if(
player == -999)// if no user is specified
            
{
                
SCM(playeridCOLOR_LABELS"/test [id test] [player]");
                return 
1;
            }
           
// do other work here
        
}    
        case 
2helloworld++;
        case 
3helloworld++;
    }
    return 
1;

Reply
#4

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
In sscanf you make a parameter optional by adding (default_value_here) in front of format specifier in your case it would be something like this :
PHP код:
CMD:test(playeridparams[])
{
    new 
player;
       if(
sscanf(params"iu(-999)"params[0], player))// if playerid is not specified in command then 'player' will be equal to -999
     
{
        
SCM(playeridCOLOR_LABELS"/test [id test]");
        
SCM(playerid, -1"[ID test]: 1: test1 2: test2 3: test3");
        return 
1;
    }
    new 
helloworld;
    if(
params[0] < || params[1] > 3) return SendClientMessage(playerid, -1"Error option.");
    switch(
params[0]) {
        case 
1: {
            
            if(
player == -999)// if no user is specified
            
{
                
SCM(playeridCOLOR_LABELS"/test 1 [player]");
                return 
1;
            }
           
// do other work here
        
}    
        case 
2helloworld++;
        case 
3helloworld++;
    }
    return 
1;

Close, yes. But optional parameters are symbolised by a capital letter.

pawn Код:
CMD:test(playerid, params[])
{
    new selection, player;
    if(sscanf(params, "iU(-1)", selection, player))// if playerid is not specified in command then 'player' will be equal to -999
    {
        SCM(playerid, COLOR_LABELS, "/test [id test]");
        SCM(playerid, -1, "[ID test]: 1: test1 2: test2 3: test3");
        return 1;
    }
    new helloworld = 0;
    switch(selection)
    {
        case 1:
        {
            if(player == -1) return SCM(playerid, COLOR_LABELS, "/test [id test] [player]");
            // do other work here
        }
        case 2: helloworld++;
        case 3: helloworld++;
        default: SendClientMessage(playerid, -1, "Error option.");
    }
    return 1;
}
Reply
#5

Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)