SA-MP Forums Archive
Multiple usage - 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: Multiple usage (/showthread.php?tid=614295)



Multiple usage - Ahmed21 - 06.08.2016

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?


Re: Multiple usage - Konstantinos - 06.08.2016

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;




Re: Multiple usage - Shinja - 06.08.2016

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;




Re: Multiple usage - Ahmed21 - 06.08.2016

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


Re: Multiple usage - Ahmed21 - 06.08.2016

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

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


Re: Multiple usage - Konstantinos - 06.08.2016

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