Config Files, and How to Make One
(October 7, 2017)
Console commands can be used to change anything from the amount of ammo a gun has by default to debugging AI nodegraphs and the PVS to changing the texture filtering mode in a GoldSrc game. Very powerful indeed, but remembering them or typing them out over and over can be a slog.
If you find yourself running a set of commands over and over, forgetting some and typing more than you should, perhaps it's worth a look at writing a config file. A config file, or a
.cfg, is a list of commands executed either by the game on startup or by the player in the console when run with the
Before we begin, it's worth noting that custom config files cannot get you VAC-banned. This is a common misconception. Config files actually serve an important purpose in the engine, and Valve includes many with their games to store keybinds and other settings.
Where are these config files?
For GoldSrc games, config files are located in the top level of the mod directory. For example, Team Fortress Classic has them in
/Half-Life/tfc. Source config files are kept neatly in a separate
/cfg directory; Half-Life 2 keeps its config files in
Common config files
Most games have a lot of config files lying around. Two of the more common ones are
autoexec.cfg gets run automatically at the start of the game. Often, this contains commands that affect the entire game, such as
sv_lan 0. If you were to put the command
echo "This was run by autoexec!" into your
autoexec.cfg, you would see this in the console when you run the game.
Not all games have a
autoexec.cfg by default; you can create it if it doesn't exist.
config.cfg contains commands that are more related to in-game behavior. If you make changes to your keyboard layout, mouse sensitivity, or sound settings, or have custom keybinds, they'll get saved in here.
The following is an example of what types of commands are usually found in a config file, from Counter-Strike: Global Offensive's
unbindallmousekeyboard bind "ESCAPE" "cancelselect" bind "`" "toggleconsole" bind "TAB" "+showscores" bind "SPACE" "+jump" bind "," "buyammo1" bind "." "buyammo2" bind "0" "slot10" bind "1" "slot1" bind "2" "slot2"
config_default.cfg is executed when
config.cfg is not present.
Making your own config files
You can make your own config files quickly and easily. We'll be making one for Garry's Mod called
MyConfigFile.cfg. All you need to make one is a text editor; Notepad will work fine.
- Open your text editor and make a new file.
- Add the commands you want to it. As a basic example, we'll add two commands to ours;
sv_cheats 1, which activates cheats, and
sbox_godmode 1, which makes the player invulnerable. Make sure they're on separate lines.
- Save the file and navigate to the config directory of the game you're making the config for. Since our config is for Garry's Mod, we will navigate to
- Save the file with a
.cfgextension. Notepad will save files with a
.txtextension if you're not careful. You can confirm this by wrapping the file name in quotes and by changing the "save as type" to "All Files".
Running config files
Config files can be run regardless of cheats or elevated server admin status, though the commands themselves are still bound to those limits. Configs are run with the
exec command. You can run a config file in the console by typing
exec <config file name>. Remember to leave off the
.cfg extension when you go to run it.
Since our above example was called
MyConfigFile.cfg, we would run
exec MyConfigFile to run it in-game. Note that
exec autocompletes with the config files available to the game.
exec itself can be run from a config, to chain config files together.
You can bind configs to a key and run them whenever that key is pressed. If you wanted to run
MyConfigFile.cfg whenever you pressed your P key, you would run
bind p "exec MyConfigFile" in the console.
Config files are a powerful tool that can save you a lot of time when you're doing work in the console.