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++; } }
CMD:test(playerid, params[])
{
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(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: {
if(player == -999)// if no user is specified
{
SCM(playerid, COLOR_LABELS, "/test [id test] [player]");
return 1;
}
// do other work here
}
case 2: helloworld++;
case 3: helloworld++;
}
return 1;
}
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(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;
}