I'd like to have certain commands execute when I change to a specific class. For instance, when I change to Spy, I'd like to immediately disguise as an enemy Pyro.
I know I can use this command to do so:

disguise 7 -1

However, I'd like to do this as soon as I spawn as Spy, not when I press a key.

Is there a config file that is always run when I spawn as a certain class, similar to how autoexec.cfg is always run when I start the game?


Yes. You can use the <classname>.cfg files, where <classname> is the name of the class (in all lowercase.)

For example, to disguise as a friendly Pyro when you spawn as Spy, you could place this in spy.cfg (under <Path to TF2>/tf/cfg/):

disguise 7 -1

which would immediately disguise you when you spawn.

You could also use it for special binds (an automatic "move forward and spin minigun" key for Heavy). Place this in your heavy.cfg file:

alias +SpinAndMove "+attack2; +forward"
alias -SpinAndMove "-attack2; -forward"
bind "]" "+SpinAndMove"

which causes you to spin your minigun and move forward when you press the ] key.

Keep in mind that binds will overwrite any command already assigned to that key, and that they stick around even after the game exits. As Richard suggested in the comments, you can have a default.cfg file with all the default binds, and then exec default at the top of every class config file.

| improve this answer | |
  • 3
    Worth remembering that if you change binds, these will persist when you change classes. I usually have a default.cfg with all the default binds in then run exec default at the top of each class file. – Richard Benson Sep 23 '15 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.