Aliases

Posted by Fluxo on Fri 09 May 2003 09:31 AM — 4 posts, 20,317 views.

#0
Hello.

I want to get an alias working both with and without an argument.

If I have "blah *" as my alias, then typing blah whoever works fine. But of course blah on it's own doesn't.

If I have "blah*" instead, then typing blah on it's own works fine, but blah whoever ends up with an extra space between the command and the whoever, as the space is counted as part of the argument. This causes problems on my mud.

Is there any way I can make an alias that will work both with and without an argument passed to it? Essentially it's for stuff like heal aliases, where I want to 'cast heal person' if there's an argument, or just 'cast heal' if there isn't (which would heal myself).
#1
This should work:


<aliases>
  <alias
   name="heal_alias"
   match="^blah( (?:.+))?$"
   enabled="y"
   regexp="y"
  >
  <send>cast heal%1</send>
  </alias>
</aliases>


The outer () has a ? on the end to make it optional.
The inner () has ?: at first, which makes it to where it doesn't remember the information, but still checks for it. The . means to check for any character, and the + means that the previous item has to match 1 or more times.

Since the outer () is storing into %1, and it contains a space in it already, the final output you send to the mud should not have a space before the %1(since it's inside this variable).
Canada #2
This can be accomplished by using a regular expression. This is a special type of syntax for building aliases and triggers. It is explained fully in a text file within your MUSHclient directory, called RegularExpressions.txt .

Here is a tidbit from one of my plugins, which uses an alias with an optional argument:

<aliases>
  <alias
   name="EQ_Display_Help"
   script="EQ_Help"
   match="^eqhelp(?:[ ]+(.*))?$"
   enabled="y"
   regexp="y"
   ignore_case="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[

Sub EQ_Help (AliasName, AliasLine, arrWildcards)
	Dim HelpArgument
	HelpArgument = Trim(LCase(ArrWildcards(1)))
	Select Case HelpArgument
		Case "eqt"
			EQ_Help_eqt "EQ_Help", AliasLine, arrWildcards
		Case "eqset"
			EQ_Help_eqset "EQ_Help", AliasLine, arrWildcards
		Case "eqxa"
			EQ_Help_eqxa "EQ_Help", AliasLine, arrWildcards
		Case "eqxr"
			EQ_Help_eqxr "EQ_Help", AliasLine, arrWildcards
		Case "eqlist"
			EQ_Help_eqlist "EQ_Help", AliasLine, arrWildcards
		Case "eqg"
			EQ_Help_eqg "EQ_Help", AliasLine, arrWildcards
		Case "eqd"
			EQ_Help_eqd "EQ_Help", AliasLine, arrWildcards
		Case "eqon"
			EQ_Help_eqon "EQ_Help", AliasLine, arrWildcards
		Case "eqoff"
			EQ_Help_eqoff "EQ_Help", AliasLine, arrWildcards
		Case "eqfix"
			EQ_Help_eqfix "EQ_Help", AliasLine, arrWildcards
		Case "eqlvl"
			EQ_Help_eqlvl "EQ_Help", AliasLine, arrWildcards
		Case "eqsw"
			EQ_Help_eqsw "EQ_Help", AliasLine, arrWildcards
		Case "eqcolour"
			EQ_Help_eqcolour "EQ_Help", AliasLine, arrWildcards
		Case Else
			EQ_Help_General "EQ_Help", AliasLine, arrWildcards
	End Select
End Sub

]]>
</script>

In my alias, the ?:[ ]+ part of the expression is what catches the space. The ?: means match on this, but don't return it as part of the result. The [ ]+ part means match on 1 or more spaces (since there is only a space between the brackets).
Canada #3
Heh, I took my time replying while playing on my mud. I think both regular expressions should work (mine and Vaejor's).