Go Back   Steam Users' Forums > Steam Game Discussions > T - Z > Team Fortress 2 > New Users / Training

Reply
Click here to go to the first staff post in this thread.  
Thread Tools Display Modes
Old 08-01-2008, 10:24 AM   #1
AciD
 
AciD's Avatar
 
Volunteer Moderator
Join Date: Sep 2007
Reputation: 2278
Posts: 13,874
Post TF2 Scripting Tutorial

Welcome to my scripting guide!
You may learn here basics of scripting in TF2.

For editing CFG files I recommend using Notepad + +.

All things mentioned here should be saved in your user config.
How you can make your own config? Where it should be placed?

Your TF2 cfg folder where you put all your configs should be located in:
C:\Program Files\Steam\steamapps\%accountame%\team fortress 2\tf\cfg
C:\Program Files\Valve\Steam\steamapps\%accountame%\team fortress 2\tf\cfg
Where %accountname% is your Steam login.

To save your config as a cfg file when you are saving file pick from file type dropdown All files (*.*), but when you are using this method you need to type file name and extension. For exapmle myconfig.cfg

Now open autoexec.cfg
and add a line
exec configname
where configname is name of config that you have chosen recently.

In your CFG folder you can find configs with class names in titles, they are executed every time you select that class.

Note:If you cant see file extension in file name please follow this guide.

Numpad key names
Code:
"KP_MINUS"        Minus
"KP_PLUS"         Plus 
"KP_Enter"        Enter
"KP_DEL"          ,
"KP_INS"          0
"KP_END"          1
"KP_DOWNARROW"    2
"KP_PGDN"         3
"KP_LEFTARROW"    4
"KP_5"            5
"KP_RIGHTARROW"   6
"KP_HOME"         7
"KP_UPARROW"      8
"KP_PGUP"         9
"KP_SLASH"        /
"KP_MULTIPLY"     *



Binding



Binding is basically assigning commands to keys
Code:
bind "key" "command"


If you want to assign multiple commands divide them by ;
Code:
bind "key" "command; command; command"

Example №1: You want to bind reload to a specified key:
Code:
bind "key" "+reload"


Example №2: You want to bind taunt and explode commands to same key
Code:
bind "key" "taunt; wait 30; explode"




Incrementvar
That command allows you cycle between specified values on chosen range.
Code:
bind "key" "incrementvar command 1 12 3
(where 1 and 12 is range and 3 is jump between values)

Example №1: You want to change sensitivity from one to twenty with 2 points jump.
Code:
bind "key" "incrementvar sensitivity 1 20 2"


Example №2: You want to switch between 3 basic net_graph positions with one click.

Code:
bind "key" "incrementvar net_graphpos 1 3 1"


Aliasing
Alias command allows you to shorten very long commands into one short alias.
Code:
alias nameofyourscript "firstalias"
alias firstalias "command; command; alias nameofyourscript secondalias" 
alias secondalias "command; command; alias nameofyourscript thirdalias"
alias thirdalias "command; alias nameofyourscript firstalias" //last alias should point to first one


Note: you can use as many aliases as you want, same with commands.


Example №1: Lets say that we want a name changing script.
Code:
alias namescr "firstname" 
alias firstname "setinfo name "First_name"; alias namescr secondname" 
alias secondname "setinfo name "Second_name"; alias namescr thirdname"
alias thirdname "setinfo name "Third-name"; alias namescr firstname"

bind "key" namescr


Note: That script does not allow spaces in names, if you want space in your nick look below.

Example №2: Duck script. Second example will be a duck script that will allow you to duck without holding a key.
Code:
alias duck "duckON"
alias duckON "+duck; alias duck duckOFF"
alias duckOFF "-duck; alias duck duckON"
bind "key" "duck"


Example №3: You and your friend are playing at same PC, both of you have different keybindings. There is a easy solution for this!
Code:
alias configsw "yourconfig"
alias yourconfig "exec yourconfig; developer 1; echo Yourconfig.cfg; wait 250; developer 0; alias configsw friendconfig"
alias friendconfig "exec friendconfig; developer 1; echo Friendconfig.cfg; wait 250; developer 0; alias configsw yourconfig"
bind "key" "configsw"

This should be used if you want to switch names in game and your names have spaces.

+ and - commands
Plus and Minus commands are commands that have 2 states.
Plus part is executed when you press a key and it's execute until key is released. When key is released it goes into minus state.
Example:
Code:
bind "mouse1" "+attack"


