Team Fortress 2

Team Fortress 2

280 ratings
How to use scripts + some useful scripts I use
By heidi_alt
Did you know that you can do a great many things in TF2 via console commands/scripts? Would you like to easily sentry jump, bind voice commands like 'Good Job!' to a single key, and many other things besides? Look no further - this guide is for you!
4
   
Award
Favorite
Favorited
Unfavorite
Introduction
Scripting/binding can be immensely useful in TF2. Quoted from the official TF2 wiki:

Scripting is the use of configuration files (.cfg) to create new keybinds and aliases automating complex behaviors and console command sequences. Unlike hacking, scripting is built into Team Fortress 2 and is not banned by VAC (Valve Anti-Cheat). Uses of scripting vary from simply binding a key to a command to self-referential loops and nested aliases that redefine one another. Any functionality that can be created with scripting can also be accomplished without it, but scripting allows these functionalities to be used in the heat of battle.

This guide will show you how to get started, and will give you some other scripts that I use myself.
Setup
Firstly, you'll need to go to [wherever you installed Steam]/steamapps/common/Team Fortress 2/tf/cfg, like so:



Alternatively you can go to your Steam library, right click on TF2, and then click on properties. A window will come up: click on the Local Files tab, then on the Browse Local Files button, like so:


This will take you to [wherever you installed Steam]/steamapps/common/Team Fortress 2, at which point you just need to double click on the tf folder and then the cfg folder.

You'll see a bunch of files, but only 10 interest us:

autoexec.cfg
demoman.cfg
engineer.cfg
heavyweapons.cfg
medic.cfg
pyro.cfg
scout.cfg
sniper.cfg
soldier.cfg
spy.cfg


They need to be called these names exactly, or TF2 won't recognise them. If they don't exist, just create an empty .txt file and rename it to a .cfg file. Make sure windows isn't hiding file extensions when you do this! Otherwise you'll end up with something like spy.cfg.txt, which won't work. autoexec.cfg is for scripts you want to use on every class, whereas the other 9 files are for class-specific scripts.
Careful!
One thing that may catch you out: when you bind something on a class-specific file, it will start working when you play that class, but it will not stop working when you switch away!

For example: in my medic.cfg, I have the following bind:

// Good Job bind "MOUSE3" "voicemenu 2 7"

This binds middle mouse click to the 'Good Job!' voice command (I like to compliment my heal targets). This will only start working when you play medic. But when you switch away, middle mouse click will still say 'Good Job!' for you - unless you bind it to some other command, or unbind it entirely. So in my other .cfg files, I have the following bind:

//Rebinds unbind "MOUSE3"

That way, middle mouse will say 'Good Job!' only for the medic class.
autoexec
exec gfx exec demo

You can use the exec command to run other .cfg files. These lines are running gfx.cfg and demo.cfg (shown later in the guide). This is done to avoid cluttering up single files.

//No wep scroll unbind MWHEELUP unbind MWHEELDOWN

Pretty simple - this unbinds mouse scroll changing weapons. I use middle click for many things and this was annoying me mightily. I change weapons with the numbers above the keyboard and Q of course.

//Micspam toggle for WinDJ alias micspamEnable "voice_loopback 1; +voicerecord; unbind V; alias micspamToggle micspamDisable" alias micspamDisable "-voicerecord; bind V +voicerecord; voice_loopback 0; alias micspamToggle micspamEnable" alias micspamToggle micspamEnable bind KP_5 micspamToggle unbind KP_Ins

This is my micspam toggle. Check out this guide for more details.

//Null movement alias +mfwd "-back; +forward; alias checkfwd +forward" alias +mback "-forward; +back; alias checkback +back" alias +mleft "-moveright; +moveleft; alias checkleft +moveleft" alias +mright "-moveleft; +moveright; alias checkright +moveright" alias -mfwd "-forward; checkback; alias checkfwd none" alias -mback "-back; checkfwd; alias checkback none" alias -mleft "-moveleft; checkright; alias checkleft none" alias -mright "-moveright; checkleft; alias checkright none" alias checkfwd none alias checkback none alias checkleft none alias checkright none alias none "" bind w +mfwd bind s +mback bind a +mleft bind d +mright

One of the more helpful scripts around. In default TF2, imagine this scenario: you're pressing right, and you see a rocket coming and want to get out of the way, so you press left in such a hurry you don't let go of right first. What happens? You stop dead because you're pressing left and right at the same time. This script fixes that and makes sure that opposite directions override each other. In the above scenario, you'd start moving left immediately.

//Improved Crouch Jump Script alias +rj "spec_mode; -duck; +cr; alias checkrj +cr"; alias -rj "-cr; checkduck; alias checkrj none"; alias +crouch "-cr; +duck; alias checkduck +duck"; alias -crouch "-duck; checkrj; alias checkduck none"; alias checkduck none; alias checkrj none; alias +cr "+jump; +duck"; alias -cr "-duck; -jump"; alias none ""; bind space +rj; bind ctrl +crouch; bind shift +jump;

