SA-MP Forums Archive
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: Problem. (/showthread.php?tid=361020)



Problem. - BaubaS - 19.07.2012

Hello again, I have a small problem with function which is detecting bad words in string, and if there is one, it changes the bad word letters to *. The problem is that in chat it works fine, but in commands - no. For example, I have command /classchat, the string is always null if I am using that function wheo formating.

pawn Код:
YCMD:classchat(playerid, params[], komandos)
{
    if (isnull(params))
    {
        return SendClientMessage(playerid, COLOR_RED, "» Komandos naudojimas: {FFFF00}/©lasschat [tekstas]");
    }
    new szRadio[128];
    format(szRadio, 128, "[RACIJA] %s %s (%d): {FF0000}%s", GetClassRang(playerid, iClass[playerid]), GetPlayerNameEx(playerid), playerid, >>>ChangeSwear(params)<<<);
    foreach(new i: Player)
    {
        if (iChannel[i] == iChannel[playerid])
        {
            SendClientMessage(i, COLOR_LIGHTBLUE, szRadio);
        }
    }
    return true;
}
If I am using this way, params is always null, I mean what ever you write (for e.g /classchat TEST), its always null!

But, if I do this way:

pawn Код:
YCMD:classchat(playerid, params[], komandos)
{
    if (isnull(params))
    {
        return SendClientMessage(playerid, COLOR_RED, "» Komandos naudojimas: {FFFF00}/©lasschat [tekstas]");
    }
    new szRadio[128];
    format(szRadio, 128, "[RACIJA] %s %s (%d): {FF0000}%s", GetClassRang(playerid, iClass[playerid]), GetPlayerNameEx(playerid), playerid, >>>params<<<);
    foreach(new i: Player)
    {
        if (iChannel[i] == iChannel[playerid])
        {
            SendClientMessage(i, COLOR_LIGHTBLUE, szRadio);
        }
    }
    return true;
}
Everything works fine then.

The function:

pawn Код:
stock ChangeSwear(Text[], Symbol = '*')
{
    new iWords = sizeof(BadWords), i;
    for (new BadWord; BadWord != iWords; ++BadWord)
    {
        while ((i = strfind(Text, BadWords[BadWord], true)) != -1)
        {
            for (new x = (i + strlen(BadWords[BadWord])); i != x; ++i)
            {
                Text[i] = Symbol;
            }
        }
    }
    return true;
}



Re: Problem. - nepstep - 19.07.2012

You are not returning the converted "params" on the function but "true".
Try:
pawn Код:
stock ChangeSwear(Text[], Symbol = '*')
{
    new iWords = sizeof(BadWords), i;
    for (new BadWord; BadWord != iWords; ++BadWord)
    {
        while ((i = strfind(Text, BadWords[BadWord], true)) != -1)
        {
            for (new x = (i + strlen(BadWords[BadWord])); i != x; ++i)
            {
                Text[i] = Symbol;
            }
        }
    }
    return Text;
}



Re: Problem. - BaubaS - 19.07.2012

I'll give a try later, thanks for fast reply


Re: Problem. - BaubaS - 19.07.2012

I tried your method, but its the same.


Re: Problem. - nepstep - 19.07.2012

Hmm put back the function to return true; instead of return Text;
And try this
pawn Код:
YCMD:classchat(playerid, params[], komandos)
{
    if (isnull(params))
    {
        return SendClientMessage(playerid, COLOR_RED, "» Komandos naudojimas: {FFFF00}/©lasschat [tekstas]");
    }
    new szRadio[128];
    ChangeSwear(params);
    format(szRadio, 128, "[RACIJA] %s %s (%d): {FF0000}%s", GetClassRang(playerid, iClass[playerid]), GetPlayerNameEx(playerid), playerid,params);
    foreach(new i: Player)
    {
        if (iChannel[i] == iChannel[playerid])
        {
            SendClientMessage(i, COLOR_LIGHTBLUE, szRadio);
        }
    }
    return true;
}