So far, you have your ChatWnd function:
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
return "< " + Message + " >";
}
Firstly, we need a variable to store whether the script is enabled or not.
Javascript code:
var Enabled = false; // disabled by default
This should be global (outside of any function), so put it at the top.
We then need to modify the message function so it only occurs if the variable is true (enabled).
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
if (Enabled)
{
return "< " + Message + " >";
}
}
The script menu is written in XML, and Plus! calls the event
OnGetScriptMenu() when it is opened.
Javascript code:
function OnGetScriptMenu()
{
// return the menu
}
The script menu should take this format:
XML code:
<ScriptMenu>
<MenuEntry Id="ItemID1">Displayed name...</MenuEntry>
<MenuEntry Id="ItemID2" Enabled="false">Disabled item...</MenuEntry>
<Separator/>
<SubMenu Label="I'm a sub-menu!">
<MenuEntry Id="ItemID3">Another item...</MenuEntry>
</SubMenu>
</ScriptMenu>
To make the menu, we return this as a string. Your menu will need one option, to enable or disable the script. We can change the text based on whether the script is enabled or not.
Javascript code:
function OnGetScriptMenu()
{
var ScriptMenu = "<ScriptMenu>";
if (Enabled)
{
ScriptMenu += "<MenuEntry Id=\"Toggle\">Disable</MenuEntry>";
}
else
{
ScriptMenu += "<MenuEntry Id=\"Toggle\">Enable</MenuEntry>";
// note the use of the same ID
}
ScriptMenu += "</ScriptMenu>";
return ScriptMenu;
}
To check and process menu clicks, use the
OnEvent_MenuClicked() function:
Javascript code:
function OnEvent_MenuClicked(MenuEntryId, Location, OriginWnd)
{
if (MenuEntryId === "Toggle")
{
Enabled = !Enabled; // invert the value
}
}
And so, the finished script:
Javascript code:
var Enabled = false;
function OnGetScriptMenu()
{
var ScriptMenu = "<ScriptMenu>";
if (Enabled)
{
ScriptMenu += "<MenuEntry Id=\"Toggle\">Disable</MenuEntry>";
}
else
{
ScriptMenu += "<MenuEntry Id=\"Toggle\">Enable</MenuEntry>";
}
ScriptMenu += "</ScriptMenu>";
return ScriptMenu;
}
function OnEvent_MenuClicked(MenuEntryId, Location, OriginWnd)
{
if (MenuEntryId === "Toggle")
{
Enabled = !Enabled;
}
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
if (Enabled)
{
return "< " + Message + " >";
}
}