Multiple usage
#1

Hello, I want to make a command with more than one usage (syntax).

Example: if someone types "/h", a usage cmd is sent: /h [BUY/SELL/CONFIG/SELLPLAYER]

If he types "/h buy or sell or config" it shows him a dialog.

But if he types "/h sellplayer" he gets another usage message: /h sellplayer [player id] [Price]

How?
Reply
#2

PHP Code:
CMD:h(playeridparams[])
{
    if (!
strcmp(params"buy"true)) ShowPlayerDialog(...);
    else if (!
strcmp(params"sell"true)) ShowPlayerDialog(...);
    else if (!
strcmp(params"config"true)) ShowPlayerDialog(...);
    else if (!
strcmp(params"sellplayer "true10))
    {
        new 
idprice;
        if (
sscanf(params[10], "ri"idprice)) return SendClientMessage(playerid, -1"/h sellplayer [player id] [Price]");
      
        
// code..
    
}
    else 
SendClientMessage(playerid, -1"/h [BUY/SELL/CONFIG/SELLPLAYER]");
    return 
1;

Reply
#3

PHP Code:
CMD:h(playeridparams[])
{
    new 
tmp[50]
     if(
sscanf(params"s[5]"tmp)) return SendClientMessage(playerid, -1"{0008F7}USAGE: {FFFFFF}/H [BUY/SELL]");
    if(
strcmp(tmp"BUY") && strcmp(tmp"SELL")) return SendClientMessage(playerid, -1"{0008F7}USAGE: {FFFFFF}/H [BUY/SELL]");
    if(!
strcmp(tmp"BUY"))
    {
        
//buy
    
}
    if(!
strcmp(tmp"SELL"))
    {
        
//sell
    
}
    return 
1;

Reply
#4

Thanks both so much but Konstantinos one is more simple for me :P
Reply
#5

Question: At the "if strcmp params("sellplayer ", true)

I can see a space between the sellplayer and the ", is it needed?
Reply
#6

Yes, it is needed so it can separate the "option" with its parameters.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)