[GUIDE] Learning to Use the Command Line, the Console, and .CFG Scripts

fartron

L1: Registered
Jan 27, 2008
45
11

USING THE COMMAND LINE, THE CONSOLE, AND .CFG SCRIPTS

When testing maps, we spend a lot of time in the console. It is often useful to write scripts to automate some of the more common tasks. This resource is meant to introduce mappers to the console, and encourage creative use of configuration files.



Command Line

We must start with the Command Line, where we pass options to the program as it is executing. The two most useful command line arguments are -dev and -console. The -dev option "Enables developer mode. Also disables the automatic loading of menu background maps and stops the quit dialog from appearing on exit." while -console "Starts the game with the developer console enabled." If you want to run the game in windowed mode, use the option -sw.

While you can add options to the command line from the Steam menu (Properties->"General" Tab->Set Launch Options...), it is more useful to make a shortcut, with the target Steam.exe -applaunch 440 -dev -console. The commands can also go in the Additional game parameters: field of the Hammer compile dialog, if you are running TF2 directly from Hammer. You'll notice a third command in the picture of the compile dialog, +sv_lan 1. The command line also accepts console commands that are preceded by the plus (+) symbol.


shortcut: compile dialog:



Console Commands
This brings us to the Developer Console. The console, once enabled, is accessed with the tilde (~) key.

The console tries to auto-complete as you type commands, which is useful for exploring the various prefixes. You can also search for commands with find, and read documentation about commands with help.

The commands sv_cheats 1 and developer 1 are unnecessary if you started the game with the -dev command line option, but are otherwise required to make all the console commands available. With sv_cheats enabled, your actions will not count toward your Achievements, or be recorded by Steam. The developer command can also be set to 2, which will echo much more information to the console, including entity inputs and outputs.

The command sv_lan 1 switches the server to a local network mode that stops players from joining over the internet. It will also prevent connection errors that may occur while hosting a server locally.

Use noclip to fly around your level and pass through solid architecture.

Enter mp_waitingforplayers_cancel 1 to skip the 30 second "waiting for players" delay that occurs after loading a new map.

To get a list of entities in the map, enter cl_showents. The command ent_text displays a lot of useful information on the screen about the entity or entities selected. You may pass a specific entity name (ent_text red_cap_point1), or an entity class (ent_text item_teamflag) to the command, or simply enter the command while looking at the entity. If you know an entity's index number, you may use that as well.

The surfaceprop command will return information about the surface under the crosshair when entered, including its type, texture and distance.

When building cubemaps, it is important to enter the console commands in the correct order.
Code:
disconnect
mat_specular 0
mat_hdr_level 0
map MAP_NAME
buildcubemaps
disconnect
mat_hdr_level 2
map MAP_NAME
buildcubemaps
disconnect
mat_specular 1
map MAP_NAME

First it is necessary to disable specular effects. We must also build the maps both with and without HDR lighting. Load the map once again, and the cubemaps will be in place.



.cfg Scripts
To simplify using the console, we can place Scripts into the folder tf/cfg. These files are a script of console commands arranged in a simple text file. You can load config files into the game with the exec command, either in console (exec example.cfg) or from the command line (+exec example.cfg). The file autoexec.cfg will be loaded every time the game starts and, unlike config.cfg, will not be changed when the game exits.

Screenshot script
Code:
alias +screeny "developer 0; cl_drawhud 0; wait; r_drawviewmodel 0; wait; jpeg_quality 100"
alias -screeny "jpeg; wait 3; developer 1; play misc/freeze_cam_snapshot.wav; wait; cl_drawhud 1; wait; r_drawviewmodel 1; wait; jpeg_quality 90"

bind F5 "+screeny"

This is a script for taking nice screenshots of our maps. Here we use alias to create the +screeny command, and bind the F5 key to it.

Commands that begin with a plus (+) symbol have an associated minus (-) command that is sent when a key is released. In this case, pressing down the F5 key will clear the screen and crank up the screenshot quality, while releasing the key will take the screenshot and then return the settings. There is a significant filesize difference between jpeg_quality 90 and 100, so it is worth switching back to the default for normal usage.

