SA-MP Forums Archive
[HELP] Replace 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: [HELP] Replace word (/showthread.php?tid=161575)



[HELP] Replace word - WThieves - 20.07.2010

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)"


Re: [HELP] Replace word - [XST]O_x - 20.07.2010

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



Re: [HELP] Replace word - WThieves - 20.07.2010

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


Re: [HELP] Replace word - Last_Stand_Guardian - 20.07.2010

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 ^^


Re: [HELP] Replace word - WThieves - 20.07.2010

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


Re: [HELP] Replace word - Tannz0rz - 20.07.2010

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



Re: [HELP] Replace word - WThieves - 20.07.2010

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


Re: [HELP] Replace word - WThieves - 20.07.2010

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)


Re: [HELP] Replace word - Tannz0rz - 20.07.2010

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.


Re: [HELP] Replace word - Brian_Furious - 20.07.2010

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