Command Last edited 5 months ago2024-06-12 11:06:53 UTC

Commands are the principle way of controlling the game in User posted image GoldSource (and also User posted image Source). It is invisible to the player, because it is done transparently via scripts and key bindings.

There are two types of commands:
  1. Those that does its thing once upon being issued, such as loading a map or a save file.
  2. A pair of commands that are prefixed with + and -. Issuing the + part produces an effect in the game (e.g. walking forward) that continues on until the - pair is issued, stopping the effect.
cvars (console variables) which are variables that hold values are also set in the same way as commands.

Commands and cvars can be entered manually by opening up the in-game console.

Types

Normal commands

Normal commands are issued and processed one time upon receipt by the game. They may accept zero, one, or more arguments, depending on the command. Arguments that contain spaces needs to be enclosed in "double quotes".
Examples: Some commands are cheats and need to have the cvar sv_cheats set to 1.

Game input commands

Game input commands consist of a pair of commands that are prefixed with + and -. In general it is used to control the player character. Throughout this page, game input command pairs will only be addressed by their + prefix and the --prefixed command is implied to also exist.
For example, +forward moves the player forward, and -forward stops it. +use makes the player USE an entity in front of them until -use is issued.
A page with a list of commands can be found in the Valve Developer Wiki. Note that it doesn't separate GoldSource and Source commands.

Binding commands

the bind command is instrumental for interacting with GoldSource engine, as it translates keyboard keypresses into commands. bind takes 2 arguments, the key name, and the command to issue.

For example, bind w +forward makes the game issue the +forward command when the W key is pressed down. Because it's assigned to an input command it also implicitly issue the -forward command when the same key is released.

Bound keys can be unbound with unbind <key>. There's also unbindall but do not issue this command willy-nilly!
A list of recognized key names is available in <Half-Life path>/valve/gfx/shell/kb_keys.lst

Command scripting

Any command line system would have some form of scripting. In GoldSource (and also Source) it is in the form of .cfg files containing a list of commands to send. It's used by the engine extensively to set up the current game, by executing some fixed-named script files autoexec.cfg, config.cfg, and userconfig.cfg. In particular, the game auto-generates config.cfg any time you change key binds (both via the Options dialog or via console) or some cvars.
Since the 25th Anniversary Update, the game also executes <mapname>_load.cfg and <mapname>_unload.cfg if they are found beside <mapname>.bsp in the maps/ folder.
You should not edit config.cfg directly and expect the changes to remain, as the game rewrites it and random commands that are not binds or cvars will get discarded. Use userconfig.cfg to setup your own set of commands you want executed on a game. You can also have any other config file that you can execute at any moment by issuing the exec <path/to/file.cfg> command.

Advanced scripting

Multiple commands can be executed at once (e.g. to feed to a bind command) by separating them with semicolons (;) e.g. bind mheelup "invprev;+attack;wait;-attack". Note in the example the wait command, which delays the execution of the rest of the commands by 1 frame, which in the example is required between the issuing of +attack and -attack.

Aliases is another powerful feature. It lets you execute a line of command (which can be multiple commands separated by semicolon as previously discussed) under a named alias. Then issuing the alias by name alone is equivalent to executing the line of command(s) you associate with it earlier. This is extremely useful as you don't have to repeatedly type the same commands, and execute multiple commands at once on top of that.

It also allows you to define your own pair of game input commands so that a bound key execute one set on key down, and the other set on key release. This example:
alias +speedup "host_framerate 0.08"
alias -speedup "host_framerate 0"
bind kp_plus +speedup
turns your keypad plus key into a "fast forward" key, which reverts to normal when the key is released.

Note that aliases are not saved. You need to add it to userconfig.cfg.

Exposing custom commands, aliases, or cvars in mods

Whether you added new commands with custom code, or just added fun aliases like the fast-forward one above, as a mod author, you can make them available to the players by editing the files corresponding to the Options > Keyboard tab (gfx/shell/kb_act.lst) for commands/aliases and the Options [> Multiplayer] > Advanced tab (user.scr) for cvars.

Comments

You must log in to post a comment. You can login or register a new account.