TrashedDT
December 16th, 2007, 04:57 PM
I got to tweaking around with some TF2 scripts and thought I'd share my successes with you. Also for you noobs I'm including a basic "how to" to get you started. As I test out new scripts that WORK I'll share them in this thread. Let me know if you find bugs and I'll try to fix them. BTW I know some people have mixed feelings about scripts, this is not the place to discuss it. Please kindly make a new thread. Thank you.
So first things first. Navigate to:
..\Program Files\Steam\Steamapps\<username>\team fortress 2\tf\cfg
ALL SCRIPTS MUST BE SAVED TO THIS FOLDER
Reference for keyboard key names
In this folder you will find config.cfg, which is the storage file for all of your keyboard control settings. It's a great reference for later if you don't know the "steam" name for a key on the keyboard. e.g. "; = SEMICOLON" You can just open up your options, map a key you want to know the name of, hit apply, and then check the config.cfg for the name associated with the key.
The Autoloading Config File
How do you get your scripts to autoload in the game? You use the autoexec.cfg. If you have vanilla TF2 (aka freshly installed) then you will not have the autoexec.cfg. So first you want to create it. Go to the "cfg" folder mentioned above and create a new text file and rename it autoexec.cfg. Now any scripts you write to this file will be automatically loaded when you play TF2. Later I'll discuss how you can create more cfg files to customize scripts for each class.
Soldier Uber Rocket Jump
To get you started lets add a script that makes it simple to make a perfect rocket jump as a soldier. In the autoexec.cfg file add the following code
//Rocket Jump
alias +rocketjump "+jump; +duck; wait; +attack"
alias -rocketjump "-jump; -attack; wait; wait; wait; -duck"
bind "f" "+rocketjump"
Now I'm going to break up the different parts of this code to give you an idea of what's going on.
Alias - this is a way of creating your own name for a task or group of tasks. It works as so: alias <createname> <task> *Notice: No Quotes*
alias "<createname>" "<task>; <task>; ....;<task>"
The quotes ' " ' are actual parts of the code. They can always be included, but are only necessary if your writing tasks with spaces inbetween them. So in the first line this script creates an alias called +rocketjump associated to the four commands: +jump, +duck, wait, and +attack. Because there is more than one command quotes must be used to include them in the alias. The plus '+' is used to signify that the action is started, like pressing and holding a key down on the keyboard. The minus '-' is used to signify that the action is stopped, like releasing your finger from a key. If you use an alias to define a custom action like +rocketjump you must define the -rocketjump as well. If you don't the game will never release the rocketjump command and you'll find yourself stuck in a loop. If you are attaching more than one task to an alias each task must be separated by a semicolon ';'.
The last line binds the alias to a key on the keyboard. In this case the quotes are optional, but it's always a good idea to include them just in case.
Can I Have A Script For Each Class?
You most certainly can! And it actually is better if you have a lot of scripts. Let's say you want to bind the bat of the scout to the right click of the mouse, but you don't want to interfere with the exploding of the demoman's sticky bombs. Separate scripts loaded at time of respawn resolve this problem.
To start off you need to create a "cfg" file for each class. Go to the cfg folder and create 9 text files. Rename each one to represent each class and use the extension ".cfg". The names I used were as follows: Scout.cfg, Soldier.cfg, Pyro.cfg, Demo.cfg, Heavy.cfg, Engineer.cfg, Medic.cfg, Sniper.cfg, and Spy.cfg. Now to use the following scripts in game open up your autoexec.cfg and copy and paste the following code into it:
//Class Config Switcher with Config Loader
alias scout "play vo\scout_battlecry01; join_class scout;exec scout.cfg; developer 1; echo ::Scout Config Loaded::; wait 200; developer 0"
alias soldier "play vo\soldier_battlecry01; join_class soldier; exec soldier.cfg; developer 1; echo ::Soldier Config Loaded::; wait 200; developer 0"
alias pyro "play vo\pyro_battlecry01; join_class pyro; exec pyro.cfg; developer 1; echo ::Pyro Config Loaded::; wait 200; developer 0"
alias demo "play vo\demoman_battlecry01; join_class demoman; exec demo.cfg; developer 1; echo :Demoman Config Loaded::; wait 200; developer 0"
alias heavy "play vo\heavy_battlecry01; join_class heavyweapons; exec heavy.cfg; developer 1; echo ::Heavy Config Loaded::; wait 200; developer 0"
alias engineer "play vo\engineer_battlecry01; join_class engineer; exec engineer.cfg; developer 1; echo ::Engineer Config Loaded::; wait 200; developer 0"
alias medic "play vo\medic_battlecry01; join_class medic; exec medic.cfg; developer 1; echo ::Medic Config Loaded::; wait 200; developer 0"
alias sniper "play vo\sniper_battlecry01; join_class sniper; exec sniper.cfg; developer 1; echo ::Sniper Config Loaded::; wait 200; developer 0"
alias spy "play vo\spy_battlecry01; join_class spy; exec spy.cfg; developer 1; echo ::Spy Config Loaded::; wait 200; developer 0"
bind KP_END "scout"
bind KP_DOWNARROW "soldier"
bind KP_PGDN "pyro"
bind KP_LEFTARROW "demo"
bind KP_5 "heavy"
bind KP_RIGHTARROW "engineer"
bind KP_HOME "medic"
bind KP_UPARROW "sniper"
bind KP_PGUP "spy"
This bit of code will bind each config file to the numeric keypad from 1-9 in the order of the file names I listed above in bold. *Note* This can be problematic for laptop users as often the numeric keypad is embedded among the letter keys and toggled with a function key. If this is the case simple replace the bindings to meet your needs. Again a great way to find the name of the binds is to assign them in the games option control menu and then look in the config.cfg file for the resulting name listed.
Now you can place whatever scripts you want into each class config file. I'm including my current config files in a zip file. I've been playing around with these for fun for the last week. Use at your own risk, they are a little buggy. If you have questions about a certain line I will answer in the subsequent posts, but not in this initial post.
Including commands in your scripts
Any command you type in the console can be executed in a script. Simply put the command on it's own line or separate commands with ';'. Every line and group separated by a semicolon in the above code is actually a command that you can type in the console.
How do I prevent my scout scripts from messing up my sniper scripts?
You may want to bind the right click for melee as scout and zoom as a sniper, but you find that some of your scripts get screwed up when you change class. There is hope! I call it default.cfg!!! Basically its just a copy of your config.cfg before binding anything special to it with extra lines of code removed. Here is how you make it.
1. Open TF2 and go to options.
2. Bind all your keys for general gameplay like you would if you had no scripts.
3. Save the settings and exit TF2.
4. Now go to your cfg folder and open config.cfg.
5. At the same time in the cfg folder create a new file called default.cfg.
6. Now, in the config.cfg file, highlight every line that starts with the word "bind". There is about 68 lines of binding.
7. Paste these into your default.cfg file and save it.
That's all there is to making the file. Now we need to implement it.
8. Open each of your class config files and add to the top of each the line:
exec default.cfg
exec autoexec.cfg //This can also be added depending on how your scripts
//are set up.
So first things first. Navigate to:
..\Program Files\Steam\Steamapps\<username>\team fortress 2\tf\cfg
ALL SCRIPTS MUST BE SAVED TO THIS FOLDER
Reference for keyboard key names
In this folder you will find config.cfg, which is the storage file for all of your keyboard control settings. It's a great reference for later if you don't know the "steam" name for a key on the keyboard. e.g. "; = SEMICOLON" You can just open up your options, map a key you want to know the name of, hit apply, and then check the config.cfg for the name associated with the key.
The Autoloading Config File
How do you get your scripts to autoload in the game? You use the autoexec.cfg. If you have vanilla TF2 (aka freshly installed) then you will not have the autoexec.cfg. So first you want to create it. Go to the "cfg" folder mentioned above and create a new text file and rename it autoexec.cfg. Now any scripts you write to this file will be automatically loaded when you play TF2. Later I'll discuss how you can create more cfg files to customize scripts for each class.
Soldier Uber Rocket Jump
To get you started lets add a script that makes it simple to make a perfect rocket jump as a soldier. In the autoexec.cfg file add the following code
//Rocket Jump
alias +rocketjump "+jump; +duck; wait; +attack"
alias -rocketjump "-jump; -attack; wait; wait; wait; -duck"
bind "f" "+rocketjump"
Now I'm going to break up the different parts of this code to give you an idea of what's going on.
Alias - this is a way of creating your own name for a task or group of tasks. It works as so: alias <createname> <task> *Notice: No Quotes*
alias "<createname>" "<task>; <task>; ....;<task>"
The quotes ' " ' are actual parts of the code. They can always be included, but are only necessary if your writing tasks with spaces inbetween them. So in the first line this script creates an alias called +rocketjump associated to the four commands: +jump, +duck, wait, and +attack. Because there is more than one command quotes must be used to include them in the alias. The plus '+' is used to signify that the action is started, like pressing and holding a key down on the keyboard. The minus '-' is used to signify that the action is stopped, like releasing your finger from a key. If you use an alias to define a custom action like +rocketjump you must define the -rocketjump as well. If you don't the game will never release the rocketjump command and you'll find yourself stuck in a loop. If you are attaching more than one task to an alias each task must be separated by a semicolon ';'.
The last line binds the alias to a key on the keyboard. In this case the quotes are optional, but it's always a good idea to include them just in case.
Can I Have A Script For Each Class?
You most certainly can! And it actually is better if you have a lot of scripts. Let's say you want to bind the bat of the scout to the right click of the mouse, but you don't want to interfere with the exploding of the demoman's sticky bombs. Separate scripts loaded at time of respawn resolve this problem.
To start off you need to create a "cfg" file for each class. Go to the cfg folder and create 9 text files. Rename each one to represent each class and use the extension ".cfg". The names I used were as follows: Scout.cfg, Soldier.cfg, Pyro.cfg, Demo.cfg, Heavy.cfg, Engineer.cfg, Medic.cfg, Sniper.cfg, and Spy.cfg. Now to use the following scripts in game open up your autoexec.cfg and copy and paste the following code into it:
//Class Config Switcher with Config Loader
alias scout "play vo\scout_battlecry01; join_class scout;exec scout.cfg; developer 1; echo ::Scout Config Loaded::; wait 200; developer 0"
alias soldier "play vo\soldier_battlecry01; join_class soldier; exec soldier.cfg; developer 1; echo ::Soldier Config Loaded::; wait 200; developer 0"
alias pyro "play vo\pyro_battlecry01; join_class pyro; exec pyro.cfg; developer 1; echo ::Pyro Config Loaded::; wait 200; developer 0"
alias demo "play vo\demoman_battlecry01; join_class demoman; exec demo.cfg; developer 1; echo :Demoman Config Loaded::; wait 200; developer 0"
alias heavy "play vo\heavy_battlecry01; join_class heavyweapons; exec heavy.cfg; developer 1; echo ::Heavy Config Loaded::; wait 200; developer 0"
alias engineer "play vo\engineer_battlecry01; join_class engineer; exec engineer.cfg; developer 1; echo ::Engineer Config Loaded::; wait 200; developer 0"
alias medic "play vo\medic_battlecry01; join_class medic; exec medic.cfg; developer 1; echo ::Medic Config Loaded::; wait 200; developer 0"
alias sniper "play vo\sniper_battlecry01; join_class sniper; exec sniper.cfg; developer 1; echo ::Sniper Config Loaded::; wait 200; developer 0"
alias spy "play vo\spy_battlecry01; join_class spy; exec spy.cfg; developer 1; echo ::Spy Config Loaded::; wait 200; developer 0"
bind KP_END "scout"
bind KP_DOWNARROW "soldier"
bind KP_PGDN "pyro"
bind KP_LEFTARROW "demo"
bind KP_5 "heavy"
bind KP_RIGHTARROW "engineer"
bind KP_HOME "medic"
bind KP_UPARROW "sniper"
bind KP_PGUP "spy"
This bit of code will bind each config file to the numeric keypad from 1-9 in the order of the file names I listed above in bold. *Note* This can be problematic for laptop users as often the numeric keypad is embedded among the letter keys and toggled with a function key. If this is the case simple replace the bindings to meet your needs. Again a great way to find the name of the binds is to assign them in the games option control menu and then look in the config.cfg file for the resulting name listed.
Now you can place whatever scripts you want into each class config file. I'm including my current config files in a zip file. I've been playing around with these for fun for the last week. Use at your own risk, they are a little buggy. If you have questions about a certain line I will answer in the subsequent posts, but not in this initial post.
Including commands in your scripts
Any command you type in the console can be executed in a script. Simply put the command on it's own line or separate commands with ';'. Every line and group separated by a semicolon in the above code is actually a command that you can type in the console.
How do I prevent my scout scripts from messing up my sniper scripts?
You may want to bind the right click for melee as scout and zoom as a sniper, but you find that some of your scripts get screwed up when you change class. There is hope! I call it default.cfg!!! Basically its just a copy of your config.cfg before binding anything special to it with extra lines of code removed. Here is how you make it.
1. Open TF2 and go to options.
2. Bind all your keys for general gameplay like you would if you had no scripts.
3. Save the settings and exit TF2.
4. Now go to your cfg folder and open config.cfg.
5. At the same time in the cfg folder create a new file called default.cfg.
6. Now, in the config.cfg file, highlight every line that starts with the word "bind". There is about 68 lines of binding.
7. Paste these into your default.cfg file and save it.
That's all there is to making the file. Now we need to implement it.
8. Open each of your class config files and add to the top of each the line:
exec default.cfg
exec autoexec.cfg //This can also be added depending on how your scripts
//are set up.