What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [request] turn a script on/ off for individual chats...

[request] turn a script on/ off for individual chats...
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [request] turn a script on/ off for individual chats...
Good, first of all: Welcome to the forums!

As for your question, you should think of how you want this to be done. Imagine which steps a script should take to get your desired result. Because you're new, I'll help you a bit.
  1. You should register the command using a ScriptCommands block in your ScriptInfo.xml file or by using OnGetScriptCommands. I'll assume the command would be "/mycommand " followed by "on" or "off".
  2. You should capture the event when the user sends the command.
  3. In that event, you should get a Contact object by checking if there's only one contact in the conversation and then get that object.
  4. You then should set and save the setting for that contact's email to on or off, depending on the parameter given.
So, in a script it could like like:
code:
//We need to store the settings somewhere, so I choose an array. This is very inefficient when you need to use them the next time you use Messenger.
var settings = new Array();
//Register the command
function OnGetScriptCommands() {
  var s = "<ScriptCommands>";
  s += "<Command>";
  s += "<Name>mycommand</Name>";
  s += "<Parameters>&lt;on|off&gt;</Parameters>";
  s += "<Description>Turn the script on or off for the current contact.</Description>";
  s += "</Command>";
  s += "</ScriptCommands>";
}

//The event!
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
  //Check if the message is our command
  //This is a regular expression, read more about these on MSDN

  if(/^\/mycommand\s([a-z]+)$/i.test(Message)) {
    //Make sure there are only two people in the chat (you and someone else)
    if(ChatWnd.Contacts.Count == 1) {
      //Get the contact!
      var Contact = new Enumerator(ChatWnd.Contacts).item();
      var Email = Contact.Email;
      //Save the setting
      //RegExp.$1 stores the first captured string in our command check (the thing between brackets)

      if(RegExp.$1 == "on" || RegExp.$1 == "true") settings[Email] = true;
      else settings[Email] = false;
      //End the event by returning nothing (otherwise Plus! gives an error)
      return "";
    } else return "";
  }
}
//Now you can add a function to load and save the settings, make the script function based on the per-contact settings and anytthing you like else...

And yes, the coloring took time... :dodgy:

This post was edited on 01-12-2007 at 08:01 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-12-2007 08:00 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[request] turn a script on/ off for individual chats... - by What? on 01-12-2007 at 07:31 PM
RE: [request] turn a script on/ off for individual chats... - by Matti on 01-12-2007 at 08:00 PM
RE: [request] turn a script on/ off for individual chats... - by pedro_cesar on 01-12-2007 at 08:05 PM
RE: [request] turn a script on/ off for individual chats... - by What? on 01-12-2007 at 08:10 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On