Bad word filter

Started by rulk, Oct 28, 2015, 04:04 PM

Previous topic - Next topic

rulk

No loops, no tokenizing strings, just a simple regex to filter bad/obscene words.

Note: To add new words just separate them with the 'pipe' symbol

function IsBadWord( string )
{
local res = regexp(@"(fuck|shit|cunt)" ).capture( string );

if ( res != null )
{
  return true;
}
else return false;
}


Example Usage

// Example Usage
function onPlayerChat( player, message )
{
// Convert to lower case to avoid case sensitivity
local string = message.tolower();

// If our string contains a bad word
if ( IsBadWord( string ) )
{
// Kick the player from the server.
KickPlayer( player );
}
}

Edit:  God damn code tags remove formatting - pastebin ver:
http://pastebin.com/raw.php?i=vGd5B3tm
We are all god's children.

KAKAN

1st of all, Nice work.
2nd. This one is better: http://forum.vc-mp.org/?topic=381.0
3rd. Your one is better in case of sensitivity.
oh no

Thijn

They both differ in what they do. This just detects them. S.L.C.'s version replaces them with asterisks.
So you can't really say one is better then the other. This one is great if you don't want bad words to be even said, so kick or warn them or just block the message altogether. S.L.C.'s version is for replacing the bad words with something else.

Just your preference which one to use.

rulk

Hya @KAKAN

I didn't notice that post, I was trying to accomplish the task without any loops or splitting strings or using 'string.find()',
I wanted to make it as simple as I could for new scripters to the community to understand.

I like @S.L.C's version and if scripters prefer to censor rather than to totally block bad language then they should use that version.

either way, they are both snippets that new scripters can hopefully learn from.

Kind regards,

rulk

Ps, thanks for the comments :-)

 
We are all god's children.

Cool

No error but when i add cKick( player ); giving error player does not exists
function cKick( p )
{
         KickPlayer( p );
SaveStats( p );
}

KAKAN

Where do you add that?
onScriptLoad?
If yes, then you've gone mad or sure.
oh no

Cool

Yes i added on scriptload no iam fine but that error come first time to me  :P

KAKAN

Do you have the player instance in onScriptLoad??
The function of onScriptLoad is function onScriptLoad(), as you can see there is no instance of player made.
You should use it on your chat function. :/
oh no

Cool

#8
Edit: kicking on any message

rulk

Sorry @Noob I should have provided you with a better example.

Here is a working example I have tested:

http://pastebin.com/raw.php?i=vGd5B3tm

Kind regards,

rulk

We are all god's children.

Cool