Can't find mistake at command
#1

Hey I can't find where I did mistake at command.. the problem is I can write /accept "weed" and few other drug names

but for example if I write /accept cocaine it will say that drug name doesn't exist, why? here is code

pawn Код:
if(strcmp(cmd, "/accept", true) == 0)
    {
        new dname[6];
       
        strcat(dname, strtok(cmdtext, idx)); // [drugname]
        if(!dname[0])
        {
            SendClientMessage(playerid, -1, "{FF6A22}USAGE: {FFFFFF}/accept [drugname]");
            SendClientMessage(playerid, -1, "{FF6A22}Available names: {FFFFFF}Weed, Cocaine, Crack, Meth, Ecstasy, Heroin");
            return 1;
        }
       
        if(strcmp(dname,"weed",true) == 0)
        {
            if(DrugOffer[playerid][0] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Weed] += Gram[playerid];
                Pdrug[Offer[playerid]][Weed] -= Gram[playerid];
                DrugOffer[playerid][0] = 0;
           
                SendClientMessage(playerid, -1, "TEST");
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any weed.");
            }
        }
        else if(strcmp(dname,"cocaine",true) == 0)
        {
            if(DrugOffer[playerid][1] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Cocaine] += Gram[playerid];
                Pdrug[Offer[playerid]][Cocaine] -= Gram[playerid];
                DrugOffer[playerid][1] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any cocaine.");
            }
        }
        else if(strcmp(dname,"crack",true) == 0)
        {
            if(DrugOffer[playerid][2] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Crack] += Gram[playerid];
                Pdrug[Offer[playerid]][Crack] -= Gram[playerid];
                DrugOffer[playerid][2] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any crack.");
            }
        }
        else if(strcmp(dname,"meth",true) == 0)
        {
            if(DrugOffer[playerid][3] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Meth] += Gram[playerid];
                Pdrug[Offer[playerid]][Meth] -= Gram[playerid];
                DrugOffer[playerid][3] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any meth.");
            }
        }
        else if(strcmp(dname,"ecstasy",true) == 0)
        {
            if(DrugOffer[playerid][4] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Ecstasy] += Gram[playerid];
                Pdrug[Offer[playerid]][Ecstasy] -= Gram[playerid];
                DrugOffer[playerid][4] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any ecstasy.");
            }
        }
        else if(strcmp(dname,"heroin",true) == 0)
        {
            if(DrugOffer[playerid][5] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Heroin] += Gram[playerid];
                Pdrug[Offer[playerid]][Heroin] -= Gram[playerid];
                DrugOffer[playerid][5] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any heroin.");
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "{FF6A22}INFO:{FFFFFF} That drug name doesn't exist");
        }
        return 1;
    }
Reply
#2

Quote:
Originally Posted by Lajko1
Посмотреть сообщение
Hey I can't find where I did mistake at command.. the problem is I can write /accept "weed" and few other drug names

but for example if I write /accept cocaine it will say that drug name doesn't exist, why? here is code

pawn Код:
if(strcmp(cmd, "/accept", true) == 0)
    {
        new dname[6];
       
        strcat(dname, strtok(cmdtext, idx)); // [drugname]
        if(!dname[0])
        {
            SendClientMessage(playerid, -1, "{FF6A22}USAGE: {FFFFFF}/accept [drugname]");
            SendClientMessage(playerid, -1, "{FF6A22}Available names: {FFFFFF}Weed, Cocaine, Crack, Meth, Ecstasy, Heroin");
            return 1;
        }
       
        if(strcmp(dname,"weed",true) == 0)
        {
            if(DrugOffer[playerid][0] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Weed] += Gram[playerid];
                Pdrug[Offer[playerid]][Weed] -= Gram[playerid];
                DrugOffer[playerid][0] = 0;
           
                SendClientMessage(playerid, -1, "TEST");
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any weed.");
            }
        }
        else if(strcmp(dname,"cocaine",true) == 0)
        {
            if(DrugOffer[playerid][1] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Cocaine] += Gram[playerid];
                Pdrug[Offer[playerid]][Cocaine] -= Gram[playerid];
                DrugOffer[playerid][1] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any cocaine.");
            }
        }
        else if(strcmp(dname,"crack",true) == 0)
        {
            if(DrugOffer[playerid][2] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Crack] += Gram[playerid];
                Pdrug[Offer[playerid]][Crack] -= Gram[playerid];
                DrugOffer[playerid][2] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any crack.");
            }
        }
        else if(strcmp(dname,"meth",true) == 0)
        {
            if(DrugOffer[playerid][3] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Meth] += Gram[playerid];
                Pdrug[Offer[playerid]][Meth] -= Gram[playerid];
                DrugOffer[playerid][3] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any meth.");
            }
        }
        else if(strcmp(dname,"ecstasy",true) == 0)
        {
            if(DrugOffer[playerid][4] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Ecstasy] += Gram[playerid];
                Pdrug[Offer[playerid]][Ecstasy] -= Gram[playerid];
                DrugOffer[playerid][4] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any ecstasy.");
            }
        }
        else if(strcmp(dname,"heroin",true) == 0)
        {
            if(DrugOffer[playerid][5] == 1)
            {
                //GivePlayerMoney(Offer[playerid], Price[playerid]);
                GivePlayerMoney(playerid, -Price[playerid]);
                Pdrug[playerid][Heroin] += Gram[playerid];
                Pdrug[Offer[playerid]][Heroin] -= Gram[playerid];
                DrugOffer[playerid][5] = 0;
            }
            else
            {
                SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}No-one offered you any heroin.");
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "{FF6A22}INFO:{FFFFFF} That drug name doesn't exist");
        }
        return 1;
    }
Length for 'Cocaine' is too long for
pawn Код:
new dname[6];
[6] means 6 characters
pawn Код:
'C' 'o' 'c' 'a' 'i' 'n' 'e' '\0' -- 8 characters
Try changing
pawn Код:
new dname[6];
to
pawn Код:
new dname[9];
Reply
#3

Oh it's working, ty, I thought number at this means how many type of drugs are involved lol.. ty rep+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)