SA-MP Forums Archive
How to replace a word - 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: How to replace a word (/showthread.php?tid=168557)



How to replace a word - Sascha - 16.08.2010

Hi...
I wanted to do something like:
if you write "fuck" it writes **** instead
like:

Code:
		if(strfind(text, "fuck", true) != -1){
			strdel(text, return, return+4);
			strins(text, "****", return);
		}
but I don't know how to get the returns
( i thought return replaces the pos where the "fuck" starts)


Re: How to replace a word - Slice - 16.08.2010

pawn Code:
result = strfind(text, "fuck", true);

if ( result != -1 )
[...]



Re: How to replace a word - (.Aztec); - 16.08.2010

pawn Code:
OnPlayerText(playerid, text[])
{
if(strcmp(text, "fuck", true) == 0) {
new string[128], playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, sizeof(string), "%s: ****", playerName);
SendClientMessageToAll(YOURCHATCOLOR, string); }
return 1;
}



Re: How to replace a word - bigcomfycouch - 16.08.2010

pawn Code:
new const BadWords[][] = {
    "shit",
    "fuck"
};

public OnPlayerText(playerid, text[])
{
    new placeholder;
    for(new i = 0; i < sizeof BadWords; i++)
    {
        placeholder = strfind(text, BadWords[i], true);
        if(placeholder != -1)
        {
            for(new x = placeholder; x < placeholder + strlen(BadWords[i]); x ++)
            {
                text[x] = '*';
            }
        }
    }
    return 1;
}



Re: How to replace a word - Sascha - 16.08.2010

Quote:
Originally Posted by (.Aztec);
View Post
pawn Code:
OnPlayerText(playerid, text[])
{
if(strcmp(text, "fuck", true) == 0) {
new string[128], playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, sizeof(string), "%s: ****", playerName);
SendClientMessageToAll(YOURCHATCOLOR, string); }
return 1;
}
that works only if I just write fuck... but I want it to work if I write "fuck you", too, etc..