Here's a good function that has always worked for me:
EDIT: put the function in and then use:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
return parseCommands(Message,ChatWnd);
}
code:
function parseCommands(sMessage,ChatWnd){
if (sMessage.charAt(0) == '/'){
if(sMessage.charAt(1) == '/'){
return sMessage;
} else {
var firstSpace = sMessage.search(' ');
if(firstSpace == -1){
var command = sMessage.toLowerCase().substr(1);
var params = '';
} else {
var command = sMessage.toLowerCase().substr(1, firstSpace-1);
var params = sMessage.toLowerCase().substr(firstSpace+1);
}
switch(command) {
case 'whatever':
//Do whatever here, but leave the next two lines. Add them to each case. They're important =)
sMessage = '';
break;
}
}
return sMessage;
}
}