SA-MP Forums Archive
Question - 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: Question - Sscanf (/showthread.php?tid=602528)



Question - Sscanf - Unrea1 - 08.03.2016

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



Re: Question - Sscanf - TheHonnor - 08.03.2016

You can add more parameters with ZCMD..


Re: Question - Sscanf - BroZeus - 08.03.2016

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;




Re: Question - Sscanf - Threshold - 08.03.2016

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



Re: Question - Sscanf - Unrea1 - 09.03.2016

Thanks guys.