What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Creating a Command?

Creating a Command?
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Creating a Command?
quote:
Originally posted by Samo502
It works now to a point, it brings up my command in the list but when I hit enter it says it isn't a command.
That's because you need to tell Messenger Plus! that you've actually processed the command. Otherwise it will think there wasn't any script which processed it and thus will show you the error.
(note that this behaviour only occurs with text strings starting with / , thus so called 'commands')

Remember that many scripts can run at the same time. So, if one of those scripts processes a specific command, you need to tell Plus! that. Otherwise it simple launches the next OnEvent_ChatWndSendMessage function from the next script until there are no OnEvent_ChatWndSendMessage functions anymore.

Not telling Plus! that you've processed the command is the same as ignoring it and thus the same as not processing it as far as Plus! is concearned. And thus Plus! will think there is no such command.

Now, to tell Plus! that you have processed the command (or text line for that manner), you simply end your processing by returning the string you want to see in place of the entered string/command.

If you simply want the command string to do something without actually sending the command string to your contact you return with an empty string:
    Return ""

If you want the command string to be replaced by another string and then be send to your contact, you return with the new string:
    Return "I just entered a command"

Returning with a string (even if it is empty) will tell Plus! that your script has processed the recieved text line and thus 'accepted' the command in case it was a command.

Also all explained in the Scripting Docs > Index > OnEvent_ChatWndSendMessage
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.



;)

jscript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    if (Message.toLowerCase() == "/dispc")
    {
        for(var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext())
        {
            var Contact = e.item();
            var status = Contact.Status;
            switch(status)
            {
                case 1:
                case 2:
                    status = "Offline";
                    break;
                case 3:
                    status = "Online";
                    break;
...
...
                case 9:
                    status = "Eating";
                    break;
            }
            if(status == "Online")
            {
                ChatWnd.SendMessage("[N]" + Contact.Name + " is " + status + "[/N]");
            }
        }
    Return "";
    }
}
PS: - note that this code can be simplified a lot using arrays.
- Also, before using the SendMessage function you should test if you actually can send a string back because it is not always possible.
- You forgot to include case 2 in the switch.

This post was edited on 10-01-2009 at 06:53 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-01-2009 06:36 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Creating a Command? - by Samo502 on 10-01-2009 at 05:37 PM
RE: Creating a Command? - by m0nst3rkill3r on 10-01-2009 at 05:41 PM
RE: Creating a Command? - by matty on 10-01-2009 at 05:44 PM
RE: Creating a Command? - by Samo502 on 10-01-2009 at 05:47 PM
RE: Creating a Command? - by matty on 10-01-2009 at 06:10 PM
RE: Creating a Command? - by Samo502 on 10-01-2009 at 06:12 PM
RE: Creating a Command? - by CookieRevised on 10-01-2009 at 06:36 PM
RE: Creating a Command? - by Samo502 on 10-01-2009 at 06:51 PM
RE: Creating a Command? - by CookieRevised on 10-01-2009 at 06:56 PM
RE: Creating a Command? - by matty on 10-01-2009 at 07:56 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