SA-MP Forums Archive
Help - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help (/showthread.php?tid=124965)



Help - (Jeff) - 01.02.2010

Код:
   	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?


Re: Help - MadeMan - 01.02.2010

Try using strtok

https://sampwiki.blast.hk/wiki/Strtok


Re: Help - (Jeff) - 05.02.2010

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


Re: Help - (Jeff) - 05.02.2010

can someone help its been 5 days



Re: Help - FireFox_ - 05.02.2010

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 */


Re: Help - (Jeff) - 05.02.2010

undefined symbol strlen


Re: Help - MadeMan - 05.02.2010

Not the very top, under #include <a_samp>


Re: Help - (Jeff) - 05.02.2010

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"


Re: Help - MadeMan - 05.02.2010

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;
}



Re: Help - Joe Staff - 05.02.2010

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

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