/r/Tf2Scripts

Photograph via snooOG

Come here for all your TF2 scripting needs. Please don't post anything except content associated with scripting.


Submission guidelines:

For readability,
please format scripts and snippets.
Begin each line with 4 spaces
  • Bulk formatting:

  • If you need more help, reply directly to the response comments, not a general reply.

  • We have a tutorial on the wiki! Check it out if you want a primer on Source commands.


  • Common troubleshooting tips:

    Reset all binds: exec config_default

    Reset all cvars: steam://runsafe/440


    Make sure to read the rules before posting. Read the Rules

    New to scripts? Script got you stumped? Start here.

    Help!

    If it's 2D and on your screen, it's not a script.

    HUDs

    Can't remember the name of that command? Want to know if something is possible?

    Ask a question

    Can't find something previously requsted?

    Request a script

    Show off your work. Tools are also welcome.

    Submit a script

    Found a new command/cvar? Want feedback or opinions? Discuss!

    Start a discussion

  • Tutorials
  • Reference
  • Example Scripts
  • Closed Captions
  • Hitsounds
  • View all pages
  • FAQ/Help!
  • User pages
  • Filter
  • Processed
  • Untagged
  • Unverified
  • Related subreddits
    • Get help with ideas and existing scripts there
  • /r/TF2HUDs
    • For all your HUD needs
  • /r/TF2TechSupport
    • Get help when TF2 breaks
  • /r/Sprays+TF2Sprays
    • Sprays and spray requests
  • /r/MannWorkshop
    • Maps, models and skins
  • /r/TF2Developers
    • External tools for TF2
  • /r/TF2Files
    • Sprays, hitsounds, skins

    /r/Tf2Scripts

    2,705 Subscribers

    1

    crosshair help please

    I made these crosshairs that im using as "indicators" for my engineer script so you know what building you chose from the scrollwheel, they work just fine in my own custom match but there missing textures in casual, also they disappear from the crosshair picker https://youtu.be/smMUCCFhoVk video to demistrate what im talking about, does anyone know how i can build 5 custom crosshairs into a hud, then switch them using a script so it works in casual?

    0 Comments
    2024/10/29
    01:24 UTC

    3

    Switch to secondary weapon when two keys are pressed simultaneously

    Hello, I wonder if you can help me write a script to put in my autoexec file please?

    Requirements:

    mouse5 equips the weapon in slot1

    mouse4 equips the weapon in slot3

    When mouse5 and mouse4 are pressed simultaneously, the weapon in slot2 is equipped.

    Any help appreciated

    1 Comment
    2024/10/28
    22:53 UTC

    3

    Switch Sensitivity with last weapon used "bind "q" "lastinv"

    Trying to have some varied sensitivities between both weapons and classes. I'm a crusty little spy main sorry people and I need more knife sens for those surf stabs. Here's what I have in all my class cfgs

    bind "MOUSE5" "slot1; sensitivity 0.85; r_drawviewmodel 0"

    bind "e" "slot2; sensitivity 0.85; r_drawviewmodel 1"

    bind "c" "slot3; sensitivity 1; r_drawviewmodel 1"

    How do I make that work with

    bind "q" "lastinv"

    I mostly use q to switch weapons, but occasionally I use my normal binds (mouse5, e, c, and 4). For people wondering why it's so weird, it's so I can moving or autosap etc without letting go of wasd.

    Also, I have a great dmg_sound randomizer script if people want that for fun.

    Thanks!

    3 Comments
    2024/10/26
    01:30 UTC

    3

    Need help with Pyro script bleeding into all other classes!

    This is the pyro script to remove viewmodels for primary, but not for secondary and melee. I am using Mastercomfig!!

    //Start of Script

    exec reset

    bind 1 eq_slot1

    bind 2 eq_slot2

    bind 3 eq_slot3

    alias set_slot1 "viewmodel_fov 1"

    alias set_slot2 "viewmodel_fov 90"

    alias set_slot3 "viewmodel_fov 90"

    alias eq_slot1 "slot1; set_slot1; alias eq_invnext eq_slot2; alias eq_invprev eq_slot3; qs_slot1; alias set_lastinv alias eq_lastinv eq_slot1; alias qs_slot1 ; alias qs_slot2 set_lastinv; alias qs_slot3 set_lastinv"

    alias eq_slot2 "slot2; set_slot2; alias eq_invnext eq_slot3; alias eq_invprev eq_slot1; qs_slot2; alias set_lastinv alias eq_lastinv eq_slot2; alias qs_slot1 set_lastinv; alias qs_slot2 ; alias qs_slot3 set_lastinv"

    alias eq_slot3 "slot3; set_slot3; alias eq_invnext eq_slot1; alias eq_invprev eq_slot2; qs_slot3; alias set_lastinv alias eq_lastinv eq_slot3; alias qs_slot1 set_lastinv; alias qs_slot2 set_lastinv; alias qs_slot3"

    eq_slot1

    alias eq_lastinv eq_slot2

    r_drawviewmodel 1

    //End of script

    However, not only does this mean that for every other class when I equip my primary there are no viewmodels, it also means that my binds for equipping slot 1, 2, 3 etc don't work until I pick pyro.

    How do I make it so this script only applies to Pyro, and furthermore I can switch slots on other classes before picking Pyro?

    3 Comments
    2024/10/25
    17:55 UTC

    1

    Anyone know how to make a spy disguised as an engineer take out the engi's PDA consistently?

    Me and u/-oOAegisOo- were coming up with different iterations of what has most recently become this script, and during the course of playtesting I expiremented with something akin to-

    bind "4" "slot4;bind T Die;lastdisguise"

    (disclaimer: Can't recall if that was the exact code)

    -and for a moment it actually worked on a random-arse casual server. While disguised as engineer, my disguise took out its PDA and was holding it while I had my cigarrete case up.

    The problem I bumped into shortly afterward was that pressing 4 while disguised as a pyro caused the disguise kit to come up and immedietely close, with my disguise reverting to its melee weapon. After that happened, I couldn't get it to work on engineer again, even after restarting the game multiple times now. The only thing I can think of that's different is the server was originally empty when I first tested the slot4;lastdisguise code, then some people joined, I swapped to pyro for a sec to get some nuisance off our spawn and after that it's never functioned again. Might be connected, might not, idk enough spaghetti to riddle this one out. All I know is I'd like to pretend I'm about to build something as an engineer when I'm really up to no good.

    0 Comments
    2024/10/25
    11:56 UTC

    0 Comments
    2024/10/25
    08:25 UTC

    2

    Custom Floating text?

    i have this engineer script that lets me select the building on the scroll wheel and i was wondering if it was possible to make custom text appear next to the cursor

    0 Comments
    2024/10/25
    04:23 UTC

    2

    Can I have build stuff and destroy stuff at same key?

    Hi I enjoy playing TF2 on a controller. But Valve force controller players to use building menu from xbox 360.
    Can I bind build and destroy buildings to F1 F2 F3 and F4 keys? If so it would be possible to bind these 4 commands into controller.

    12 Comments
    2024/10/22
    15:35 UTC

    4

    Script for turning off pyro's primary viewmodel & flames?

    So I looked online for scripts doing just that. it seems that the scripts I've found so far only works for when I switch weapons via number keys, and I don't. I use the mouse wheel to cycle through weapons. If this is even possible at all, please let me know if you have solutions. Thank you

    5 Comments
    2024/10/12
    20:32 UTC

    5

    How do i add a crosshair for each individual class with deafult crosshairs without using any programs

    For example i want to use the dot crosshair or "crooshair 5" on sniper but i want to use the default on on scout

    1 Comment
    2024/10/10
    15:04 UTC

    2

    Shoot gun manually via scripts to override fire rate

    Do vscripts count as tf2 scripts? Hopefully I'm in the right subreddit.

    I'm making a custom map, and would like a hitscan gun that shoots perfectly accurately with a high fire-rate. I tried addcond 91 sniper rifle as well as addcond 96 kleaner's carbine, but the former is still too slow and the latter still too inaccurate.

    Since I'm making the map I can mess with the netprops, so I have been attempting to manually shoot the sniper rifle faster than the game normally lets me. I have been somewhat successful with the following:

    ...
    NetProps.SetPropFloat(weapon, "m_flNextPrimaryAttack", 0)
    weapon.PrimaryAttack()
    ...

    ...but the issue is when I break the fire-rate floor using the above code, it kind of breaks all of the sniper animations - the sniper no longer has muzzle flash, a shooting animation, a gunfire sound (there's some slight clicking noise still), no bullet trace and no bullethole at the impact location. Triggering a resupply locker fixes the issue.

    I suppose if the resupply locker restores everything, I could try to just, destroy my gun and then re-equip a new one after shooting it? Maybe that'll fix the animations, but that sounds pretty scuffed. Then again, everything I'm doing is already pretty damn scuffed.

    Anybody know how I can trigger all of the animations and sound effects via script when I shoot? I've been looking through the developer wiki and also the source code leak back from 2020 but I'm without a lead I'm wandering around in the dark.

    0 Comments
    2024/10/08
    21:05 UTC

    2

    How do I make a resupply bind that doesn’t change my loadout?

    I’ve been trying to make a resupply bind that doesn’t change my loadout but whenever I press the bind it goes to my first loadout.

    4 Comments
    2024/10/01
    01:10 UTC

    2

    Main menu music

    USING MASTERCONFIG LOW

    Followed the steam guide to get the custom main menu music and it’s not working and a could videos related to it and still nothing https://steamcommunity.com/sharedfiles/filedetails/?id=1511463814

    I remember it working pre x64 when I did it following the guide and wanted to do it again to save my updated config to my google drive so I don’t have to tweak everything a thousand times when I switch my OS

    Troubleshooting I did

    I have them in the proper format and size 192kbs 44100hz .mp3

    They are In my custom as /custom/menumusic/sound/ui/gamestartup1.mp3 All the way to 32 just like the guide says attempted to move them to the base /tf folder

    Took everything out of custom accept music and nothing plays

    Looked for posts like this all seemed to be unanswered or got it working and never explained how they did

    (Edit just came up with an idea as to why it could not be working relating to my preloading script for custom animations will test this tomorrow since the music will stop playing if you happen to boot a map and go back to the menu)

    1 Comment
    2024/09/18
    07:38 UTC

    1

    Fix weaponspread command not working

    I was on a valve server and when i typed the fix weaponspread command It didnt work and a message popped up (you can see It under the image), someone know how to fix It?

    4 Comments
    2024/09/17
    14:29 UTC

    3

    Is this formatted correctly?

    This script is supposed to switch weapons and fire when pressing the appropriate mouse button. However when I tried to use it last night it seemed to do nothing. The echo command also did not print

    **Running Heavy** 

    as it should have. I am running mastercomfig. All class config files are in tf/cfg/overrides which is where I understand they belong. The script is written as follows:

    Echo **Running Heavy**
    
    alias +heavy_shoot "slot1; +attack"
    alias -heavy_shoot "-attack"
    alias +heavy_sandvich "slot2; +attack"
    alias -heavy_sandvich "-attack"
    alias +heavy_melee "slot3; +attack"
    alias -heavy_melee "-attack"
    
    bind mouse1 "+attack"
    bind mouse2 "+attack2"
    bind mouse3 "+heavy_melee"
    bind mwheelup "+heavy_shoot"
    bind mwheeldown "+heavy_secondary"

    Original source is Gamebanana, the echo command added by myself to make sure the script is actually running.

    Yes the script lacks exec reset. Mastercomfig has a game_overrides.cfg that runs before every class config where I have placed the exec reset command to run my reset.cfg

    I also posted about this on r/tf2scripthelp/ but have not gotten much help there as of yet.

    1 Comment
    2024/09/15
    17:42 UTC

    6

    My 9in1 class inspired insult, super chat script.

    I missed the old days of people having a chat bind for when they get a kill. Anyone remember "Meatshot"?
    So I made one
    When I decided to make one initially, it was just for soldier. It would cycle through 11 soldier inspired insults on the same key, T
    During my testing, another gamer said "I wonder what he says when he dies", and so I decided to make a set of death lines, bound on the right alt key.
    I then wondered if I could make a set of lines for engineer but also have those on T
    I haven't made the lines yet, which is the only thing missing from this script excluding the 'cycle-script' that goes with the lines, but I ended up preparing it for every class. There's an empty setup for Scout though which can be copy pasted and then edited a little.

    I needed a way to switch between the classes, at first I thought to just write whatever class-set you wanted to use in console, 'scout', 'soldier' and so on, which would just switch it.
    But that wasn't super user-friendly, so I added numpad keybinds, but I don't have a numpad, so it wasn't useful for me, and therefore I needed a third method, which ended up turning my x key into both voice_menu 2, but also the class changer, inspired by u/DeltaEks

    Just a little bit of fun, I hope you liked the little script, and that some of you might find some fun in this as well.

    3 Comments
    2024/09/14
    04:30 UTC

    3

    medic toggle scripting

    i need some help, so, i have a medic scrip what says "uber used, push now" when i uber, but when i use the vax, i dont want it to spam, so i was wondering if theres a way to toggle my medic ubercharge script?

    1 Comment
    2024/09/12
    04:02 UTC

    2

    zoom_sensitively ratio

    current settings

    in game sens 1.00

    software dpi 1400

    ratio 4:3

    in game res 1280 x 1024

    using masterconfig w/flat mouse addon

    hello all, i recently attempted to configure my game again to make a new tf2 customization folder for my google drive the last thing on my list was changing my zoom_sensitivity_ratio to be a more accurate 1:1 to zoom_sensitivity_ratio_mouse 0.818933027098955175 unscoped for my sniper however it seems that maybe this command has changed names as i get an error in the game that the command does not exist however i was able to input it as zoom_sensitivity_ratio 0.818933027098955175 but i don't feel a difference and it is not 1:1 just like how the default of zoom_sensitivity_ratio_mouse 1 isnt 1:1 i have also tried zoom_sensitivity_ratio 0.793471413188092

    followed these guides through discussion on https://www.teamfortress.tv/35467/on-the-correct-value-of-zoom-sensitivity-ratio

    https://www.reddit.com/r/GlobalOffensive/comments/43urd4/why_0818933027098955175_is_the_best_zoom/

    https://www.reddit.com/r/GlobalOffensive/comments/grq67e/is_the_calculated_0818933027098955175_zoom_sens/

    1 Comment
    2024/09/11
    17:32 UTC

    2

    Processing time exceeded

    Every time I try launching into my tf2 server, it says processing time exceeded..how can I fix this?

    1 Comment
    2024/09/10
    21:15 UTC

    2

    i'm looking for a way to toggle binds for demoman.

    I'm not sure if it is possible but I'm looking to bind my left, down and right arrow keys to change my binds for demoman, hybridknight and demoknight loadouts. I have some basic binds for demoman but for demoknight i want to bind q and e to turn left/right, i then want to undo it for hybrid and full demo, also instead of lastinv i have set slot switches between slot1 and slot2 but for hybrid i want to change that to slot1 and slot3. If this is at all possible i would be very grateful. I've been messing around a bit with this code, but it doesn't work.

    https://preview.redd.it/3wjgerm2uznd1.png?width=707&format=png&auto=webp&s=ff0c184fc50ceb3aaece37fd46758cb1358e5174

    11 Comments
    2024/09/10
    14:19 UTC

    1

    I can't see my arms or weapons in game anymore what do I do

    I watched a video on how to change my fov and viewmodle fov but now there's nothing on my screen but the hud I can still shoot and use items but I can't see my arms or the gun is there a way to reset my settings I'm ther command console or am I screwed im not to tech savvy

    5 Comments
    2024/09/09
    23:29 UTC

    2

    Tf2 server help.

    Recently started a dedicated server for me and my friends. I have a server.cfg in my cfg file aswell as source mod and meta mod, which also states I'm admin of the sever. However, when I join my sever with my rcon password, it says "bad rcon password" and doesn't let me do any commands. The server also says "Server.cfg not found:Not executing". Any help on how I can use commands and how to get server.cfg and rcon to work

    16 Comments
    2024/09/09
    20:05 UTC

    2

    script command for the extra mini sentry in mvm?

    I already has a script for senrty at 1, dispenser at 2, tele in and out in 3 and 4. But what is the command for the extra mini sentry engineer can build in mvm? I would like to put that at 5 button.

    1 Comment
    2024/09/07
    14:10 UTC

    3

    How do you make multiple configs for the same class?

    I use mastercomfig and have been delving into class configs lately to change up my binds. The biggest switches for me are when playing demoknight and so I’ve made a bind in my demoman config that allows me to toggle the use of a demoknight.cfg file. What I would really rather have is the ability to switch between a demoman and demoknight class cfg on the fly, which would allow me to change to net_hitscan settings (as per mastercomfigs network aliases) because the way I have it right now I’m stuck with projectile network settings on a hitscan subclass. As far as I am aware it is not possible to change network settings mid game, as you can only bypass the necessity to enter spectate mode when doing so via class configs. Mastercomfig has a section https://docs.comfig.app/latest/customization/custom_configs/#optional-aliases that explains the possibility of multiple same-class configs but it’s gone over my head to be honest. Any help is greatly appreciated, cheers

    3 Comments
    2024/09/07
    02:22 UTC

    1

    How do I change my lerp

    I can't find a tutorial

    (PLEASE USE PICTURES)

    1 Comment
    2024/09/04
    00:25 UTC

    2

    Is there a way to toggle disguise teams?

    (I don't exactly know how binds work, but I'm lazy, so I came here.) I have a backup set of binds for spy to disguise as each different class on the opposite team, but I'm wondering if it's possible to make a key to toggle my team and the opposite? This is what I have.

    bind "KP_HOME" "disguise 1 -1"
    bind "KP_UPARROW" "disguise 2 -1"
    bind "KP_UP" "disguise 3 -1"
    bind "KP_LEFTARROW" "disguise 4 -1"
    bind "KP_5" "disguise 5 -1"
    bind "KP_RIGHTARROW" "disguise 6 -1"
    bind "KP_END" "disguise 7 -1"
    bind "KP_DOWNARROW" "disguise 8 -1"
    bind "KP_PGDN" "disguise 9 -1"
    2 Comments
    2024/09/03
    03:44 UTC

    1

    Detonator Jump and ALT Fire button change

    I'm completely new to scripting and I was wondering how to script the detonator so that right mouse click does a JUMP + CROUCH + FIRE + SELF DET. Since this bind would completely change the button to self detonate, I want to be able to change the SELF DET to left mouse click as well. So both the left mouse button is the button responsible for Primary Fire and Self Detonating, the self detonate will occur only after I have pressed the left mouse button a second time when the primary fire has already been pressed

    0 Comments
    2024/09/02
    03:05 UTC

    1

    Is there a way to make it so when I hit "q" it switches from my primary to my melee as spy?

    I want it to work with the stabby stabby viewmodel script.

    For reference

    knife_vm_mode

    // replace [KEY] with the your Keybinds for the sapper♥♥♥♥♥♥♥ambassador/watch

    bind "2" +equip_sap // Key/button for sapper
    bind "3" +equip_knife // Key/button for knife
    bind "1" +equip_amby // Key/button for ambassador
    bind "mouse2" "+watch;spec_prev" // Key for watch (mouse2 default)

    //re-bind mouse1

    alias knife_vm_mode "bind mouse1 +viewmodel_knife" // binds mouse1 to turn viewmodel on when attacking (for knife knife)
    alias amby_vm_mode "bind mouse1 +viewmodel_amby" // binds mouse1 to turn viewmodel off when attacking (for amby)
    alias sap_vm_mode "bind mouse1 +viewmodel_sap" // binds mouse 1 to turn viewmodel on when attacking and off when not (for sapper)

    // causes viewmodel to go off or on when you shoot

    alias +viewmodel_knife "+attack;r_drawviewmodel 1;spec_next" // attacks, turns viewmodel on
    alias -viewmodel_knife "-attack;r_drawviewmodel 1" // finishes atack, turns viewmodel on again as safeguard

    alias +viewmodel_amby "+attack;r_drawviewmodel 0;spec_next" // attacks, turns viewmodel off
    alias -viewmodel_amby "-attack;r_drawviewmodel 0" // finishes attack, turns viewmodel off again as a safeguard

    alias +viewmodel_sap "+attack;r_drawviewmodel 1;spec_next" // shows sapper when sapping
    alias -viewmodel_sap "-attack;r_drawviewmodel 0" // hides sapper when mouse1 released

    // Equip item, turn vm on/off, set vm toggle for attack

    alias +equip_knife "slot3;r_drawviewmodel 1" // Equips knife, turns viewmodels on
    alias -equip_knife "knife_vm_mode;r_drawviewmodel 1" // Sets viewmodels to turn ON when stabbing (makes sure it stays on)

    alias +equip_amby "slot1" // Equips amby
    alias -equip_amby "amby_vm_mode" // Sets viewmodels to turn OFF when shooting

    alias +equip_sap "slot2;r_drawviewmodel 1" // Equips sapper, turns viewmodels on
    alias -equip_sap "sap_vm_mode" // Sets viewmodels to turn on while firing, and off when not

    alias +watch "+attack2;r_drawviewmodel 1" // watch up/cloak on/secondary attack + viewmodels on
    alias -watch "-attack2;r_drawviewmodel 1" // viewmodels on again as safeguard

    4 Comments
    2024/09/01
    05:24 UTC

    2

    Any possible way to make the sniper rifle work on a release fire?

    I want it to work on a -input without auto-firing after. The zooming and firing can be separate or together, I don't have a preference but it would be nice to have both.

    4 Comments
    2024/09/01
    00:09 UTC

    3

    hello! i am a complete noob to scripting, and i was wondering if someone could help with a certain script!

    so i was watching some theory-y to get a better hang of med, and i notice he said something about a bind where q was bound to swap to fire res, pop, and switch back to bullet (when on bullet), and e for explosion res bubbles, and it was something he could switch on and off when/if he was using vax. i wanted to replicate this (so q would switch to fire res, pop a bubble, and switch back to bullet extremely fast, and e for blast res).

    2 Comments
    2024/08/30
    00:05 UTC

    Back To Top