Quite neat I must say.
I did a little edit to remove that timeout
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]);
}
}
}
}
// DustyPorViva's replacetext function.
function replacetext(txt,a,b) {
if (txt.pos(a)<0) return txt;
temp.txtpos = txt.positions(a);
temp.newtxt = txt.substring(0,txtpos[0]);
for (temp.i=0;i<txtpos.size();i++) {
newtxt @= b;
newtxt @= txt.substring(txtpos[i]+a.length(),txt.substring(txtpos[i]+a.length()).pos(a));
}
return newtxt;
}