Again, nobody succeeded in giving the right code.
code:
//By Jimbodud
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 4)== "test"){
return'test1'
}
if (Message.substr(0, 4) == "cant"){
return'can't'
}
if (Message.substr(0, 4) == "dont"){
return'don't'
}
}
This code will only match if the word is in front, and will forget the rest of the message. Example: "cant do that" gives "can't" without the "do that".
code:
//By NanaFreak
var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(original[i],changed[i]);
}
return Message;
}
This code is better, only it's case-sensitive and it'll only replace one occurrence per array element. That's why markee was using RegExp's. So, the code which should do it:
code:
var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(RegExp(original[i], "gi"), changed[i]);
}
return Message;
}