matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: How to make a menu and commands?
Menu functions:
js code: function OnGetScriptMenu(nLocation){
var oMenu = new ScriptMenu();
with (oMenu) {
AddSubMenu('My Menu'));
AddItem('/mycommand1', 'My Command without parameter');
AddItem('/mycommand1 5', 'My command with parameter');
AddSeperator();
AddItem('', 'Disabled item', false);
CloseSubMenu();
}
return oMenu.ExportMenu();
}
function OnEvent_MenuClicked(sMenuId, nLocation, oChatWnd){
OnEvent_ChatWndSendMessage(oChatWnd, sMenuId);
}
Command functions:
js code: function OnGetScriptCommands(){
var oCommand = new Commands();
with (oCommand) {
AddCommand('mycommand1', 'My command without parameter');
AddCommand('mycommand1', 'My command with parameter', 5);
}
return oCommand.ExportCommands();
}
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMenuId) !== null) {
var _command = RegExp.$1.toLowerCase();
var _param = RegExp.$2;
switch (_command) {
case 'mycommand':
if ( _param !== '' ) {
/*
Do stuff here
*/
} else {
/*
Do stuff here
*/
}
break;
}
}
}
Attachment: script classes.zip (1022 bytes)
This file has been downloaded 79 time(s).
This post was edited on 02-11-2009 at 03:18 PM by matty.
|
|