Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Two-way Aliases.

Two-way Aliases.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jakevanderpuy   (22 posts)  Bio
Date Sun 26 Sep 2004 02:24 AM (UTC)

Amended on Sun 26 Sep 2004 11:50 PM (UTC) by Jakevanderpuy

Message
Yet another banal alias targetting system question. Sorry. ;)
Tried to make it as lucid as possible.


SCRIPT:
Quote:

sub SetTarget  (sName, sLine, wildcards)
  world.SetVariable "target", wildcards (1)
  world.Note "Target: " & World.GetVariable("target") 
end sub


ALIASES:
Quote:

<aliases>
  <alias
   script="SetTarget"
   match="targ *"
   enabled="y"
  >
  </alias>

  <alias
   match="ii"
   enabled="y"
   expand_variables="y"
   sequence="100"
  >
  <send>o all bash @target</send>
  </alias>

  <alias
   match="cs"
   enabled="y"
   expand_variables="y"
   sequence="100"
  >
  <send>c 'color spray' @target</send>
  </alias>
</aliases>





I'd like to have my aliases work without an argument against my @target, but also work with an argument. Thus, I'd like both of the following to work using the 'ii' alias, for example.

ii
"o all bash @target"

ii human
"o all bash human"

I know this is pretty simple, but I've searched for a few hours in the forums and I haven't come across anything that explains it clearly. Not sure if it'd be easier to write out the extra code I need or just paste me a link to some information that I missed.

In any regard, thanks in advance. You guys do a great job of keeping up on this forum, and it's a credit to Mushclient all around. I've recommended the client to everyone I mud with.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #1 on Sun 26 Sep 2004 04:53 AM (UTC)
Message
Assuming you want to do it without scripting (which will be easier anyway), set the alias ii (without arguments) sequence 99 (lower than the ii *) one.

Make sure 'keep evalutating' is NOT checked.

Erm, you only have one.

Ok, make a second alias "ii *" and have it have a higher sequence than the first. Then have it send o all bash %1.


Actually, it shouldnt matter. At all. Since sending "ii human" wont match the "ii" alias.

So just make a second alias. Its only with open ended regexps that you'd need to do all that humdrum.

And actually, your targetting alias can send to variable. And then you can get rid of the need for a script all together. (send: "%1" send to: "variable" then set the variable field to "target")
Or if you didnt want to do that, you could send to script, then put your setvariable line in the "send" field.
If that last paragraph confused you, dont worry about it.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Jakevanderpuy   (22 posts)  Bio
Date Reply #2 on Sun 26 Sep 2004 02:10 PM (UTC)

Amended on Sun 26 Sep 2004 02:44 PM (UTC) by Jakevanderpuy

Message
I originally wanted a way to do this without adding twice as many aliases, but it's okay. I understand what you're saying about setting the target to %1 as well, but I am not sure entirely how to code another subfunction in the script file or utilize the existing SetTarget subfunction in this way. I included a different subfunction known as SetTargetExtend in the example code below for the sake of cogency. I think that'd be the easiest way to do it.

Here is a projected timeline of a fight.

I walk into a room, I see that my target is there grouped with a few other people. I type ii and my alias sends o all bash @target to the world. Now, after I'm done with my primary target I COULD just target another person real quick (using targ @target), but I would prefer not to. Thus, your idea has a great deal of validity. I want to then be able to type ii @target and have that set my @target variable, plus send o all bash @target to the world at the same time. Pretty basic stuff.


Here are the two pieces of code that I'm looking for additions/changes to:

Quote:

sub SetTargetExtend  (sName, sLine, wildcards)
  world.SetVariable "target", wildcards (1)
end sub

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

  <alias
   script="SetTargetExtend"
   match="ii *"
   enabled="y"
   expand_variables="y"
   sequence="99"
  >
  <send>o all bash %1</send>
  </alias>


*note* I have no idea if what I posted for the above alias will work. Logically, that seems what is necessitated, but I'm not sure.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #3 on Sun 26 Sep 2004 06:50 PM (UTC)

