To provide key-press, key-release, and packaged-actions command aliases.
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.
(Note: the beginning slash (/) is needed if run from the drop-down console (the "~ console"))
/alias
&
) in the alias name indicates that it is an alias./alias aliasname
/alias aliasname "commands; commands"
/aliasname
Alias names with the form of "+
" or
"-
" have special meanings.
When bound directly to a key, the '+-
' form will be run.
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
".
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.
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.
Patched against Q3A 1.27g game source: q3aliases.diff