Multi-Function Command Help
#1

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
}
Reply
#2

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
Reply
#3

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;
}
Reply
#4

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.
Reply
#5

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;
}
Reply
#6

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.
Reply
#7

Use ID's on the variable usage instead.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)