[HELP] Replace word
#1

Hi there, i need your help i've got this
pawn Code:
if (strfind(text, "idiot") != -1)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        SetTimer("Botanswer3",500,false);
        //SendChat(string);
    }
Now if someone says idiot, you get an answer in half a second, BUT the word idiot still displays, and thats what i want to be replaced, i want idiot replaced by (censored) so if you say "you idiot" you get "you (censored)"
Reply
#2

pawn Code:
if (strfind(text, "idiot") != -1)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        SetTimer("Botanswer3",500,false);
        //SendChat(string);
        return 0;
    }
Reply
#3

Quote:
Originally Posted by [XST]O_x
View Post
pawn Code:
if (strfind(text, "idiot") != -1)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        SetTimer("Botanswer3",500,false);
        //SendChat(string);
        return 0;
    }
Errrm this just makes you unable to say any sentence with idiot in it, thats like 0.001% of what i wanted and i could do that myself if i needed that.

lets say it again then, i want that if you say 'you are an idiot' you get 'you are an (censored)' and not ____ .
Reply
#4

Try:
pawn Code:
public OnPlayerText(playerid, text[])
{
      if(strfind(text, "idiot") != -1)
      {
            new Position = strfind(text, "idiot", true);
            strdel(text, Position, Position+5);
            strins(text, "censored", Position, 10);
            SendPlayerMessageToAll(playerid, text);
            return 0;
      }
}
return 1;
I'm not sure if it works, but it could look like this xD ^^
Reply
#5

Quote:
Originally Posted by Last_Stand_Guardian
View Post
Try:
pawn Code:
public OnPlayerText(playerid, text[])
{
      if(strfind(text, "idiot") != -1)
      {
            new Position = strfind(text, "idiot", true);
            strdel(text, Position, Position+5);
            strins(text, "censored", Position, 10);
            SendPlayerMessageToAll(playerid, text);
            return 0;
      }
}
return 1;
I'm not sure if it works, but it could look like this xD ^^
I'll try
Reply
#6

Not entirely sure how OnPlayerText works regarding the sending of the messages and whatnot, but here's a quick filtering method I just whipped up:
Code:
new
	badwords[4][16] =
	{
	    { "idiot\0" 	},
	    { "stupid\0" 	},
		{ "asshole\0" 	},
		{ "fuck\0" 		}
	};

public OnPlayerText(playerid, text[])
{
	new
	    i,
	    j,
		sub;
	    
	for(; i < 4; ++i)
		if((sub = strfind(text, badwords[i], true)) != -1)
			for(; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
			    if(text[sub] == badwords[i][j])
			    {
			        strdel(text, sub, sub + 1);
			        strins(text, "*", sub);
		        }
	    
	return 1;
}
Reply
#7

Quote:
Originally Posted by Tannz0rz
View Post
Not entirely sure how OnPlayerText works regarding the sending of the messages and whatnot, but here's a quick filtering method I just whipped up:
Code:
new
	badwords[4][16] =
	{
	    { "idiot\0" 	},
	    { "stupid\0" 	},
		{ "asshole\0" 	},
		{ "fuck\0" 		}
	};

public OnPlayerText(playerid, text[])
{
	new
	    i,
	    j,
		sub;
	    
	for(; i < 4; ++i)
		if((sub = strfind(text, badwords[i], true)) != -1)
			for(; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
			    if(text[sub] == badwords[i][j])
			    {
			        strdel(text, sub, sub + 1);
			        strins(text, "*", sub);
		        }
	    
	return 1;
}
This sounds good but how can i add more than 4 words, cause i get initialisation data exceeds declared size
Reply
#8

Quote:
Originally Posted by WThieves
View Post
This sounds good but how can i add more than 4 words, cause i get initialisation data exceeds declared size
Not working either (sorry 4 dub post)
Reply
#9

Quote:
Originally Posted by WThieves
View Post
Not working either (sorry 4 dub post)
The filtering of strings works fine, I just haven't tested it with OnPlayerText.

Try this:
Code:
#define MAX_BADWORDS 4

new
	badwords[MAX_BADWORDS][16] =
	{
	    { "idiot\0" 	},
	    { "stupid\0" 	},
		{ "asshole\0" 	},
		{ "fuck\0" 		}
	};

public OnPlayerText(playerid, text[])
{
	new
	    i,
	    j,
		sub;

	for(; i < MAX_BADWORDS; ++i)
		if((sub = strfind(text, badwords[i], true)) != -1)
			for(j = 0; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
			    if(	text[sub] == badwords[i][j] ||
					text[sub] == (badwords[i][j] - 32))
			    {
			        strdel(text, sub, sub + 1);
			        strins(text, "*", sub, strlen(text));
		        }

 	return 1;
}
Just change MAX_BADWORDS to the total number of badwords, and just add your words to the array appropriately like I did with the other ones.
Reply
#10

Quote:
Originally Posted by Tannz0rz
View Post
The filtering of strings works fine, I just haven't tested it with OnPlayerText.

Try this:
Code:
#define MAX_BADWORDS 4

new
	badwords[MAX_BADWORDS][16] =
	{
	    { "idiot\0" 	},
	    { "stupid\0" 	},
		{ "asshole\0" 	},
		{ "fuck\0" 		}
	};

public OnPlayerText(playerid, text[])
{
	new
	    i,
	    j,
		sub;

	for(; i < MAX_BADWORDS; ++i)
		if((sub = strfind(text, badwords[i], true)) != -1)
			for(j = 0; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
			    if(	text[sub] == badwords[i][j] ||
					text[sub] == (badwords[i][j] - 32))
			    {
			        strdel(text, sub, sub + 1);
			        strins(text, "*", sub, strlen(text));
		        }

 	return 1;
}
Just change MAX_BADWORDS to the total number of badwords, and just add your words to the array appropriately like I did with the other ones.
i really like it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)