parameters with strcmp
#6

Acutally, sscanf is a better way than strtok, your command will become like that using it

pawn Код:
#include <sscanf2>

public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[33], params[128];
    sscanf(cmdtext, "'/'s[33]s[128]", cmd, params);
    if(!strcmp(cmd, "selldrugs", true) || !strcmp(cmd, "sd", true))
    {
        new gpid, drugname[21], amount, price;
        if(sscanf(params, "us[21]dd", gpid, drugname, amount, price))
        {
            SendClientMessage(playerid, -1, "{FF6A22}USAGE: {FFFFFF}/selldrugs (/sd) [playerid] [drugname] [amount] [price]");
            return SendClientMessage(playerid, -1, "{FF6A22}Available names: {FFFFFF}Weed, Cocaine, Crack, Meth, Ectasy, Heroin");
        }
        if(!IsPlayerConnected(gpid)) return SendClientMessage(playerid, -1, "The player isn't connected !");
        if(ProxDetectorS(8.0, playerid, gpid))
        {
            if(!strcmp(drugname,"weed",true))
            {
                format(string, sizeof(string), "* You offered to sell %d grams of weed to %s for $%d, Wait for a reply.", needed, giveplayer, price);
                SendClientMessage(playerid, 0x33CCFFAA, string);
                //
                format(string, sizeof(string), "* %s wants to sell %d grams of weed to you for $%d, (type /acceptdrugs cocaine) to buy.", sendername, needed, price);
                SendClientMessage(gpid, 0x33CCFFAA, string);
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "{FF6A22}INFO:{FFFFFF} That player isn't enough close");
        }
        return 1;
    }
}
(If you wanna keep using the '/' in the command name, simply remove the " '/' " when you use the "sscanf" function on cmdtext)
Reply


Messages In This Thread
parameters with strcmp - by Lajko1 - 12.06.2014, 17:00
Re : parameters with strcmp - by S4t3K - 12.06.2014, 17:05
Re: parameters with strcmp - by TakeiT - 12.06.2014, 17:11
Re : parameters with strcmp - by S4t3K - 12.06.2014, 17:15
Re: parameters with strcmp - by Lajko1 - 12.06.2014, 17:43
Re : parameters with strcmp - by S4t3K - 12.06.2014, 18:01
Re: parameters with strcmp - by Lajko1 - 12.06.2014, 18:11
Re: parameters with strcmp - by Lajko1 - 12.06.2014, 21:45
Re: parameters with strcmp - by Jefff - 12.06.2014, 22:23
Re: parameters with strcmp - by Lajko1 - 13.06.2014, 05:09

Forum Jump:


Users browsing this thread: 3 Guest(s)