How to replace a word
#1

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)
Reply
#2

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

if ( result != -1 )
[...]
Reply
#3

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;
}
Reply
#4

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;
}
Reply
#5

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..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)