Command shows me the usage only?
#1

Hey folks,

here's the code:
pawn Код:
if(strcmp(cmd,"/materials",true)==0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pJob] != 1)
            {
                SendClientMessage(playerid,COLOR_LIGHTYELLOW2,"[ERROR:] Your not an arms dealer!");
                return 1;
            }
            new x_nr[256];
            x_nr = strtok(cmdtext, idx);
            if(!strlen(x_nr)) {
                SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /materials [usage]");
                SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGES:] buy, dropoff.");
                return 1;
            }
            if(strcmp(x_nr,"buy",true) == 0)
            {
                if(PlayerToPoint(3.0,playerid,GunJob[BuyPackagesX],GunJob[BuyPackagesY],GunJob[BuyPackagesZ]))
                {
                    if(MatsHolding[playerid] >= 10)
                    {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] You can't hold any more packages.");
                        return 1;
                    }
                   tmp = strtok2(cmdtext, idx);
                    if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /materials [usage]");
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGES:] buy, dropoff.");
                        return 1;
                    }
                    new moneys;
                    moneys = strval(tmp);
                    if(moneys < 1 || moneys > 10) { SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] Maximum number of packages is 10."); return 1; }
                    new price = moneys * 100;
                    if(GetPlayerCash(playerid) > price)
                    {
                        format(string, sizeof(string), "[INFO:] You got %d materials packages - Cost: $%d.", moneys, price);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        GivePlayerCash(playerid, - price);
                        MatsHolding[playerid] = moneys;
                    }
                    else
                    {
                        format(string, sizeof(string), "[ERROR:] You don't have $%d.", price);
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, string);
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] You are not at the materials package place!");
                    return 1;
                }
            }
            else if(strcmp(x_nr,"dropoff",true) == 0)
            {
                if(PlayerToPoint(3.0,playerid,GunJob[DeliverX],GunJob[DeliverY],GunJob[DeliverZ]))
                {
                    if(MatsHolding[playerid] > 0)
                    {
                        new payout = (50)*(MatsHolding[playerid]);
                        format(string, sizeof(string), "{INFO:] Materials packages delivered, you got %d materials.", payout);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        PlayerInfo[playerid][pMaterials] += payout;
                        MatsHolding[playerid] = 0;
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] You don't even have any packages!");
                        return 1;
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "{ERROR:] You are not at the materials dropoff place.");
                    return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] Invalid Usage.");
                return 1;
            }
        }
        return 1;
    }
The problem is it keeps spamming me this part:

pawn Код:
if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /materials [usage]");
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGES:] buy, dropoff.");
                        return 1;
                    }
How can I fix this? I cant get it.
Reply
#2

pawn Код:
tmp = strtok2(cmdtext, idx);
I don't know what this strtok2 function is, but you've been using strtok for the other one so why not use it again?

pawn Код:
tmp = strtok(cmdtext, idx);
Reply
#3

The same thing occurs, I had a one in the script before and named it strtok2, but it doesen't work still. Its not the problem.
Reply
#4

pawn Код:
if(!strlen(tmp))  ??? WTF YOU DID? - NOTHING!

if(strlen(tmp) == 0)
And i suggest you get rid of STRCMP+STRTOK and use ZCMD+SSCANF
Reply
#5

Didn't work and still keeps occuring. Any more solutions?
Reply
#6

pawn Код:
if(strcmp(cmd,"/materials",true)==0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pJob] != 1)
            {
                SendClientMessage(playerid,COLOR_LIGHTYELLOW2,"[ERROR:] Your not an arms dealer!");
                return 1;
            }
            new x_nr[256];
            x_nr = strtok(cmd, idx);
            if(strlen(x_nr) == 0) {
                SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /materials [usage]");
                SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGES:] buy, dropoff.");
                return 1;
            }
            if(strcmp(x_nr,"buy",true) == 0)
            {
                if(PlayerToPoint(3.0,playerid,GunJob[BuyPackagesX],GunJob[BuyPackagesY],GunJob[BuyPackagesZ]))
                {
                    if(MatsHolding[playerid] >= 10)
                    {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] You can't hold any more packages.");
                        return 1;
                    }
                   tmp = strtok2(cmd, idx);
                    if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /materials [usage]");
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGES:] buy, dropoff.");
                        return 1;
                    }
                    new moneys;
                    moneys = strval(tmp);
                    if(moneys < 1 || moneys > 10) { SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] Maximum number of packages is 10."); return 1; }
                    new price = moneys * 100;
                    if(GetPlayerCash(playerid) > price)
                    {
                        format(string, sizeof(string), "[INFO:] You got %d materials packages - Cost: $%d.", moneys, price);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        GivePlayerCash(playerid, - price);
                        MatsHolding[playerid] = moneys;
                    }
                    else
                    {
                        format(string, sizeof(string), "[ERROR:] You don't have $%d.", price);
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, string);
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] You are not at the materials package place!");
                    return 1;
                }
            }
            else if(strcmp(x_nr,"dropoff",true) == 0)
            {
                if(PlayerToPoint(3.0,playerid,GunJob[DeliverX],GunJob[DeliverY],GunJob[DeliverZ]))
                {
                    if(MatsHolding[playerid] > 0)
                    {
                        new payout = (50)*(MatsHolding[playerid]);
                        format(string, sizeof(string), "{INFO:] Materials packages delivered, you got %d materials.", payout);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        PlayerInfo[playerid][pMaterials] += payout;
                        MatsHolding[playerid] = 0;
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] You don't even have any packages!");
                        return 1;
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "{ERROR:] You are not at the materials dropoff place.");
                    return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ERROR:] Invalid Usage.");
                return 1;
            }
        }
        return 1;
    }
EDITED TRY AGAIN
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
pawn Код:
if(!strlen(tmp))  ??? WTF YOU DID? - NOTHING!

if(strlen(tmp) == 0)
And i suggest you get rid of STRCMP+STRTOK and use ZCMD+SSCANF
pawn Код:
if(!strlen(tmp))
if(strlen(tmp) == 0)
//are both the same things - it both means the same...
And as for the answer to the topic, it's probably a strcmp problem, but im on my phone at the moment so i cant test anything, sorry - ill have a proper look if this thread is still not answered by the time i get to my laptop.
Reply
#8

Is still NOT fixed, and needs more solutions!
Reply
#9

I noticed you used ERROR twice so i just edited my post again
(i think i fixed it now)
Reply
#10

You need to increase your "idx" variable before using strtok again. Try adding this bit of code before using strtok:
pawn Код:
idx++;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)