You aren't limited to commands that developers created. You can create your own using alias command.
Code:
alias +minigun "+duck; +attack"
alias -minigun "-attack; -duck"
bind "key" "+minigun"

As you probably noticed, there is no need to bind minus command, it's executed automatically after you stop holding key that you bound it to.

Useful scripting commands:
Code:
"wait"             Stop command parsing until next frame.(if you put a value ex: wait 30 it will wait 30 frames)
"exec"             Executes user config
"bind"             Binds command to key (bind "F1" "kill")
"unbind"           Unbinds command (unbind "F1")


Pyro loadout binds
Equip command doesn't exist since 2009-02-17.

Heavy loadout binds
Equip command doesn't exist since 2009-02-17.

Medic loadout binds
Equip command doesn't exist since 2009-02-17.

Engineer buildables binds
Paste this into Engineer.cfg
Code:
echo **Execing Engineer Config**
bind "KP_ENTER"          "build 3"     //Builds Sentry
bind "KP_PGDN"           "build 0"     //Builds Dispenser
bind "KP_DOWNARROW"      "build 1"     //Builds Teleport Entrance
bind "KP_END"            "build 2"     //Builds Teleport Exit
bind "KP_PLUS"           "destroy 3"   //Destroy Sentry
bind "KP_RIGHTARROW"     "destroy 0"   //Destroy Dispenser
bind "KP_5"              "destroy 1"   //Destroy Teleport Entrance
bind "KP_LEFTARROW"      "destroy 2"   //Destroy Teleport Exit


Spy cloak weapon switcher
Code:
alias disg "primaryweapon"
alias primaryweapon "slot1;lastdisguise;alias disg secondaryweapon"
alias secondaryweapon "slot2;lastdisguise;alias disg meleeweapon"
alias meleeweapon "slot3;lastdisguise;alias disg primaryweapon"

bind "b" "disg"


Visual problems fix
You got lagged or you alt-tabbed out of game and you got a visual problems?
That is fix for misplaced items, players holding wrong weapons, invisible players, missing cart indicator and wrong team color models(Blue medic with red needle gun)

Code:
bind "home" "record fix; stop"


Stopping music that is played on server
Admin is playing annoying music and you don't want to disable sounds downloading?
Use that bind to stop music:

Code:
bind "key" "play common/null"


Console commands
Basic gameplay
Code:
"+forward"                      Move forward
"+back"                         Move back
"+moveleft"                     Move left
"+moveright"                    Move right
"+jump"                         Jump
"+duck"                         Duck
"+moveup"                       Swim up
"+movedown"                     Swim down
"+attack"                       Primary attack
"+attack2"                      Secondary attack
"+reload"                       Reload weapon
"slot1"                         Weapon category 1
"slot2"                         Weapon category 2
"slot3"                         Weapon category 3
"slot4"                         Weapon category 4
"slot5"                         Weapon category 5
"invprev"                       Previous weapon
"invnext"                       Next Weapon
"lastinv"                       Last used weapon
"taunt"                         Taunt
"dropitem"                      Drop item(intelligence)
"changeteam"                    Change team menu
"changeclass"                   Change class menu
"lastdisguise random"           [Spy]Random disguise (no Spy/Scout)


Spy Disguises
Code:
"disguise 1 2"                  Red Scout
"disguise 2 2"                  Red Sniper
"disguise 3 2"                  Red Soldier 
"disguise 4 2"                  Red Demoman
"disguise 5 2"                  Red Medic
"disguise 6 2"                  Red Heavy
"disguise 7 2"                  Red Pyro
"disguise 8 2"                  Red Spy
"disguise 9 2"                  Red Engi


"disguise 1 1"                  Blue Scout
"disguise 2 1"                  Blue Sniper
"disguise 3 1"                  Blue Soldier
"disguise 4 1"                  Blue Demoman
"disguise 5 1"                  Blue Medic   
"disguise 6 1"                  Blue Heavy
"disguise 7 1"                  Blue Pyro  
"disguise 8 1"                  Blue Spy
"disguise 9 1"                  Blue Engi



Communication
Code:
"+voicerecord"	  Voice communication
"say"             Chat message(Public chat)
"say_team"        Chat message(Team chat)
"voice_menu_1"	  1st Voice menu
"voice_menu_2"	  2nd Voice menu
"voice_menu_3"	  3rd Voice menu

"voicemenu 0 0"   Medic!
"voicemenu 0 1"   Thanks!
"voicemenu 0 2"   Go go go!
"voicemenu 0 3"   Move up!
"voicemenu 0 4"   Flank left!
"voicemenu 0 5"   Flank right!
"voicemenu 0 6"   Yes!
"voicemenu 0 7"   No!

