- 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.
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: