Weird command issue
#1

I'm not the best at SA-MP scripting and i'm coding a server from scratch to train my skills and build my community up.

pawn Код:
if(!strcmp(cmdtext, "/b", true, 3))
    {
        if(!cmdtext[2])return SendClientMessage(playerid, COLOR_ERRORRED, "USAGE: /b [ooc chat]");

        new str[128];
        GetPlayerName(playerid, str, sizeof(str));
        format(str, sizeof(str), "(( %s: %s ))", str, cmdtext[3]);
       
        ProxDetector(10.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);

        return 1;
    }
When I type /b text it works properly, but when I type /ban userid reason it will show up like this:

(( Jonty: an 1 noob ))

So, it's using the /b not the /ban

Can anyone help?
Reply
#2

Yes, because it finds in /ban the /b. So I recommend you to use a proper command processor. Like ZCMD, or DCMD.
Reply
#3

I don't like ZCMD or DCMD
Reply
#4

change if(!strcmp(cmdtext, "/b", true, 3))
to
if(!strcmp(cmdtext, "/b", true, 10))
see if it works
Reply
#5

pawn Код:
if(!strcmp(cmdtext, "/b", true, 2))// Here it must be 2 cause there is not 3 words (Ex: /=> 1, b=> 2)
    {
        if(!cmdtext[2])return SendClientMessage(playerid, COLOR_ERRORRED, "USAGE: /b [ooc chat]");

        new str[128];
        GetPlayerName(playerid, str, sizeof(str));
        format(str, sizeof(str), "(( %s: %s ))", str, cmdtext[3]);
       
        ProxDetector(10.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);

        return 1;
    }
Reply
#6

Quote:
Originally Posted by Naruto_Emilio
Посмотреть сообщение
pawn Код:
if(!strcmp(cmdtext, "/b", true, 2))// Here it must be 2 cause there is not 3 words (Ex: /=> 1, b=> 2)
    {
        if(!cmdtext[2])return SendClientMessage(playerid, COLOR_ERRORRED, "USAGE: /b [ooc chat]");

        new str[128];
        GetPlayerName(playerid, str, sizeof(str));
        format(str, sizeof(str), "(( %s: %s ))", str, cmdtext[3]);
       
        ProxDetector(10.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);

        return 1;
    }
yeah but then if you have a command starting with /b like
Example
/bike the command /b will be run because you put it as
true, 2 that means anything starting with /b will be recognized as the /b command if you see what i mean correct me if im wrong
Reply
#7

The 3 in that line should be a 2 since /b is 2 characters, not 3.

/ban should be 4 because it has 4 characters. Yes, a forward slash (/) counts as one of the characters in pawn.

Tell me if it works.
Reply
#8

Quote:
Originally Posted by grand.Theft.Otto
Посмотреть сообщение
The 3 in that line should be a 2 since /b is 2 characters, not 3.

/ban should be 4 because it has 4 characters. Yes, a forward slash (/) counts as one of the characters in pawn.

Tell me if it works.
Same issue

Does anyone want to help me convert my script to DCMD tonight? I'll be out during the day and this could bring you into my project which is sure to be big...
Reply
#9

I'll convert your /b command for you:

pawn Код:
// top of script

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

// OnPlayerCommandText

dcmd(b,1,cmdtext) // b = command name 1 = command length cmdtext = not 100% sure what it is lol

// bottom of script

dcmd_b(playerid,params[])
{
    if(!strlen(params))  return SendClientMessage(playerid, COLOR_ERRORRED, "USAGE: /b [ooc chat]");
       
    new str[128];
    GetPlayerName(playerid, str, sizeof(str));
    format(str, sizeof(str), "(( %s: %s ))", str, cmdtext[3]);      
    ProxDetector(10.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
    return 1;
}
Reply
#10

thanks, i've now rewritten my whole script. thanks for doing that it has helped me learn a much better command handler.

<3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)