Shoutbox

Some big help I need - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Some big help I need (/showthread.php?tid=94969)

Some big help I need by SR01001010 on 07-08-2010 at 07:36 PM

On an event of someone signing in, how can I have it so it automatically opens a selected contact and says a certain thing? Eg:

// contact signs in

// if contact email = "myfriendexample135"hotmail.co.uk"
//{
//open window for chat with this person
ChatWnd.SendMessage("Hello mate!");
//}

Some help would be nice :D


RE: Some big help I need by matty on 07-08-2010 at 07:39 PM

js code:
function OnEvent_ContactSignin(sEmail) {
    // Make sure they are my friend
    if (sEmail === 'myfriendexample135@hotmail.co.uk') {
        // Make sure the contact isn't blocked
        if (Messenger.MyContacts.GetContact(sEmail).Blocked === false) {
            Messenger.OpenChat(sEmail).SendMessage('Hello mate!');
        }
    }
}

RE: Some big help I need by ultimatebuster on 07-09-2010 at 02:36 AM

or better yet

js code:
var CONTACTS = "johnsmith@hotmail.com, abcdefg@hotmail.com";

function OnEvent_Signin(Email){
    if (CONTACTS.indexOf(Email) != -1){
        if (!Messenger.MyContacts.GetContact(Email).Blocked) {
            Messenger.OpenChat(Email).SendMessage('Hi!);
        }
    }
}

RE: Some big help I need by whiz on 07-09-2010 at 08:12 AM

quote:
Originally posted by ultimatebuster
js code:
var CONTACTS = "johnsmith@hotmail.com, abcdefg@hotmail.com";

function OnEvent_Signin(Email){
    if (CONTACTS.indexOf(Email) != -1){
        if (!Messenger.MyContacts.GetContact(Email).Blocked) {
            Messenger.OpenChat(Email).SendMessage('Hi!);
        }
    }
}


If you want to check multiple contacts, you would be better off with an array.
js code:
var Contacts = ["johnsmith@hotmail.com", "abcdefg@hotmail.com"];

function OnEvent_Signin(Email)
{
    for (var X in Contacts)
    {
        if (Contacts[X] === Email)
        {
            if (!Messenger.MyContacts.GetContact(Email).Blocked)
            {
                Messenger.OpenChat(Email).SendMessage("Hi!");
            }
            break;
        }
    }
}

PS: you also seemed to miss the end quote for the sent message.  :)
quote:
Originally posted by ultimatebuster
js code:
Messenger.OpenChat(Email).SendMessage('Hi!);


RE: Some big help I need by Matti on 07-09-2010 at 12:55 PM

And if you want to improve even further upon that code snippet, you go for a fast numeric loop instead of a slower property enumeration loop.

js code:
var Contacts = ["johnsmith@hotmail.com", "abcdefg@hotmail.com"];

function OnEvent_Signin(Email)
{
>>>    for (var i=0, len=Contacts.length; i < len; ++i)<<<
    {
        if (Contacts[i] === Email)
        {
            // <snipped>
        }
    }
}
Or with a reverse while loop:
js code:
function OnEvent_Signin(Email)
{
>>>    var i = Contacts.length;<<<
>>>    while(i--)<<<
    {
        if (Contacts[i] === Email)
        {
            // <snipped>
        }
    }
}

RE: Some big help I need by SR01001010 on 07-09-2010 at 11:51 PM

Thankyou everyone I'll get on my project asap thanks again