If you prefer high quality Targa (.tga) images, you can remove the jpeg_quality variable and replace the jpeg command with screenshot.





 
Last edited:

fartron

L1: Registered
Jan 27, 2008
45
11

Appendix A: Scripting Examples
Scripts may be placed in the folder team fortress 2\tf\cfg. The file config.cfg is created by the game upon exit to store all your binds and settings, and will be loaded the next time the game starts. The game will also look for a file name autoexec.cfg, which is where you will want to start your scripts.

You can place the exec command in your scripts to load another script file. This new file will load immediately, before the rest of the first script has loaded. I use this to keep my scripts tidy by executing separate files for different commands. I find making my scripts modular this way also has many advantages, including swapping and restoring settings in batches.


autoexec.cfg
Code:
// 
// autoexec.cfg example
//

echo "starting autoexec.."

exec "settings.cfg"
exec "binds.cfg"
exec "aliases.cfg"
//exec "maptest.cfg"

echo "autoexec loaded."

Any line that begins with two forward slashes (//) will be considered a comment, and skipped when the script is executed.

The echo command will display text in the console. This text will only be readable if the console is open, unless developer mode is on, when it will appear in the upper left corner of the screen. In this example, all three of the other .cfg files will be loaded before the console says "autoexec loaded".

It is proper form to enclose variables and strings in quotation marks, though it is not entirely necessary unless the string contains a space, and may then be mistaken for multiple commands or arguments.

Your settings and binds will of course depend on how you have your game set up. You can always check your config.cfg and see how the console variables were set the last time you quit the game, or type the variable name into the console to see what it is set at currently. I always make a point of including my mouse and network settings.

Here is a script for flying around your level in noclip mode. The bindings are based on my existing set up, and should be changed to match your own. It swaps the +duck and +jump buttons with the +movedown and +moveup commands to make moving in 3 dimensions much easier.


Noclip script
Code:
bind a "+d"            // this is the key i normally have for +duck
bind space "+u"        // this is the key i normally have for +jump
bind ctrl "noclippy"   // this engages the fancy new noclip mode

alias +d "+duck"
alias -d "-duck"

alias +u "+jump"
alias -u "-jump"

alias noclippy "movement_toggle1"
alias movement_toggle1 "noclip; alias +d +movedown; alias -d -movedown; wait; alias +u +moveup; alias -u -moveup; wait; alias noclippy movement_toggle2"
alias movement_toggle2 "noclip; alias +d +duck; alias -d -duck; wait; alias +u +jump; alias -u -jump; wait; alias noclippy movement_toggle1"

Here you can see a simple toggle alias, with the binding done externally. While you can use the bind command in an alias, doing so makes changing the script later much more difficult. It is simpler to have only a single location in which to change the key binding, and makes the script more accessible to others.

Once this script has loaded, the space and A keys will be bound to +u and +d, respectively, until you change them back. If you quit, the new settings will be stored in your config.cfg file. Restoring your default binds is exactly what having a binds.cfg file is useful for. If it is loaded in the autoexec.cfg file, the settings will overwrite those in config.cfg. You may also load it manually from the console in the midst of a game to restore your settings.

 
Last edited:

DrHaphazard

L5: Dapper Member
Jan 6, 2008
249
12
Excellent, I confess that I am sadly underinformed about all the console command stuff. Thanks a lot fartron, oh and nice sig.
 

fartron

L1: Registered
Jan 27, 2008
45
11
Thank you. I've been playing around with the console since qwtf, writing disguise scripts and stuff, and I noticed there didn't seem to be a good introductory guide for mappers. If anyone has suggestions for useful commands, or scripts they use, I'd be more than happy to include them.
 

Paria

L5: Dapper Member
Dec 12, 2007
202
31
perfui - performance ui occlusion/wireframe/area portal tools
 
Last edited: