Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: rulk on Oct 28, 2015, 04:04 PM

Title: Bad word filter
Post by: rulk on Oct 28, 2015, 04:04 PM
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
Title: Re: Bad word filter
Post by: KAKAN on Oct 28, 2015, 05:43 PM
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.
Title: Re: Bad word filter
Post by: Thijn on Oct 28, 2015, 05:55 PM
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.
Title: Re: Bad word filter
Post by: rulk on Oct 28, 2015, 07:47 PM
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 :-)

 
Title: Re: Bad word filter
Post by: Cool on Oct 29, 2015, 10:16 AM
No error but when i add cKick( player ); giving error player does not exists
function cKick( p )
{
         KickPlayer( p );
SaveStats( p );
}
Title: Re: Bad word filter
Post by: KAKAN on Oct 29, 2015, 10:44 AM
Where do you add that?
onScriptLoad?
If yes, then you've gone mad or sure.
Title: Re: Bad word filter
Post by: Cool on Oct 29, 2015, 10:50 AM
Yes i added on scriptload no iam fine but that error come first time to me  :P
Title: Re: Bad word filter
Post by: KAKAN on Oct 29, 2015, 10:52 AM
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. :/
Title: Re: Bad word filter
Post by: Cool on Oct 29, 2015, 11:09 AM
Edit: kicking on any message
Title: Re: Bad word filter
Post by: rulk on Oct 29, 2015, 11:45 AM
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

Title: Re: Bad word filter
Post by: Cool on Oct 29, 2015, 11:52 AM
Thanks @rulk