Unknown Command
#1

So i am trying to make a inventory system for my GM from scratch but the problem is i finished the command but when i try to test it ingame it doesn't work at all.

here is the code
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/i use", true))
    {
        new itemslot,string[128];
        if(sscanf(cmdtext,"i",itemslot))
        {
           SendClientMessage(playerid,-1,"USAGE: /i use (itemslot).");
           return 1;
        }
        if(itemslot == 1)
        {
           itemslot = pInfo[playerid][pInv1];
           if(pInfo[playerid][pInv1] == 995)
           {
              SendClientMessage(playerid,-1,"The command works");
           }
           return 1;
        }
        return 1;
    }
    return 0;
}
Reply
#2

pawn Код:
if(strcmp(cmdtext, "/i use", true))
If the strings are the same, strcmp returns 0. What you do is call the command if the returned value is 1.
Try
pawn Код:
if(!strcmp(cmdtext, "/i use", true))
    //rest
Placing a '!' before strcmp should work.

OR

You can place a == 0 behind it. It would look like this

pawn Код:
if (strcmp("/i use", cmdtext, true) == 0)
 //rest
I hope this helps you further
Reply
#3

I think you can't put a space in a command so try this?

pawn Код:
if(strcmp(cmdtext, "/i", true))
    {
        new var[5];
        if(strcmp(var,"use",true) == 0)
        {
            // Code here
        }
    }
Reply
#4

i converted my command to ZCMD but when i type the command correct the sscanf always says the usage even if its correct.

pawn Код:
CMD:i(playerid,params[])
{
        new itemslot,string[128];
        new var[5];
        if(strcmp(var,"use",true) == 0)
        {
            if(sscanf(params,"i",itemslot))
            {
               SendClientMessage(playerid,-1,"USAGE: /i use (itemslot).");
               return 1;
            }
            if(itemslot == 1)
            {
               itemslot = pInfo[playerid][pInv1];
               if(pInfo[playerid][pInv1] == 995)
               {
                  SendClientMessage(playerid,-1,"The command works");
               }
               return 1;
            }
            return 1;
        }
        return 1;
}
Reply
#5

pawn Код:
CMD:i(playerid,params[])
{
    new option[4], itemslot; // if you add more options with more characters on them, make the size of the array longer
    if (sscanf(params, "s[4]i", option, itemslot)) return SendClientMessage(playerid, -1, "USAGE: /i use (itemslot).");
    if (!strcmp(option, "use", true))
    {
        if (itemslot == 1)
        {
            if(pInfo[playerid][pInv1] == 995)
            {
                SendClientMessage(playerid, -1, "The command works");
            }
        }
    }
    else SendClientMessage(playerid, -1, "Available options: use");
    return 1;
}
Reply
#6

Works thank you so much +1 to all who contributed their time.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)