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.