SA-MP Forums Archive
Simple command problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Simple command problem (/showthread.php?tid=365605)



Simple command problem - Makaveli93 - 03.08.2012

Whenever I type /smoke 1 or /smoke 2 or 3 in-game, I get an error message that it's an unknown command. I have /aim command that's made in the exactly the same way, and it works great. Can someone help me out please?

pawn Код:
if (strcmp("/smoke", cmdtext, true) == 0)
    {
        if(pCriticallyInjured[playerid] == 1) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Critically injured!");
        if(!IsPlayerInAnyVehicle(playerid))
        {
            if (!strlen(cmdtext[9])) return SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            switch (cmdtext[9])
            {
                case '1': ApplyAnimation(playerid,"SMOKING", "M_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '2': ApplyAnimation(playerid,"SMOKING", "F_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '3': ApplyAnimation(playerid,"SMOKING", "M_smkstnd_loop", 4.0, 1, 0, 0, 0, 0);
                default: SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Not possible in a vehicle.");
        }
        return 1;
    }



Re: Simple command problem - [MM]RoXoR[FS] - 03.08.2012

Try this

pawn Код:
if (strcmp("/smoke", cmdtext, true) == 0)
    {
        if(pCriticallyInjured[playerid] == 1) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Critically injured!");
        if(!IsPlayerInAnyVehicle(playerid))
        {
            new id;
            if(sscanf(cmdtext,"i",id)) return SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            switch (id)
            {
                case '1': ApplyAnimation(playerid,"SMOKING", "M_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '2': ApplyAnimation(playerid,"SMOKING", "F_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '3': ApplyAnimation(playerid,"SMOKING", "M_smkstnd_loop", 4.0, 1, 0, 0, 0, 0);
                default: SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Not possible in a vehicle.");
        }
        return 1;
    }
You will need sscanf


Re: Simple command problem - Makaveli93 - 03.08.2012

I don't use sscanf, I want to learn how to do it on the regular normal way. I used sscanf and zcmd before and I know it's easier.

Anyways, this is the command that WORKS:

pawn Код:
if(strcmp(cmd, "/aim", true) == 0)
    {
        if(pCriticallyInjured[playerid] == 1) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Critically injured!");
        if(!IsPlayerInAnyVehicle(playerid))
        {
            if (!strlen(cmdtext[5])) return SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /aim [1-3]");
            switch (cmdtext[5])
            {
                case '1': ApplyAnimation(playerid,"PED","gang_gunstand",4.0,0,1,1,1,1,1);
                case '2': ApplyAnimation(playerid,"PED","Driveby_L",4.0,0,1,1,1,1,1);
                case '3': ApplyAnimation(playerid,"PED","Driveby_R",4.0,0,1,1,1,1,1);
                default: SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /aim [1-3]");
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Not possible in a vehicle.");
        }
        return 1;
    }
And this is the command that DOESN'T WORK:

pawn Код:
if (strcmp("/smoke", cmdtext, true) == 0)
    {
        if(pCriticallyInjured[playerid] == 1) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Critically injured!");
        if(!IsPlayerInAnyVehicle(playerid))
        {
            if (!strlen(cmdtext[9])) return SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            switch (cmdtext[9])
            {
                case '1': ApplyAnimation(playerid,"SMOKING", "M_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '2': ApplyAnimation(playerid,"SMOKING", "F_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '3': ApplyAnimation(playerid,"SMOKING", "M_smkstnd_loop", 4.0, 1, 0, 0, 0, 0);
                default: SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Not possible in a vehicle.");
        }
        return 1;
    }
Now, I don't see what I did wrong here.


Re: Simple command problem - [MM]RoXoR[FS] - 03.08.2012

Hmm ok lets count

/smoke

pawn Код:
/ = 0
s = 1
m = 2
o = 3
k = 4
e = 5
space(   ) =6
1/2/3 =7
So, change your code to
pawn Код:
if (!strlen(cmdtext[7])) return SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            switch (cmdtext[7])



Re: Simple command problem - Makaveli93 - 03.08.2012

I tried it before, and now again, still doesn't works.


Re: Simple command problem - [MM]RoXoR[FS] - 03.08.2012

I wasted lot of time trying to fix this but failed, /smoke shows Unknown CMD, but /smoke 1/2/3 works
pawn Код:
if (strcmp(cmdtext,"/smoke", true,6) == 0)
    {
        if(pCriticallyInjured[playerid] == 1) return SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Critically injured!");
        if(!IsPlayerInAnyVehicle(playerid))
        {
            if (!cmdtext[7] || cmdtext[6] == '\0')
            {
                SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
                return 1;
            }
            switch (cmdtext[7])
            {
                case '1': ApplyAnimation(playerid,"SMOKING", "M_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '2': ApplyAnimation(playerid,"SMOKING", "F_smklean_loop", 4.0, 1, 0, 0, 0, 0);
                case '3': ApplyAnimation(playerid,"SMOKING", "M_smkstnd_loop", 4.0, 1, 0, 0, 0, 0);
                default: SendClientMessage(playerid,COLOR_USAGE,"[USAGE:] /smoke [1-3]");
            }

            return 1;
 
        }
        else
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Not possible in a vehicle.");
            return 1;
        }

        return 1;

    }