"voicemenu 1 0"   Incoming!
"voicemenu 1 1"   Spy!
"voicemenu 1 2"   Sentry ahead!
"voicemenu 1 3"   Need a Teleporter here!
"voicemenu 1 4"   Need a Dispenser here!
"voicemenu 1 5"   Need a Sentry here!
"voicemenu 1 6"   Activate UberCharge!
"voicemenu 1 7"  (MEDIC) UberCharge Ready!

"voicemenu 2 0"   Help!
"voicemenu 2 1"   Battle Cry
"voicemenu 2 2"   Cheers
"voicemenu 2 3"   Jeers
"voicemenu 2 4"   Positive
"voicemenu 2 5"   Negative
"voicemenu 2 6"   Nice shot!
"voicemenu 2 7"   Good job!


Netgraph commands
Code:
"net_graph"           Enable/disable netgraph (2-4 advanced modes)
"net_graphheight"     Height of netgraph
"net_graphpos 3"      Position of netgraph (3-left 2-middle 1-right)


Demo commands
Note: Shift+F2 brings demoui
Code:
"cl_demoviewoverride"  Override player view when you are playing a demo
"demoui"               Show hide demo controlling interface

"demoui2"              Show hide demo controlling interface(diffrent look than normal one)
"demolist"             Show list of demos
"record demoname"      Records a demo (replace demoname with name of your demo)
"stop"                 Stops demo recording


Server/Multiplayer commands
Code:
"cl_downloadfilter"        None-enables  downloading files, nosounds-disables downloading sounds, all-disables downloading files
"mp_autoteambalance"       Enables/Disables team balance
"mp_decals"                Number of rendered decals
"mp_maxrounds"             Number of rounds that could be played before map change
"mp_restartround"          If non-zero round will be restarted in x seconds
"mp_teams_unbalance_limit" Teams are unbalanced when one team has this many more players than the other team
"mp_timelimit"             Time limit per map
"mp_winlimit"              Maximal number of rounds that team can win before map changes
"sv_allowdownload"         Allows/Disallows downloading files
"sv_allowupload"           Allows/Disallows uploading files
"sv_alltalk"               Allows both teams to hear each other
"sv_gravity"               Determines gravity on server(800 by default)
"sv_lan"                   Makes your server LAN only
"sv_hltv"                  Activates HLTV
"sv_password"              Sets server password
"sv_pausable"              Enables/Disables ability to pause game
"sv_voiceenable"           Enables/Disables voice chat


Misc useful commands

Code:
"exit"                   hmm... Closes game?
"kill"                   Kills yourself
"explode"                Kills yourself(you explode)
"hud_fastswitch"         Turns fastswitch (0 disables 1 enables 2 disables [consoles style]) 
"showmapinfo"            Shows info about map
"+showscores"            Shows scroreboard
"impulse 201"            Sprays your logo
"toggleconsole"          Opens console
"screenshot"             Makes a screenshot (TGA)
"jpeg"                   Makes a screenshot (JPEG)
"fps_max"                Limits your FPS
"mat_bumpmap"            Enables/Disables bumpmapping 
"mat_compressedtextures" Enables/Disables textures compression 
"mat_dxlevel"            Sets DirectX level
"mat_specular"           Enables/Disables spectacular lighting
"cl_showfps"             Shows fps, but not netgraph statistics (upper left)
"mat_picmip"             (-10 min., 4 max) - Changes texture quality, -1 = Very High.
"cl_drawhud"             Disalbes the hud, useful for taking screenshots.
"hidepanel all"          Hides the panels, useful for taking screenshots.
"jpeg_quality"           (0-100) - Changes the qualtiy of jpeg screenshots, 90 = default.


Multithreading commands

Code:
"mat_queue_mode -1"      Autodetection, enables threaded rendering if you have multiple cores
"mat_queue_mode 0"       Disables threaded rendering
"mat_queue_mode 2"       Enables threaded rendering it even if you don't have multiple cores
You can also change those settings in Options > Video > Advanced.

Last edited by AciD: 03-08-2011 at 12:24 PM.
AciD is offline  
Reply With Quote
Old 08-01-2008, 10:31 AM   #2
AciD
 
AciD's Avatar
 
Volunteer Moderator
Join Date: Sep 2007
Reputation: 2278
Posts: 13,874
Placeholders

Last edited by AciD: 08-04-2008 at 04:01 AM.
AciD is offline   Reply With Quote
Old 08-01-2008, 10:32 AM   #3
waebi
 