Makes every jump into a crouch jump. This is a personal preference, but I find there are a number of advantages: 1) Makes your hitbox smaller and therefore harder to hit; 2) It's a huge convenience to get over annoying jumps like the concrete barrier just outside RED's first spawn on Badwater; 3) It makes it much easier to surf away from enemy explosions.

// Aim zoom alias "+zoom" "zoomin" alias "-zoom" "zoomout" alias zoomin "r_drawviewmodel 0; fov_desired 70" alias zoomout "r_drawviewmodel 1; fov_desired 90" bind "alt" "+zoom"

If you play with FOV on 90 (as you should!) this has the effect of providing a small zoom and hiding the viewmodel. I find it particularly useful sniping engy nests with the ambassador, but I occasionally use it for every class so it's here.

//Suicide bind DEL "explode"

Kill yourself in a spectacular explodey fashion. Always useful to have if you get stuck somewhere, or teletrapped. Just make sure to bind it to a key you wouldn't press by accident!

// Adding text hud_combattext_batching 1 hud_combattext_batching_window 0.5

If you have damage numbers turned on (as you should!) this will add them together for you (as long as, in this case, they are between 0.5 seconds. Especially useful for sustained damage flamethrowers or miniguns.

//Lerp cl_cmdrate 66 rate 60000 cl_interp 0.0152 cl_interp_ratio 1 cl_lagcompensation 1 cl_pred_optimize 2 cl_smooth 1 cl_smoothtime 0.01 cl_updaterate 67

Not sure exactly what this does but it's what a comp friend of mine has in his config, so I'm using it too. It's supposed to smooth out movement, thus making it easier to aim.
engineer
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+attack2" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Sentry jumping alias "+crouchjump" "+attack2; +jump; +duck" alias "-crouchjump" "-attack2; -jump" bind "o" +crouchjump alias "+fire" "lastinv; +attack2" alias "-fire" "-attack2; -duck" bind "p" +fire //Combat engie alias +fastbuildsentry "destroy 2 0;build 2 0;+attack;" alias -fastbuildsentry "-attack;lastinv;" bind "MOUSE3" +fastbuildsentry //Rebinds bind "MOUSE2" "+attack2"

Two main scripts here: the sentry jumping one is a bit old thanks to the rescue ranger that allows you to being your sentry with you afterwards, but it can still be useful. You point your lv 3 at your feet with the wrangler, and press O and then P very quickly. You'll be flying with your sentry in your hand! Very useful to do some silly strategies like get on top of the second point in barnblitz:

1. Build sentry right outside spawn
2. This is where we want to go
3. Point wrangler like this and mash OP quickly
4. Arrived! Now, place an exit down and get some more buildings and friends up there.

The second main one is the combat engie script. What it does is destroy your current sentry and places a new one down. In this case it's bound to middle click and is tremendously useful for when you're an offensive engie with the minisentry and need to constantly redeploy your sentries. Simply hold down and you'll place a new sentry at the next available spot.
medic
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+attack2" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Good Job bind "MOUSE3" "voicemenu 2 7" //Rebinds unbind "o" unbind "p" bind "MOUSE2" "+attack2"

The only interesting thing here is the 'Good Job!' voice command I talked about earlier.
pyro
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+attack2" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Scorch/det jump alias "+bombjump" "+jump;+duck;+attack" alias "-bombjump" "-jump;-duck;-attack" bind "MOUSE3" "+bombjump" //Rebinds unbind "o" unbind "p" bind "MOUSE2" "+attack2"

The middle script is for when you have a detonator or scorch shot. Simply aim down and press middle click! You can pull off some pretty wacky jumps with this, and get places enemies don't expect you: obviously a helpful thing for a pyro. Take 1st stage Goldrush, for instance. You can do all these helpful jumps you wouldn't be able to otherwise:

Directly on top of RED's spawn
On top of the ledge opposite the long corridor from RED spawn
My favourite: going up the drop just above the full health pack
Up the cliffs in front of BLU spawn.
sniper
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+attack2" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Zoom sensitivity zoom_sensitivity_ratio "0.6" //Rebinds unbind "o" unbind "p" unbind "MOUSE3" bind "MOUSE2" "+attack2"

Zoom sensitivity here just lowers your sensitivity when zoomed in. Play around with the value until you find a good balance you like.
soldier
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+finisher" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Shotgun finish alias "+finisher" "slot2" alias "-finisher" "lastinv" bind "MOUSE2" "+finisher" //Rocketjump alias "+bombjump" "+jump;+duck;+attack" alias "-bombjump" "-jump;-duck;-attack" bind "MOUSE3" "+bombjump" //Tele bind "o" "sm_cpsave" bind "p" "sm_cptele"

The first script is why I have to have shift-voicecommand in every file and not just autoexec: m2 is bound to a different action. Speaking of which...

This is a script I came up with personally and I find it tremendously useful. All it does is bind m2 to hold out your shotgun/secondary. As soon as you let go of m2, it reverts back to the weapon you were using before. You can press m1 at the same time to shoot, and simply hold it out to reload (assuming you have autoreload on, which you should). Immensely helpful for popping people up into the air and finishing them off, or taking potshots at fleeing enemies. Note: this does ♥♥♥♥ up the secondary fire of the cow mangler, but I think that's a small price to pay as the cow mangler is pretty low tier IMO.

The next script is a rocketjumping script, identical to the pyro one in fact. I know people might call me a noob for using one but I'm lefthanded and therefore contorting my right hand to press WASD, Ctrl, and Space at the same time is very difficult. Regardless, it works perfectly for the vast majority of rocketjumping maps as well.

The last script is for rocketjumping servers that use a checkpoint system, including mine (at nocf.wawgame.eu). When you're on solid ground, O will save your position and P will teleport you back to it.
spy
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+attack2" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Last disguise bind "MOUSE3" "lastdisguise" //Rebinds unbind "o" unbind "p" bind "MOUSE2" "+attack2"

A very simple bind that moves the 'last disguise' command to middle mouse click for easier access. Make sure to switch your disguises around every so often!
demoman + heavyweapons + scout
//Shift-VoiceCommand alias +voice "bind "MOUSE1" "m1voice"; bind "MOUSE2" "m2voice" alias -voice "bind "MOUSE1" "+attack"; bind "MOUSE2" "+attack2" alias m1voice "Voicemenu 0 6;" alias m2voice "voicemenu 0 7;" Bind shift "+voice" //Rebinds unbind "o" unbind "p" unbind "MOUSE3" bind "MOUSE2" "+attack2"

I don't have any special binds for these classes so this goes in all three .cfg files. It's a simple shift-m1: 'Yes', shift-m2: 'No' for quick acknowledgement of instructions and whatnot. I also have all my unbinds from other class-specific .cfg files.
demo + gfx
exec demo exec gfx

You're probably wondering what these lines at the very top of my autoexec file were.

demo.cfg is a file I got from here[gamebanana.com]: it records demos by pressing the F6 key. Pretty handy.

gfx.cfg is a performance config I got by using this service[clugu.com]: I'm on a laptop, and every little bit of fps helps!
Conclusion
I hope this was helpful in showing you how to use scripts and hopefully setting you on the path to use your own. If you want to know the commands, this is the place to go.

If you want to find more examples of scripts, you could go here[gamebanana.com], here, or simply google 'tf2 scripts' and you'll find a bunch.

One final note, just to reiterate: scripts are not cheating. They simply automate what can already be done naturally. Don't feel awkward about using them.

Have fun and happy scripting!

78 Comments
Mori 3 Aug, 2023 @ 6:07pm 
I can't find the cfg files
Morbillionaire 15 Jun, 2023 @ 5:20pm 
I think a better way to rebind keys every time you switch class is to copy the current setting from config.cfg and paste them into config_default.cfg and exec that at the start of every class cfg. I just did this and haven't noticed any downsides, for reference this is what my soldier.cfg looks like

exec config_default

//Market garden
alias +Trolldier Slot3
alias -Trolldier Slot1

//Shotgun finish
alias "+finisher" "slot2"
alias "-finisher" "lastinv"


bind "MOUSE2" "+finisher"
bind MOUSE4 +Trolldier
bind SHIFT "toggle_duck"
bind "MOUSE1" "+attack; impulse 101"
Quesant 8 Sep, 2022 @ 1:19pm 
nvm i just sus'd it out, if i alias +fireswap "+attack" then alias -fireswap "-attack; lastinv" itl swap when i let go, feelsgoodman
Quesant 8 Sep, 2022 @ 1:13pm 
Any advice on how to make a script that would make you shoot once, then switch with last inv with one press? i tried "+attack; lastinv" but it just swaps weapon and doesnt fire first
david 17 Jul, 2022 @ 2:27am 
The crouch jump script worked for me, but it binded my crouch from shift to the default ctrl. It also for some reason binded my shift to jump. When I tried to bind them back to norm, the script stopped working. Help?
ScoutAndScoot 20 Jan, 2022 @ 5:43pm 
um, does the demo script still work?
Thanks
Józef Pinda 28 Mar, 2021 @ 11:14am 
that second script for soldier is very useful :steamthumbsup:
skilful gamer 20 Nov, 2020 @ 11:34pm 
unnamed: sometimes messing around with .cfg files can mess up your view models. it happened to me on medic
Wh1t3st4r 31 Oct, 2020 @ 10:22am 
Those voice commands lines that you created are the most big brain lines of script that I've ever seen.
Oreos with Salsa 9 Apr, 2020 @ 4:45pm 
The:
cl_cmdrate 66
rate 60000
cl_interp 0.0152
cl_interp_ratio 1
cl_lagcompensation 1
cl_pred_optimize 2
cl_smooth 1
cl_smoothtime 0.01
cl_updaterate 67

Script increases the frequency your computer sends the server data so basically it just improves response time. EVERYONE who plays should have this in the autoexec file.