Command and Parameters -
HidroDF - 02.01.2017
Hello, I'm trying to make a command with multiple parameters but, each case is different.
I'm creating the /ochat command and I need to use it with one or two parameters. There are two options: invite and close. The close parameter doesn't have any extra parameter just /ochat close and chat will close. But with invite I need to add a parameter (playerid) and I don't know how I can use first one parameter to detect where IF statement I have to go and then check if the player has entred a second parameter, in case of "invite".
I'm making this:
Код:
CMD:ochat(playerid, params[])
{
new param[10];
new id;
if(sscanf(params, "s", param)) SendClientMessage(playerid, -1, "Use: /ochat [invite | close]");
if(strmatch(param, "invite"))
{
if(sscanf(params, "sd", param, id)) return SendClientMessage(playerid, -1, "Use: /ochat invite playerid");
SendClientMessage("OK");
}
else if(strmatch(param, "close"))
{
SendClientMessage("CLOSE");
}
else
{
SendClientMessage(playerid, -1, "Options: invite + playerid or close");
}
return 1;
}
But don't work.
Anyone can help me? Thanks!
Respuesta: Command and Parameters -
HidroDF - 02.01.2017
Anyone?
Re: Respuesta: Command and Parameters -
CutX - 02.01.2017
//EDIT:
Quote:
Originally Posted by GoldenLion
not sure if you can do it with the player specifier like this: "U", but you should try.
|
as suggested by GoldenLion, use "U" instead of "I" i was too quick
----------------------------
Quote:
Originally Posted by HidroDF
Anyone?
|
PHP код:
CMD:ochat(playerid, params[])
{
new param[7],
id;
if(sscanf(params, "s[7]I(-1)", param,id)) return SendClientMessage(playerid, -1, "Use: /ochat [invite | close]");
if(!strcmp(param, "invite"))
{
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Use: /ochat invite playerid");
{
//do invite stuff here
}
}
else if(!strcmp(param, "close"))
{
//do close stuff here
}
else
SendClientMessage(playerid, -1, "Options: invite + playerid or close");
return 1;
}
visit the
sscanf thread to learn more about it
Re: Command and Parameters -
GoldenLion - 02.01.2017
You can use "D" or "I" for an optional integer, not sure if you can do it with the player specifier like this: "U", but you should try.
But this is what it would look like with an integer:
Код:
new item[10], playerid;
if (sscanf(params, "s[10]D(INVALID_PLAYER_ID)")) return SendClientMessage(playerid, -1 "usage...");
if (!strcmp(item, "invite"))
{
if (playerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1 "usage...");
//do whatever you want with the playerid here
}
else if (!strcmp(item, "close"))
{
//that closing stuff
}
EDIT: CutX was faster
Re: Command and Parameters -
Spmn - 02.01.2017
@GoldenLion, there's a little mistake in your code at sscanf part. INVALID_PLAYER_ID will get treated as a string, so you should have used a negative default ID as CutX did, or use the stringize operator:
Код:
if (sscanf(params, "s[10]D(" #INVALID_PLAYER_ID ")")) return SendClientMessage(playerid, -1 "usage...");
Re: Command and Parameters -
SickAttack - 02.01.2017
You should use strcmp with its length parameter to check what the first option is.
After that and a match was found, use sscanf with its ignore feature ("{s[7]}" - for your case) followed by other specifiers.
And you're pretty much set. The only con about this is that you will have to place the strcmp if-thens in a order where none conflict (e.g. helpme should go before help). You could avoid this tiny issue by using sscanf at the start (s[]s []), you'll have no use for the ignore feature however. Use the argument given by sscanf.