Scripting - help with commands (Was: HELP!) |
Author: |
Message: |
Ashylay
Junior Member
Intermediate Scripter
Posts: 70 Reputation: 1
– / / –
Joined: Mar 2007
|
O.P. Scripting - help with commands (Was: HELP!)
Okay so Im not the best at scripting and I was just wondering how this would happen.
So basically with the pre-installed scripts when you type say /name your name changes to whatever you type after the /name command so I just want to know how do you reffer to what you type after that.
I want it so say you type:
/command Hello!
A toast appears with the text 'Hello!'
Help?!?
This post was edited on 04-01-2007 at 01:21 PM by surfichris.
|
|
04-01-2007 12:47 PM |
|
|
TheGuruSupremacy
Full Member
Posts: 367 Reputation: 19
34 / /
Joined: Nov 2006
|
RE: HELP!
quote: Originally posted by Ashylay
Okay so Im not the best at scripting and I was just wondering how this would happen.
So basically with the pre-installed scripts when you type say /name your name changes to whatever you type after the /name command so I just want to know how do you reffer to what you type after that.
I want it so say you type:
/command Hello!
A toast appears with the text 'Hello!'
Help?!?
code: function OnGetScriptCommands(){
var commands = "<ScriptCommands>";
commands += " <Command>"
commands += " <Name>command</Name>"
commands += " <Description>TheGuruSupremacy</Description>"
commands += " </Command>"
commands += "</ScriptCommands>"
return commands;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
var split=Message.split(" ")
if(split[0]=="/command"){
MsgPlus.DisplayToast("Example",split[1])
return "";}}
This post was edited on 04-01-2007 at 12:57 PM by TheGuruSupremacy.
|
|
04-01-2007 12:52 PM |
|
|
Ashylay
Junior Member
Intermediate Scripter
Posts: 70 Reputation: 1
– / / –
Joined: Mar 2007
|
O.P. RE: HELP!
Is there a possible way to involve this in a getURL function of some sort? && The above script only works with one word ;o
This post was edited on 04-01-2007 at 01:07 PM by Ashylay.
|
|
04-01-2007 01:00 PM |
|
|
TheGuruSupremacy
Full Member
Posts: 367 Reputation: 19
34 / /
Joined: Nov 2006
|
RE: HELP!
quote: Originally posted by Ashylay
Is there a possible way to involve this in a getURL function of some sort?
I don't understand....Involve in a geturl function????Tell me what you want to do....Try to explain it better...
|
|
04-01-2007 01:07 PM |
|
|
Ashylay
Junior Member
Intermediate Scripter
Posts: 70 Reputation: 1
– / / –
Joined: Mar 2007
|
O.P. RE: HELP!
Well say on a webpage you used a variable
Would it be possible to load an internet page which has a variable on it and use the writing you wrote as the varibale so some of the script would look like this:
"http://www.yoursite.com/index.php?variable=" + split[1]
Then it would load
http://www.yoursite.com/index.php?variable=WHATEVER YOU PUT FOR SPLIT 1
|
|
04-01-2007 01:13 PM |
|
|
TheGuruSupremacy
Full Member
Posts: 367 Reputation: 19
34 / /
Joined: Nov 2006
|
RE: HELP!
quote: Originally posted by Ashylay
Well say on a webpage you used a variable
Would it be possible to load an internet page which has a variable on it and use the writing you wrote as the varibale so some of the script would look like this:
"http://www.yoursite.com/index.php?variable=" + split[1]
Then it would load
http://www.yoursite.com/index.php?variable=WHATEVER YOU PUT FOR SPLIT 1
Ok...if i have understand well...you want this:
code: function OnGetScriptCommands(){
var commands = "<ScriptCommands>";
commands += " <Command>"
commands += " <Name>command</Name>"
commands += " <Description>TheGuruSupremacy</Description>"
commands += " </Command>"
commands += "</ScriptCommands>"
return commands;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
var split=Message.split(" ")
if(split[0]=="/command"){
var url="http://www.yoursite.com/index.php?variable=" + split[1]
Interop.Call("shell32","ShellExecuteW",0,"open",url,null,null,1)
MsgPlus.DisplayToast("Example",split[1])
return "";}}
This post was edited on 04-01-2007 at 01:25 PM by TheGuruSupremacy.
|
|
04-01-2007 01:20 PM |
|
|
Ashylay
Junior Member
Intermediate Scripter
Posts: 70 Reputation: 1
– / / –
Joined: Mar 2007
|
O.P. RE: Scripting - help with commands (Was: HELP!)
Yes and also is it possible to use a for loop so I can type say
/command more than one word.
|
|
04-01-2007 01:25 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: HELP!
split() isn't the best way to parse command, regular expressions are more effective:
code: function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
if(/^\/command\s(.+)$/i.test(Message)) { //Regular expression to do the check
var Param = RegExp.$1; //Store Param, making the code easier to understand
MsgPlus.DisplayToast("Example", "Opening page with parameter '"+Param+"'"); //Display a toast
new ActiveXObject("WScript.Shell").Run("http://www.yoursite.com/index.php?variable="+escape(Param)); //Open the page with escaped Param to avoid any conflicts
return ""; //Don't send the message, otherwise Plus! warns you that the command couldn't be parsed
}
Or, instead of using the ActiveX object, you could replace that rule with:
code: Interop.Call("shell32", "ShellExecuteW", 0, "open", "http://www.yoursite.com/index.php?variable="+escape(Param), null, null, 1);
The advantage here is that it works for more than one word!
quote: Originally posted by TheGuruSupremacy
code: function OnGetScriptCommands(){
var commands = "<ScriptCommands>";
commands += " <Command>"
commands += " <Name>command</Name>"
commands += " <Description>TheGuruSupremacy</Description>"
commands += " </Command>"
commands += "</ScriptCommands>"
return commands;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
var split=Message.split("/command")
if(split[0]==""){
var url="http://www.yoursite.com/index.php?variable=" + split[1]
Interop.Call("shell32","ShellExecuteW",0,"open",url,null,null,1)
MsgPlus.DisplayToast("Example",split[1])
return "";}}
That code will work, but it will be case sensitive and it's not the recommend way to parse commands. Also, this won't work too good either with your code:
quote: /command I'm testing this /command, funny huh!
Therefore, it's more common to use regular expressions. They're harder to understand and learn, but they avoid a lot of problems you can have when using such split() calls.
This post was edited on 04-01-2007 at 01:32 PM by Matti.
|
|
04-01-2007 01:26 PM |
|
|
TheGuruSupremacy
Full Member
Posts: 367 Reputation: 19
34 / /
Joined: Nov 2006
|
RE: Scripting - help with commands (Was: HELP!)
quote: Originally posted by Ashylay
Yes and also is it possible to use a for loop so I can type say
/command more than one word.
Yes..It's possible:
code: function OnGetScriptCommands(){
var commands = "<ScriptCommands>";
commands += " <Command>"
commands += " <Name>command</Name>"
commands += " <Description>TheGuruSupremacy</Description>"
commands += " </Command>"
commands += "</ScriptCommands>"
return commands;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
var split=Message.split("/command")
if(split[0]==""){
var url="http://www.yoursite.com/index.php?variable=" + split[1]
Interop.Call("shell32","ShellExecuteW",0,"open",url,null,null,1)
MsgPlus.DisplayToast("Example",split[1])
return "";}}
|
|
04-01-2007 01:28 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Scripting - help with commands (Was: HELP!)
quote: Originally posted by TheGuruSupremacy
quote: Originally posted by Mattike
The advantage here is that it works for more than one word!
Also with split function works for more than one word
But not when you have "/command" in your actual message, read edited post.
I'm soo slow at editing...
|
|
04-01-2007 01:33 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|