View Single Post
  #1  
Old 04-30-2009, 11:56 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Clientside Swear Filter

As you may or may not know, I am one of the pioneers in removing foul language around Graal. I don't like to read it, I don't like to write it, I don't want to hear it, I don't want to see it.

However, I believe that people should have the choice as to whether or not they want to see the text or not.

So, I have devised a quick clientside swear filter for those of you who agree.

It probably needs to be improved in the future to run more efficiently, but this is a nice step in the right direction. You will still have to filter your PMs using the default graal rules.txt which is highly recommended, but now you can add a choice to whether or not the player wants to filter the swear words.

Here is the weapon script:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.swearwords = {
    {
"testing""*******"},
    {
"test2""*******"},
    {
"damn""****"}
  };
}

function 
onPlayerChats() {
  switch (
player.chat) {
    case 
"filteron":
      
client.swearfilter true;
      
player.chat "Swear filter is now on!";
    break;
    case 
"filteroff":
      
client.swearfilter false;
      
player.chat "Swear filter is now off.";
    break;
  }
}

function 
onRemotePlayerChats(objchat) {
  if (
client.swearfilter) {
    for (
temp.0temp.this.swearwords.size(); temp.++) {
      if (
obj.chat.pos(this.swearwords[temp.s][0]) >= 0) {
        
obj.chat replacetext(obj.chatthis.swearwords[temp.s][0], this.swearwords[temp.s][1]);
      } 
    }
  }
}

// edited version of my replacetext function in the code gallery
// http://forums.graalonline.com/forums/showthread.php?t=79538
// this one is not case sensitive
function replacetext(textoldtextnewtext) {
  
temp.oldlen   oldtext.length();
  
temp.textdiff newtext.length() - temp.oldlen;
  
  for (
temp.ptext.lower().positions(oldtext.lower())) {
    
temp.pos temp.temp.textdiff * (temp.index ++);
    
text text.substring(0temp.pos) @ newtext text.substring(temp.pos temp.oldlen);
  }
  
  return 
text;

As you can see, I added an example of how to turn on/off the sear filter by using the commands "filteron" and "filteroff."

I'd like to start seeing these sort of methods used around Graal to prevent foul language.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 12-06-2012 at 09:59 PM.. Reason: Edited the replacetext and also made it not case-sensitive.
Reply With Quote