Purpose

To provide key-press, key-release, and packaged-actions command aliases.

Overview

A new command, "alias", is added. The packaged-action form precludes the need of prefixing "vstr" for scripting. Actions can be bound to both key-presses and key-releases, instead of only to key-presses.

Usage

(Note: the beginning slash (/) is needed if run from the drop-down console (the "~ console"))

/alias
Lists all known aliases and their contents. The beginning ampersand (&) in the alias name indicates that it is an alias.
/alias aliasname
List the content of the given alias named aliasname.
/alias aliasname "commands; commands"
Assigns the provided command sequence to the given alias name.
/aliasname
Runs the given alias name aliasname as a command. Note the lack of a leading "vstr".

Alias names with the form of "+aliasname" or "-aliasname" have special meanings. When bound directly to a key, the '+-' form will be run.

Useless Examples

alias +sit "+movedown; +button3"
alias -sit "-button3; -movedown"
alias suicide "drop flag; wait; kill"
bind b +sit
bind k suicide

Holding down 'b' will cause your player to crouch and start gesturing. When 'b' is released, your character will stop crouching (and maybe still continue gesturing).

Pressing 'k' causes your player to drop the flag, then commit suicide (preventing an immediate flag return in Q3TA CTF). Release 'k' does nothing special. However, note that the bind for 'k' lacks the string "vstr".

Limitations

You cannot create an alias that has the same name as a builtin command. This includes, but is not limited to, "quit", "echo", "+forward", "+moveup", "cvarlist", "set", and so on. You can go ahead and try, but the builtin command will take precedence.

Programming Notes

The major hook is in CG_ConsoleCommand() in cgame/cg_consolecmds.c. The "alias" command is added as any normal command. However, the aliases themselves must act as normal commands, too. Since the commands array is fixed at compile time, CG_ConsoleCommand() is a convenient place to handle commands defined at run-time (aliases). Running aliases is accomplished simply by prepending ampersand (&) to any unrecognized command, and attempting to "vstr"-run the resulting name; if the cvar is empty or undefined, the alias returns as an unknown command. Likewise, storing/defining aliases is stored in a cvar with the alias's name prepended with ampersand (&): "alias foo" => "&foo". As a result, an alias can also be run in the form "vstr &aliasname".

Patches at a later date will include parameterized aliases ("functions"). This, in many ways, also leads into comparison expression (equal to, not equal to), conditional statement structures (if-then-else), and looping (for-each-parameter). In short, it opens a path to full blown programmability.


(2001.03.29)

Patched against Q3A 1.27g game source: q3aliases.diff


-- PhaethonH (phaethon@linux.ucla.edu)