SA-MP Forums Archive
Multi-Function Command Help - 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: Multi-Function Command Help (/showthread.php?tid=543603)



Multi-Function Command Help - DTV - 27.10.2014

I'm trying to make a command that when you type in /i(nventory), it will give you a prompt saying "Command Usage: /i [use/discard]"

However, I have no clue how to have the script detect when someone typed in "use" or "discard", at the moment, it just says "Command Usage: /i use [inventory slot]", no matter what I type in for /i

pawn Код:
CMD:i(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    new string[128], use[4], discard[8], slot, Float: HP;
    if(sscanf(params, "")) return SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
    if(!strcmp(use, "use"))
    {
          if(sscanf(params, "i", slot)) return SendClientMessage(playerid, -1, "Command Usage: /i use [inventory slot]");
It'd be real great if anyone could help me with this.
//Unneeded here
}


Re: Multi-Function Command Help - DavidBilla - 27.10.2014

pawn Код:
new choice[8];
if(sscanf(params,"s[8]",choice)) return SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
if(!strcmp(choice,"use",true,3)) //function
else if(!strcmp(choice,"discard",true,7)) //function



Re: Multi-Function Command Help - Jefff - 27.10.2014

pawn Код:
CMD:i(playerid, params[])
{
    new str[8];
    if(GetPVarInt(playerid, "LoggedIn") == 0) SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    else if(!(2 < strlen(params) < sizeof(str)) || sscanf(params,"s[8]",str)) SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
    else if(!strcmp(str, "use"))
    {
        new slot;
        if(sscanf(params, "{s[8]}i", slot)) SendClientMessage(playerid, -1, "Command Usage: /i use [inventory slot]");
        else{
        }
    }
    else if(!strcmp(str, "discard"))
    {

    }
    else
    {
        SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
    }
    return 1;
}



Re: Multi-Function Command Help - DTV - 27.10.2014

Quote:
Originally Posted by DavidBilla
Посмотреть сообщение
pawn Код:
new choice[8];
if(sscanf(params,"s[8]",choice)) return SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
if(!strcmp(choice,"use",true,3)) //function
else if(!strcmp(choice,"discard",true,7)) //function
This helped, but now the script can't detect that I'm entering a value for "slot", so it just brings "Command Usage: /i use [inventory slot] back up.


Re: Multi-Function Command Help - Quickie - 28.10.2014

pawn Код:
CMD:i(playerid,params[])
{
    new usage[20],slot;
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    if(isnull(params))  return SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
    if(sscanf(params,"s[15]i",usage,slot) return SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
    if(!strcmp(usage,"use",true)
    {
        //your command for the use parameter
        //remember ur value of the inventory slot is slot
    }
    else if(!strcmp(usage,"discard",true)
    {
   
            //your command for the discard param
            //remember ur value of the inventory slot is the slot variable
    }
    else
    {
        return SendClientMessage(playerid, -1, "Command Usage: /i [use/discard]");
    }
    return 1;
}



Re: Multi-Function Command Help - DavidBilla - 28.10.2014

Then the solution is already here.
Using Quickie's code will check for 2 params in the beginning itself and won't respond to /i discard, properly.
But the code that Jeff has posted will do exactly what you wanted.
The {} in the sscanf code is called quiet section and will read the value but will not store it in a variable which actually fulfills your purpose.
Read ******' sscanf documentation to know more about it.


Re: Multi-Function Command Help - Metroplex - 28.10.2014

Use ID's on the variable usage instead.