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:
What?
New Member
*


Posts: 4
Joined: Jan 2007
O.P. [request] turn a script on/ off for individual chats...
I'm new here, and new to the whole Scripts thing, so first up hello! But more importantly, I'm trying to write a script that can be turned on and off for individual contacts by typing a / command into the chat box.

I can get it to work individually using an variable turned on/off by sending the message but not for individual contacts.

I've only been using JScript a day (all I've done so far is picked up the very basics to make a script that changes my display name to a random quote of various people from an array every couple of minutes) so sorry if I'm a bit slow to pick this up. Any help would be appreciated.

Thank you. :D
01-12-2007 07:31 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / 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
pedro_cesar
Junior Member
**

Avatar

Posts: 61
35 / Male / –
Joined: Dec 2006
Status: Away
RE: [request] turn a script on/ off for individual chats...
u can do it by selecting the emails u want it to work for:


var e = new Enumerator(ChatWnd.Contacts);
    var Cnt = e.item();


now Cnt.Email stands for the Contact's (the one u typed command for) email, so for example u want it to work for somenone like: someone@somewhat.com u can use:

if (Cnt.Email == someone@somewhat.com) { do this }
01-12-2007 08:05 PM
Profile E-Mail PM Web Find Quote Report
What?
New Member
*


Posts: 4
Joined: Jan 2007
O.P. Happy  RE: [request] turn a script on/ off for individual chats...
oh wow! thanks you two :D
I want it to add the emails itself from the chat window so i'll try out Mattikes suggestion first. I'll probably mess it up though >.< lol!

edit:
That seems to work just finding various ways to check whether the message i received came from someone on the list- think i've got it though. Can't test for sure until I've found it.

Thanks again for all your help! :)

This post was edited on 01-12-2007 at 09:35 PM by What?.
01-12-2007 08:10 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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