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

/ commands
Author: Message:
JANiT0R
New Member
*


Posts: 2
32 / Male / –
Joined: Feb 2007
O.P. / commands
i'm working on a script, i've never done anything like this before.
how do i make it so that if i put "/command" and then my message, the script will take effect?
any help is appreciated.
02-04-2007 05:17 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: / commands
Aaah... here's where regular expressions can help. :-)

I'll try to simplify it for you, since I guess you've never worked with those.
code:
var myCommand = "myscriptcmd"; //This is the name of your command! Please don't use any special characters to avoid problems with the regular expression
var myCommandDesc = "My first script command!"; //Here you can add a description for your command which will be shown in the shortcut menu when you press "/"

//Register our command
function OnGetScriptCommands() {
   var s = "<ScriptCommands>";
   s += "<Command>";
   s += "<Name>"+myCommand+"</Name>";
   s += "<Description>"+myCommandDesc+"</Description>";
   s += "<Parameters>&lt;message&gt;</Parameters>";
   s += "</Command>";
   s += "</ScriptCommands>";
   return s;
}

//The send event!
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   var reCheck = MakeRegExp(myCommand); //Get a regular expression
   if(reCheck.test(Message)) { //Checks if the message is our command
      var Param = RegExp.$1; //This thing is where the captured parameter is stored
      Message = MyFunction(Param); //Change this to your function name, and eventually add other parameters to it.
   }
   return Message;
}

//A simple function to create a regular expression
function MakeRegExp(str) {
   return new RegExp("/^\/"+str+"\s(.+)$", "i");
}

//An example function. Note that you always have to return something to be sent as replacement for the original message. If you want it to stop sending a message (eg if you want the command to only open a window), just return an empty string. (return "")
function MyFunction(Param) {
   var newMsg = "[c=4]"+Param+"[/c]";
   return newMsg;
}
Note: this code is not tested. It's possible that something wasn't noticed while I reviewed my post. If so, please let me know (or you can try to fix it yourself of course)!

This post was edited on 02-04-2007 at 06:49 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!
02-04-2007 06:47 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: / commands
quote:
Originally posted by Mattike
Aaah... here's where regular expressions can help. :-)

I'll try to simplify it for you, since I guess you've never worked with those.
code:
//Register our command
function OnGetScriptCommands() {
...
}

OnGetScriptCommands has got absolutely nothing todo with "registering" a command and is absolutely not needed.

A command is reconized as a command of your script ONLY if you handle it in the ChatWndSendMessage event and return an empty string.

If you do not return an empty string the command line is passed further to other scripts and eventually to Plus! itself. Though this returning of something or an empty string is not mandatory and you can still perfectly 'react' on something the user has typed.

So...
quote:
Originally posted by Mattike
//An example function. Note that you always have to return something to be sent as replacement for the original message.
No you don't. This only depends on what you wanna do and is not mandatory for handling commands (though it is recommended and the 'right' thing todo).

quote:
Originally posted by Mattike
Note: this code is not tested. It's possible that something wasn't noticed while I reviewed my post. If so, please let me know (or you can try to fix it yourself of course)!
For stuff like this always test the code yourself first (and verify the things you claim are correct like "OnGetScriptCommands registers our command").

This post was edited on 02-05-2007 at 01:22 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
02-05-2007 01:16 AM
Profile PM Find Quote Report
JANiT0R
New Member
*


Posts: 2
32 / Male / –
Joined: Feb 2007
O.P. RE: / commands
Firstly: thanks for the quick assistance.

but this is really confusing, someone wouldn't happen to be able to do this for me would they?
Basically i wanted a script to turn a message into l33t. i have made one that kinda works, but requires manually switching on and off in scripts menu and i had to copy stuff multiple times. I'm posting the script so feel free to have a shot at it.
any help is appreciated

.txt File Attachment: 1337script.txt (7.69 KB)
This file has been downloaded 160 time(s).
02-10-2007 09:02 PM
Profile PM Web Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: / commands
why will you have to repeat the same thing again and again?

just use regular expression:

code:
sMessage = sMessage.replace(/whatever/gi,"something")

/whatever/gi << change the "whatever" to a letter; the g means that it will search for multiple entries; the i is ignore case.


edit: i do not think you should put words in there also.. because the letters will take care of it?

i will try and fix this.. i will update this post once its finished so hold on to your butt :happy:

------------


i did it some other way.. so here. i tested it and it works - not sure if you wanted this kind

.zip File Attachment: 1337 script.zip (991 bytes)
This file has been downloaded 128 time(s).

This post was edited on 02-11-2007 at 02:21 AM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
02-10-2007 11:49 PM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: / commands
That method you used, roflmao456, is not a proper way to do it. In fact, it will render messages wrong.

You first replace a letter 'A' with a letter 'B' and then in the next iteration you search for 'B' to change it to 'C'. Of course, in the end, 'A' will be replaced by 'C' and not by 'B'...

Never use many replace statements after each other for things like this!
.-= A 'frrrrrrrituurrr' for Wacky =-.
02-11-2007 10:25 AM
Profile PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: / commands
quote:
Originally posted by CookieRevised
That method you used, roflmao456, is not a proper way to do it. In fact, it will render messages wrong.

You first replace a letter 'A' with a letter 'B' and then in the next iteration you search for 'B' to change it to 'C'. Of course, in the end, 'A' will be replaced by 'C' and not by 'B'...

Never use many replace statements after each other for things like this!

check again? it only replaces 'a' with 4 and 'b' with itself and 'c' with (.. etc.

i dont see how it will replace 'a' with a 'b'
[quote]
Ultimatess6
: What a noob mod
02-11-2007 03:33 PM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: / commands
:dodgy: ... the 'A', 'B', 'C' are examples which stand for something, it could be anything. I could have called it 1 2 3 too...

The point is that using many replace statements after eachother and using the same input variable as the output variable is not a good programming method. You should use a different variable as output to avoid that 'A' becomes 'C' in the end.

Explained many times on the forum too though. The type of script asked here, and the scripts shown here already exist in many forms. So search forums first instead of creating yet another script which does the same thing (in a bad way).

This post was edited on 02-12-2007 at 11:10 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
02-12-2007 11:07 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