command to heal doesn't work
#1

Hi, I created this command and everything seems ok to me but everytime I /coke adding a number (like /coke 1) I got SERVER:Unknown command

Example:
>I write "/coke" I got "USAGE: /coke [grams]"
but
>I write "/coke + smth" I got "Server Unknown command"

pawn Код:
if (strcmp("/coke", cmdtext, true, 10) == 0)
     {
        tmp = strtok(cmdtext, idx);
        new cgramme;
        cgramme = strval(tmp);

    if(logged[playerid] == 0)
    {
    SendClientMessage(playerid, COLOR_BRIGHTRED, "Must be logged in!");
    return 1;
    }

        if(Spawned[playerid] == 0)
     {
    SendClientMessage(playerid, COLOR_BRIGHTRED, "Must be spawned");
      return 1;
     }
        if(coke[playerid] < 1)
       {
    SendClientMessage(playerid, COLOR_BRIGHTRED, "You have no coke.");
       return 1;
       }
        if(!strlen(tmp))
      {
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /coke [grammes]");
        return 1;
      }
     if (possiblecoke[playerid] == 1)
   {
     if(cgramme < 0 || cgramme > 3)
      {
      SendClientMessage(playerid, COLOR_BRIGHTRED, "You can only take between 1 and 3 grams of coke.");
      return 1;
      }
     if(cgramme == 0)
       {
      SendClientMessage(playerid, COLOR_BRIGHTRED, "You must take at least 1 gram.");
      return 1;
       }
     if(cgramme == 1)
       {
     SetTimerEx("ungCoke", 1000, true, "i", playerid);
     SetTimerEx("fincoke", 20000, false, "i", playerid);
     SetTimerEx("cokepossible", 60000, false, "i", playerid);
     SendClientMessage(playerid, COLOR_LIGHTBLUE, "You took 1g of cocaпne, your health restores slowly.");
     possiblecoke[playerid]=0;
     return 1;
       }
     if(cgramme == 2)
       {
     SetTimerEx("deuxgCoke", 700, true, "i", playerid);
     SetTimerEx("fincoke", 20000, false, "i", playerid);
     SetTimerEx("possiblecoke", 60000, false, "i", playerid);
     SendClientMessage(playerid, COLOR_LIGHTBLUE, "You took 2g of cocaпne, your health restores gradually.");
     possiblecoke[playerid]=0;
     return 1;
       }
     if(cgramme == 3)
       {
     SetTimerEx("troisgCoke", 500, true, "i", playerid);
     SetTimerEx("fincoke", 20000, false, "i", playerid);
     SetTimerEx("possiblecoke", 60000, false, "i", playerid);
     SendClientMessage(playerid, COLOR_LIGHTBLUE, "You took 3g of cocaпne, your health restores faster.");
     possiblecoke[playerid]=0;
     return 1;
       }
    }
     else
     {
     SendClientMessage(playerid, COLOR_BRIGHTRED, "You must wait one minut between each take!");
     return 1;
     }
    return 1;
  }
Where is the mistake?
Reply
#2

Dude, first thing, learn to use zcmd and sscanf cmds
Reply
#3

I'd like to, but everytime I put zcmd or sscanf include I got shittone of errors.
Reply
#4

First of all, you should start using zcmd or Pawn.CMD (my most recommended processors)

The problem is with the length parameter in strcmp.
You're comparing the first 10 characters of the command.

So it checks if the characters you enter (from 0 to 9) are equal to "/coke"

Change the 10 to 5 (The number of characters "/coke" has)

Код:
if (strcmp("/coke", cmdtext, true, 10) == 0)
-- becomes:
if (strcmp("/coke", cmdtext, true, 5) == 0)
Reply
#5

Thank you it works, and I'll try to start using zcmd.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)