#1

Код:
   	if(strcmp(cmdtext, "/b", true, 3) == 0)
    {
    if(!cmdtext[3])return SendClientMessage(playerid, COLOR_RED, "USAGE: /b [text]");
    new str[128];
    GetPlayerName(playerid, str, sizeof(str));
    format(str, sizeof(str), "[%s]: %s", str, cmdtext[4]);
    SendLocalMessage(playerid, COLOR_PURPLE, 7, str);
    return 1;
    }
Doesn't work
Код:
   	if(strcmp(cmdtext, "/me", true, 3) == 0)
    {
    if(!cmdtext[3])return SendClientMessage(playerid, COLOR_RED, "USAGE: /me [text]");
    new str[128];
    GetPlayerName(playerid, str, sizeof(str));
    format(str, sizeof(str), "[%s]: %s", str, cmdtext[4]);
    SendLocalMessage(playerid, COLOR_PURPLE, 7, str);
    return 1;
    }
Works fine , its the same code but changed the /b to /me
why wont the /b work?
Reply
#2

Try using strtok

https://sampwiki.blast.hk/wiki/Strtok
Reply
#3

Quote:
Originally Posted by MadeMan
Did not help, I left the /me command as it is, edited the /b cmd but the /me works , /b still doesnt work
Reply
#4

can someone help its been 5 days
Reply
#5

pawn Код:
//Put at the top of your script
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new tmp[128], cmd[128], idx, name[MAX_PLAYER_NAME], string[128];
    cmd = strtok(cmdtext, idx);

    if(strcmp(cmd, "/b", true) == 0)
    {
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /b [text]");
    {
        GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "[%s]: %s", name, cmdtext);
    SendLocalMessage(playerid, COLOR_PURPLE, 7, string);
   
    }
    return 1;
    }
    return 0;
}
/* Untested Script */
Reply
#6

undefined symbol strlen
Reply
#7

Not the very top, under #include <a_samp>
Reply
#8

ok now it compiles, but when i type /l [text] it comes up with [Myname]: /l [text] e.g
my name = Noob
text = hi
it comes up with this:
"[Noob]: /l hi"
Reply
#9

Put this also to your script somewhere

pawn Код:
stock strrest(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
    new offset = index;
    new result[64];
    while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new tmp[128], cmd[128], idx, name[MAX_PLAYER_NAME], string[128];
    cmd = strtok(cmdtext, idx);
   
    if(strcmp(cmd, "/b", true) == 0)
    {
        tmp = strrest(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /b [text]");
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "[%s]: %s", name, tmp);
        SendLocalMessage(playerid, COLOR_PURPLE, 7, string);
        return 1;
    }
    return 0;
}
Reply
#10

http://forum.sa-mp.com/index.php?top...0464#msg900464

I hate strtok, and people who refer to it as useful
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)