First, I recommend you read the excellent “Mushclient protips” guide by notwalking.
After writing some basic aliases, you may have noticed that you do the same thing over and over when defining an alias. This is the idea behind MUSHclient’s built-in meta alias, “#alias {*} {*}”, which allows you to quickly define an alias from the prompt.
We can build on this concept, along with a little scripting, to create some pretty useful meta aliases.
First, let’s take a look at the built-in meta alias:
-
- In MUSHclient, hit Ctrl-Shift-9 to bring up the Aliases configuration.
- For this article, click the Tree View check box so we can easily group the aliases.
- Expand special_convenience_aliases
- Double-click on #alias {*} {*} to see what it does.
Looks pretty messy, but really this is just building the XML for another alias, and then saving the new alias. Once you have a sense of how this works, you have quite a bit of power at your fingertips to create clever new meta aliases.
Here we’ll walk through two use cases for meta aliases: a cycling attack meta alias, and a portal meta alias.
Cycling Attack Meta Alias
One day, this author noticed that he often manually cycled through several attack aliases whenever he wanted to inflict a certain type of damage (say, holy). “Wouldn’t it be nice if I could just type ‘hol’ and have the client cast a different holy-damage spell each time?” he thought. This is the purpose of the Cycling Attack meta alias.
Our end goal is to be able to do the following in the client:
> t1 kobold
> hol
cast 'holy strike' kobold
> hol
cast repentance kobold
> hol cast 'holy strike' kobold
Minor note: in this article, text that follows the “>” is supposed to be what you type at the prompt. The lines above that don’t start with “>” are supposed to show what the client then sends to the server.
First, it’s important to understand the concept of a “target” variable. This feeds into the attack aliases, so let’s start there.
Creating a Target alias/variable
It’s a common MUD pattern to create an alias like the following, which lets you quickly set a target mob’s name in a client variable (here called “target1”):
<aliases>
<alias
match="t1 *"
enabled="y"
variable="target1"
send_to="9"
sequence="100"
>
<send>%1</send>
</alias>
</aliases>
You can add this to your own MUSHclient as follows:
-
- Hit Ctrl-Shift-9.
- Copy the above XML.
- Click the Paste button in the Aliases configuration screen.
Now whenever you type something like “t1 kobold”, you’ll set a MUSHclient variable named “target1” to the value of “kobold”. Then you can simplify all of your attack-related commands by referencing the @target1 variable like so:
<aliases>
<alias
match="unmagic"
enabled="y"
expand_variables="y"
group="attack_aliases"
send_to="10"
sequence="100"
>
<send>cast 'dampening field' @target1</send>
</alias>
</aliases>
Notice that using this alias, you only have to type “unmagic” and you’ll cast dampening field on your current target, instead of having to type the target’s name every time.
With this in mind, let’s return to the cycling attack alias idea. We’ll start by creating a scripted Lua function that we can use later in our meta alias.
Creating a script that cycles through attacks
First, create a new file called cycle_commands.lua with this as its contents:
function cycle_attack (cmdvar, idxvar)
if not GetVariable(idxvar) then
SetVariable(idxvar, 0)
end -- if
idx = tonumber(GetVariable(idxvar))
cmds = utils.split(GetVariable(cmdvar), ",")
nextcmd = cmds[idx + 1]
Send (nextcmd .. " " .. GetVariable ("target1") )
SetVariable(idxvar, bit.mod(idx + 1, #cmds))
end -- function
Okay, what are we doing here? The function makes use of two arguments:
- A command variable (cmdvar). This must contain a list of comma-separated commands that can be run by the client. For example, it might contain “cast ‘holy strike’,cast repentance”. Here, the idea would be to somehow cycle through those two attack commands.
- An index variable (idxvar). This is where an array index pointer is kept. The functions start it off at 0 if it hasn’t been defined yet.
The cycle_commands function first gets the index variable and use it to get the appropriate value in the command variable list, and sends the command to the server, along with the @target1 variable. It then increments the index (rolling back to zero if it’s reached the end of the list) and sets the index variable again.
To enable this script:
-
- Place this script file under your MUSHclient home folder, under the scripts directory.
- In MUSHclient, hit Ctrl-Shift-6 to bring up the Scripts configuration.
- In the External Script File section, select Browse, and select the cycle_commands.lua script. Ensure “Enable scripting” is checked.
Now we can use the cycle_attacks function in our aliases.
Creating the meta attack alias
Next, let’s create the actual meta alias, which will let us quickly create attack aliases later. Paste this in your Aliases configuration view:
<aliases>
<alias
match="#attackalias {*} {*}"
enabled="y"
group="special_convenience_aliases"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>require "addxml" -- addxml extension
-- add the alias
addxml.alias {
name = "command_line_alias_" .. string.gsub(Base64Encode("%1"), "=", ""),
match = "%1",
send = "cycle_attack ('%1cmds', '%1idx')",
sequence = 100,
enabled = true,
send_to = 12,
group = "attack_aliases"
}
ColourNote ("white", "green", "Added alias to match on '%1' with '%2' attacks")
SetVariable ("%1cmds", "%2")
</send>
</alias>
</aliases>
Whew, what have we done here? It’s probably easiest to just try it out in your prompt:
> #attackalias {hol} {cast 'holy strike',cast repentance}
This will do the following:
-
- Set a new variable called ‘holcmds’ to the value: cast ‘holy strike’,cast repentance
- Set a new variable called ‘holidx’ to the value: 0
- Define a new alias in the attack_aliases group called ‘hol’ that sends the following to a Script:
cycle_attack ("holcmds", "holidx")
Now in your client, once you’ve set your target (remember, t1 kobold), you can simply type this:
> hol
cast 'holy strike' kobold
> hol
cast repentance kobold
Portal Meta Alias
Now we turn to portals. You may already have a “portal” alias defined that gets a portal from your bag, holds it, and enters, but let’s first create one here just as a sample:
<aliases>
<alias
match="portal *"
enabled="y"
group="portal_aliases"
send_to="10"
sequence="100"
>
<send>get %1 backpack
hold %1
enter
rem %1
put %1 backpack
dual @dual
remove invis
wear invis lfinger</send>
</alias>
</aliases>
Say you type ‘portal mirror’. This alias will do the following (feel free to edit as suits your gear):
-
- Gets the portal from the portal bag (a backpack, in my case)
- Holds the portal, enters it, removes it, puts it back in the bag.
- Dual wields a weapon whose name I’ve put in my @dual variable (a good practice, as well).
- Re-applies the ring of invisibility.
Obviously, much of this is optional, like the dual wield and invisibility ring, and you’ll want to use your actual portal bag name.
But, let’s go back to the meta concept: how can we easily create portal aliases, since we do it so often? Paste the following meta alias in your client:
<aliases>
<alias
match="#portalalias {*} {*}"
enabled="y"
group="special_convenience_aliases"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>require "addxml" -- addxml extension
-- add the alias
addxml.alias {
name = "command_line_alias_" .. string.gsub(Base64Encode("%1"), "=", ""),
match = "%1",
send = "portal %2",
sequence = 100,
enabled = true,
send_to = 10,
group = "portal_aliases"
}
ColourNote ("white", "green", "Added alias to match on '%1' with 'portal %2'")
</send>
</alias>
</aliases>
This makes use of our “portal *” alias. Now you can do the following:
> #portalalias {preme} {mirror}
Which will create an alias called ‘reme’ that sends to the server: portal mirror
Once you’ve used your portal, you can additionally add it to the mapper:
> mapper portal preme
Disarming Triggers
Finally, let’s define some useful triggers related to getting disarmed. These triggers use a @weap variable that lets you quickly rewield your primary weapon when disarmed.
First, let’s set up the alias that sets this variable:
<aliases>
<alias
match="setweap *"
enabled="y"
variable="weap"
send_to="9"
sequence="100"
>
<send>%1</send>
</alias>
</aliases>
You can use this as follows:
> setweap sword
(You can do the same with the @dual variable from above, by the way.)
The folowing trigger, then, will detect when you’re disarmed but keep the weapon in your inventory:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="*DISARMS you and you struggle not to drop your weapon*"
send_to="12"
sequence="100"
>
<send>Note ("++++++++++++++++++++++++++++++++++++ You have been DISARMED! +++++++++++++++++++++++++++++++++++")
Send("wield @weap")</send>
</trigger>
</triggers>
And this one triggers when your weapon goes flying:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^.*DISARMS you and sends(.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>Note ("++++++++++++++++++++++++++++++++++++ You have been DISARMED! ++++++++++++++++++++++++++++++++++++")
Send ("get @weap")
Send("wield @weap")</send>
</trigger>
</triggers>
Now you shouldn’t worry, as long as you keep your @weap variable up to date.