Amended on Mon 27 Sep 2004 03:22 PM (UTC) by Flannel

Message
Yes, that will work.
You could however, reuse that same other script. You dont need to make a second function.

You could also do this (and get rid of the script file all together):
<alias
match="ii *"
enabled="y"
expand_variables="y"
sequence="99"
send_to="12"
>
<send>send "o all bash %1"
setvariable "target", "%1"</send>
</alias>

See how that works? with the sendto:script and then the stuff the alias does changed into a script (with the world.send). Its the preferred method now, since its more modular (and you wont have a nightmare when/if you convert to a plugin).

And with your old target alias, you can do something similar, with the send to and have to send to "variable" and then set your variable without having to call a script function at all. (Sendto: variable, send: %1, variable: target)

Alright, now that Ive finished preaching the newfangled send to script. There are times when you want to use old fasioned script files. This would be one.
Turn your alias into a regexp, that looks like this:
^ii([ ](.*))?$
then that will match on ii or ii target.
then in your script you can check to see if your wildcard array has a value or not (check the length) and if so, use it (and set a target value), if not, use your stored variable.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Jakevanderpuy   (22 posts)  Bio
Date Reply #4 on Mon 27 Sep 2004 01:14 AM (UTC)

Amended on Mon 27 Sep 2004 01:37 AM (UTC) by Jakevanderpuy

Message
Way too many options, lol.

But, here's what I finally came up with. Decided this was the most portable way to go...don't have to lug around a script file this way.

Quote:

<aliases>
  <alias
   match="tar *"
   enabled="y"
   variable="target"
   send_to="12"
   sequence="90"
  >
  <send>
   SetVariable "target", "%1"
   ColourNote "white", "blue", "Target now %1"
  </send>
  </alias>

  <alias
   match="ii *"
   enabled="y"
   expand_variables="y"
   sequence="99"
   send_to="12"
  >
  <send>
   send "o all bash %1"
   SetVariable "target" "%1"
  </send>
  </alias>

  <alias
   match="ii"
   enabled="y"
   expand_variables="y"
   sequence="99"
   send_to="12"
  >
  <send>
   send "o all bash @target"
  </send>
  </alias>
</aliases>


Thanks!

*Not sure if I should have changed the send_to number on the first "tar *" alias so that I send to variable instead of world. I think that it will work the way I have it set up, however.
Top

Posted by Jakevanderpuy   (22 posts)  Bio
Date Reply #5 on Mon 27 Sep 2004 01:43 PM (UTC)

Amended on Mon 27 Sep 2004 04:14 PM (UTC) by Jakevanderpuy

Message
Oops! Getting an error when I input "ii snow" (without quotes).


Error number: -2146827263
Event:        Execution of line 2 column 22
Description:  Expected end of statement
Line in error: 
setvariable "target" "snow"
Called by:    Immediate execution
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #6 on Mon 27 Sep 2004 03:21 PM (UTC)

Amended on Mon 27 Sep 2004 03:22 PM (UTC) by Flannel

Message
you need a comma in there, between your two strings.

(I have edited my original post, yes I was comma-less. But now Im not)

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 29 Sep 2004 11:29 PM (UTC)
Message
Quote:

I originally wanted a way to do this without adding twice as many aliases, but it's okay.


You can do it with one alias, as Flannel suggested, by having a single match with an optional argument. See the example below. The script tests to see if wildcard 1 is empty or not, and behaves differently accordingly.

With this you don't even need the "tar" alias, except that the alias will give an error if there is no target variable at all (as it tries to expand the variables first). However once "target" variable exists, this single alias will do both "ii target" and "ii".


<aliases>
  <alias
   match="^ii( .*)?$"
   enabled="y"
   echo_alias="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>if "%1" = "" then
  Send "o all bash @target"
else 
  Send "o all bash%1"
  SetVariable "target", Trim ("%1")
  ColourNote "white", "blue", "Target now%1"
end if
  </send>
  </alias>
</aliases>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,765 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.