Aaah... here's where regular expressions can help.
I'll try to simplify it for you, since I guess you've never worked with those.
code:
var myCommand = "myscriptcmd"; //This is the name of your command! Please don't use any special characters to avoid problems with the regular expression
var myCommandDesc = "My first script command!"; //Here you can add a description for your command which will be shown in the shortcut menu when you press "/"
//Register our command
function OnGetScriptCommands() {
var s = "<ScriptCommands>";
s += "<Command>";
s += "<Name>"+myCommand+"</Name>";
s += "<Description>"+myCommandDesc+"</Description>";
s += "<Parameters><message></Parameters>";
s += "</Command>";
s += "</ScriptCommands>";
return s;
}
//The send event!
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
var reCheck = MakeRegExp(myCommand); //Get a regular expression
if(reCheck.test(Message)) { //Checks if the message is our command
var Param = RegExp.$1; //This thing is where the captured parameter is stored
Message = MyFunction(Param); //Change this to your function name, and eventually add other parameters to it.
}
return Message;
}
//A simple function to create a regular expression
function MakeRegExp(str) {
return new RegExp("/^\/"+str+"\s(.+)$", "i");
}
//An example function. Note that you always have to return something to be sent as replacement for the original message. If you want it to stop sending a message (eg if you want the command to only open a window), just return an empty string. (return "")
function MyFunction(Param) {
var newMsg = "[c=4]"+Param+"[/c]";
return newMsg;
}
Note: this code is not tested. It's possible that something wasn't noticed while I reviewed my post. If so, please let me know (or you can try to fix it yourself of course)!