Tigairius |
04-30-2009 11:56 PM |
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(obj, chat) { if (client.swearfilter) { for (temp.s = 0; temp.s < this.swearwords.size(); temp.s ++) { if (obj.chat.pos(this.swearwords[temp.s][0]) >= 0) { obj.chat = replacetext(obj.chat, this.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(text, oldtext, newtext) { temp.oldlen = oldtext.length(); temp.textdiff = newtext.length() - temp.oldlen; for (temp.p: text.lower().positions(oldtext.lower())) { temp.pos = temp.p + temp.textdiff * (temp.index ++); text = text.substring(0, temp.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.
|