Join Date: Dec 2007
Reputation: 3
Posts: 596
Sweet, this should clarify some things for all new players. Maybe add a section about the console, how it works/can be activated/whatever
edit: acid beat me, dammit
waebi is offline   Reply With Quote
Old 08-01-2008, 10:41 AM   #4
richard.eid
 
 
 
Join Date: Jul 2006
Reputation: 2169
Posts: 5,137
Yeah, great job on this, AciD! This is a great tutorial for everyone getting started.

How many slices do you want for this?
richard.eid is offline   Reply With Quote
Old 08-01-2008, 10:47 AM   #5
FrostbiteX
 
 
 
Join Date: Sep 2004
Reputation: 195
Posts: 6,653
Nice job AciD.
FrostbiteX is offline   Reply With Quote
Old 08-01-2008, 11:11 AM   #6
Sti_Striker
 
Join Date: Apr 2008
Reputation: 14
Posts: 421
Sticky????
Sti_Striker is offline   Reply With Quote
Old 08-01-2008, 12:02 PM   #7
remmeh
 
Join Date: Mar 2008
Reputation: 0
Posts: 151
definitely sticky-worthy
remmeh is offline   Reply With Quote
Old 08-01-2008, 12:17 PM   #8
bFusion
 
Join Date: Feb 2008
Reputation: 13
Posts: 831
Very nice, thank you very much. I created some scripts for Pyro and Medic for weapon swapping a long time ago, they are insanely useful.

A+++ WILL READ FROM USER AGAIN!
bFusion is offline   Reply With Quote
Old 08-01-2008, 12:33 PM   #9
biggs_ff
 
 
 
Join Date: Dec 2007
Reputation: 1
Posts: 285
Very well put together man.


/sticky
biggs_ff is offline   Reply With Quote
Old 08-01-2008, 12:41 PM   #10
CannibalBob
 
 
 
Join Date: Jan 2008
Reputation: 469
Posts: 6,582
Did not know about incrementvar but the rest I knew about from fpsbanana and tf2wiki.

Anyway about scripts: There is 1 script I really want to make, and it is 'auto demo'. What I want it to do is automatically record a demo when you spawn, and stop recording when you die. I don't think it's possible atm because .cfg files only execute when you select a class or when tf2 starts. For some reason, valve decided to not put in conditions into scripts, which is a bummer.

I would use aliases and some keys to make it 'save' a demo, so for example after I die, you press home and it 'saves' that demo. If you don't, then it pretty much overwrites that demo when you die again.

If anyone can think about a creative way to make it automatically record a demo, then PM me or post here.
CannibalBob is offline   Reply With Quote
Old 08-01-2008, 01:34 PM   #11
dustbunny
 
Banned
Join Date: May 2006
Reputation: 0
Posts: 19,421
Awesome work.
dustbunny is offline   Reply With Quote
Old 08-01-2008, 01:37 PM   This is the last staff post in this thread.   #12
MikeBlaszczak
 
MikeBlaszczak's Avatar
 
Valve
Join Date: Feb 2007
Reputation: 4662
Posts: 5,061
Thanks for putting this together, Acid. I made it a sticky.
MikeBlaszczak is offline   Reply With Quote
Old 08-01-2008, 02:03 PM   #13
Tharg
 
 
 
Join Date: Apr 2008
Reputation: 404
Posts: 1,700
It says "echo **Execing Medic Config**" in the Engineer buildings one.

Nice post.
Tharg is offline   Reply With Quote
Old 08-01-2008, 02:05 PM   #14
AciD
 
AciD's Avatar
 
Volunteer Moderator
Join Date: Sep 2007
Reputation: 2278
Posts: 13,874
Quote:
Originally Posted by Tharg View Post
It says "echo **Execing Medic Config**" in the Engineer buildings one.

Nice post.
Thanks for pointing out

Edit:Fixed
AciD is offline   Reply With Quote
Old 08-01-2008, 02:11 PM   #15
Sierra Oscar
 
Sierra Oscar's Avatar
 
Volunteer Moderator
Join Date: Dec 2005
Reputation: 6782
Posts: 44,758
Quote:
Originally Posted by MikeBlas View Post
Thanks for putting this together, Acid. I made it a sticky.
Beat me to it . . .

Great work Acid.
Sierra Oscar is offline   Reply With Quote
Reply

Go Back   Steam Users' Forums > Steam Game Discussions > T - Z > Team Fortress 2 > New Users / Training


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -7. The time now is 10:49 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2012, All Rights Reserved.