What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] Messenger.MyContacts.GetContact

[Help] Messenger.MyContacts.GetContact
Author: Message:
Red Blood
New Member
*


Posts: 3
Joined: Apr 2009
O.P. [Help] Messenger.MyContacts.GetContact
Hello, I'm new to this forum. I started scripting not to long ago and at the moment I'm at a stump. What I'm trying to do is when the user types something (EX:/Test) The user recieves a message BUT ONLY THAT USER.

my code is:

code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
    if(Message =="/Test"&&Messenger.MyContacts.GetContact("emails@hotmail.com")){
        var Message = "Testing";
        ChatWnd.SendMessage(Message);
        return '';
}
}

In my code the email address is different (Obviously) but anyways I can type /Test and it sends the messages but I can use the code on everyone not just that email. Help is appreciated.

04-15-2009 08:45 PM
Profile E-Mail PM Find Quote Report
ryxdp
Senior Member
****


Posts: 804
Reputation: 16
27 / Male / Flag
Joined: Jun 2006
RE: [Help] Messenger.MyContacts.GetContact
I'm pretty sure it's impossible to send a message in a group chat to only one person. Just open a new chat window with them ;)

Besides which, there are a few syntax errors here, I've fixed some stuff up for you. Not that it's going to be particularly useful if it is impossible.

JScript code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
    var exp=/\/Test\s(.*)/i //Regular expression of /Test email@domain.com
    if(exp.exec(Message!==null){ //If regexp matched message being sent
        var email=RegExp.$1 //Store the email for future use
        switch(email){ //Find out what the email is
            case 'email@hotmail.com': //If it's this one
                //Do stuff here
                return 'Testing'; //Send message
                break; //Stop the script here
            case 'jsmith@tardis.com': //Otherwise if it's this one
                //Do more stuff here
                return 'Testing2'; //Send a different message
                break; //Stop here
        }
    }
}


This post was edited on 04-15-2009 at 10:15 PM by ryxdp.
04-15-2009 10:14 PM
Profile PM Find Quote Report
Red Blood
New Member
*


Posts: 3
Joined: Apr 2009
O.P. RE: [Help] Messenger.MyContacts.GetContact
Hmm, ok thanks. But you see the reason for that was my "Main Plan" was to create a simple like text based Rpg and have like you could only roleplay with like that one msn account.
04-16-2009 01:06 AM
Profile E-Mail PM Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
RE: [Help] Messenger.MyContacts.GetContact
quote:
Originally posted by Red Blood
Hello, I'm new to this forum. I started scripting not to long ago and at the moment I'm at a stump. What I'm trying to do is when the user types something (EX:/Test) The user recieves a message BUT ONLY THAT USER.
Can you please try to explain in more detail what exactly you're doing... At the moment I've just written this code which probably isn't of any use. *-)
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    if (match = /^\/test (.*)/i.exec(Message))
    {
        var Email = match[1];
        if (Messenger.MyContacts.GetContact(Email))
            return "Test";
        else
            MsgPlus.DisplayToast("Error", Email + " is not on your contact list");
        return "";
    }
    return Message;
}
 
function OnGetScriptCommands()
{
    var SC = "<ScriptCommands>";
    SC += "<Command>";
    SC += "<Name>test</Name>";
    SC += "<Description>Test</Description>";
    SC += "</Command>";
    SC += "</ScriptCommands>";
    return SC;
}


Btw, I realise the code makes no real sense. I'm confused and it is late.

This post was edited on 04-16-2009 at 02:31 PM by davidpolitis.
04-16-2009 02:27 PM
Profile PM Find Quote Report
Red Blood
New Member
*


Posts: 3
Joined: Apr 2009
O.P. RE: [Help] Messenger.MyContacts.GetContact
^ "Hmm, ok thanks. But you see the reason for that was my "Main Plan" was to create a simple like text based Rpg and have like you could only roleplay with like that one msn account."

Alright like first I would make a new hotmail account Ex:Rpg1@hotmail.com (Just example) Then I want to make it so for example when you type /Test that code only works on Rpg1@hotmail.com and then it will have no effect if I try it on another email.

This post was edited on 04-16-2009 at 06:20 PM by Red Blood.
04-16-2009 06:20 PM
Profile E-Mail PM Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
36 / Male / Flag
Joined: Mar 2007
RE: RE: [Help] Messenger.MyContacts.GetContact
quote:
Originally posted by Red Blood
Alright like first I would make a new hotmail account Ex:Rpg1@hotmail.com (Just example) Then I want to make it so for example when you type /Test that code only works on Rpg1@hotmail.com and then it will have no effect if I try it on another email.

So you don't actually want to send a message to another player, you want it to just be the script works only on your DM account for instance?

If you were to set a variable for the DM then you could just use an if to do it.

code:
var DM = "rpg1@hotmail.com";

function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
  if ((Message =="/Test") && (Messenger.MyEmailAddress == DM))
  {
        var Message = "Testing";
        MsgPlus.DisplayToast("Alert", Message);
  }
}

Apologies for the bad code.  I'm a little rusty, but you get the gist and hopefully it'll help you out a bit.
[Image: adsig.jpg]
04-16-2009 08:48 PM
Profile E-Mail PM Web Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
RE: RE: RE: [Help] Messenger.MyContacts.GetContact
quote:
Originally posted by Leroux
Javascript code:
var DM = "rpg1@hotmail.com";
 
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
  if ((Message =="/Test") && (Messenger.MyEmailAddress == DM))
  {
        var Message = "Testing";
        MsgPlus.DisplayToast("Alert", Message);
  }
}

Apologies for the bad code.  I'm a little rusty, but you get the gist and hopefully it'll help you out a bit.
quote:
Return Value
A string containing the message to be sent instead of Message. If you do not want to modify the message, simply return Message without changing it. No size restriction applies to the new message except for the maximum size allowed by Messenger. If the event handler returns an empty string, the message is ignored and not sent to the server.
Problems:
1. You're setting the variable "Message", which is already set by OnEvent_ChatWndSendMessage
2. You aren't returning anything at the end of the event
3. Script commands should not start with an uppercase character (although they will still work)
4. Using OnGetScriptCommands(), along with our script command check, would be more suitable

Btw, I changed the one if to use two ifs so that "/test" isn't returned, causing a loop and script error, if the current user's email address is not the value of "DM". Also, "MyEmailAddress" is not a valid property of the Messenger object and was therefore changed to "MyEmail".

Javascript code:
var DM = "email@live.com"; // Change to the 'enabled' email address
 
function OnGetScriptCommands()
{
    var SC = "<ScriptCommands>";
    SC += "<Command>";
    SC += "<Name>test</Name>";
    SC += "<Description>Test</Description>";
    SC += "</Command>";
    SC += "</ScriptCommands>";
    return SC;
}
 
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    if (Message === "/test")
    {
        if (Messenger.MyEmail == DM)
        {
            var Msg = "Testing";
            MsgPlus.DisplayToast("Alert", Msg);
        }
        return "";
    }
    return Message;
}

P.S. hopefully what I said makes sense. Sorry if it doesn't.

This post was edited on 04-17-2009 at 08:18 AM by davidpolitis.
04-17-2009 12:24 AM
Profile 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