Weapon scripts

From TF2 Wiki

Share/Save/Bookmark
Jump to: navigation, search
Community script navigation
General scripts
Weapon scripts
General class scripts
Collection scripts
Class scripts
Scout scripts
Soldier scripts
Pyro scripts
Engineer scripts
Heavy scripts
Demoman scripts
Medic scripts
Sniper scripts
Spy scripts


Contents

Global Shift-AutoAttack

Hold shift key and left click to autoattack (continues firing even after releasing mouse button)
Left click without shift key to engage regular attack (stops firing when you release the mouse button)
Posted by Greeze
//Shift-Autoattack
//==========================
alias +primaryattack "+attack"
alias -primaryattack "-attack"
alias +primaryattackmodifier "alias -primaryattack +attack"
alias -primaryattackmodifier "alias -primaryattack -attack"
//==========================

bind "MOUSE1" "+primaryattack"
bind "SHIFT" "+primaryattackmodifier"

Weapon scroll thru 1, 2, and 3 only

The mouse wheel will only scroll thru weapons 1-3 and not pdas and the disguise kit.
Alias num1 "slot1; bind MWHEELUP num3; bind MWHEELDOWN num2"
alias num2 "slot2; bind MWHEELUP num1; bind MWHEELDOWN num3"
alias num3 "slot3; bind MWHEELUP num2; bind MWHEELDOWN num1"

num1

Global Melee Weapon Switch & Attack

Hold the bound key down and you will switch to your melee weapon and begin attacking. Releasing the key will take you back to your primary weapon.
Posted by Shifty54
alias +melee "slot3; +attack"
alias -melee "-attack; wait; slot1"
bind "mouse3" "+melee"

NOTE: Make sure Fast Weapon Switch is enabled under advanced keyboard options. This could save you an hour or two of frustration ;)

Weapons Scroll

Scroll Wheel guns ONLY, Mouse 3 is melee.
Posted by Icehawk
//Weapons Switching
alias primary "slot1; wait; bind MWHEELUP secondary" 
alias secondary "slot2; wait; bind MWHEELUP primary" 
bind "MWHEELUP" "primary"
alias primary2 "slot1; wait; bind MWHEELDOWN secondary2" 
alias secondary2 "slot2; wait; bind MWHEELDOWN primary2" 
bind "MWHEELUP" "primary"
bind "MWHEELDOWN" "primary2"
alias melee "slot3; bind MOUSE3"
bind "MOUSE3" "melee"

No-Menus Weapon Switch

Scroll Wheel goes through your primary, secondary, and melee weapons, not through Build/Destroy/Disguise Menus
You must set fast weapon switch on to use this script.
Posted by The404Error
//No-Menu Cycle
alias weapon1 "slot1; bind MWHEELDOWN weapon2; bind MWHEELUP weapon3"
alias weapon2 "slot2; bind MWHEELDOWN weapon3; bind MWHEELUP weapon1"
alias weapon3 "slot3; bind MWHEELDOWN weapon1; bind MWHEELUP weapon2"
alias weapon4 "slot4; bind MWHEELDOWN weapon1; bind MWHEELUP weapon3"
alias weapon5 "slot5; bind MWHEELDOWN weapon1; bind MWHEELUP weapon3"
bind "1" "weapon1"
bind "2" "weapon2"
bind "3" "weapon3"
bind "4" "weapon4"
bind "5" "weapon5"
bind "MWHEELUP" weapon3
bind "MWHEELDOWN" weapon2

Bind-Agnostic Version of Weapons Scroll

Same as above, but doesn't duplicate effort, and allows users to bind any number of keys/buttons to the same function.
(This does not include the melee function.)
Original script by Icehawk, modified by Greeze
There is some discussion about this script.
//Alias-only Weapons Switching
alias weaponSet "secondary"
alias primary "slot1; wait; alias weaponSet secondary"
alias secondary "slot2; wait; alias weaponSet primary"

//Now bind whatever you like to weaponSet.  For example,
bind "MWHEELUP" "weaponSet"
bind "MWHEELDOWN" "weaponSet"

Bind-Agnostic Version of Melee Toggle

Original script by Icehawk, modified by Greeze
alias meleeToggle "melee"
alias melee "slot3; alias meleeToggle ranged"
alias ranged "lastinv; alias meleeToggle melee"

bind "MOUSE3" "meleeToggle"

Bind-Agnostic Version of Weapon scroll/melee toggle with melee toggle state reset

Changing weapons after toggling melee will now reset the melee toggle.

Original script by Icehawk, modified by Greeze, modified by BAss
//Alias-only Weapons Switching with reset
alias weaponSet "secondary"
alias primary "slot1; wait; alias weaponSet secondary; meleereset"
alias secondary "slot2; wait; alias weaponSet primary; meleereset"

//Now bind whatever you like to weaponSet.  For example,
bind "MWHEELUP" "weaponSet"
bind "MWHEELDOWN" "weaponSet"

alias meleeToggle "melee"
alias melee "slot3; alias meleeToggle ranged"
alias ranged "lastinv; alias meleeToggle melee"

bind "MOUSE3" "meleeToggle"

//reset changes the melee toggle to primary state

alias meleereset "alias meleetoggle melee"
bind "q" "lastinv; meleereset"

Melee Toggle and Auto-Attack

Thanks to the above Duck Toggle script for giving me this concept!
Press bound key (I use mouse button 4 in this example) to whip out your melee weapon and start busting some butt, automatic-style!
Posted by TandooriChicken
//Melee Toggle and Auto-Buttwhoopin'
alias meleetoggle melee1
alias melee1 "slot3; +attack; alias meleetoggle melee2"
alias melee2 "-attack; slot1; alias meleetoggle melee1"

//Variant to pop a shot when you switch back
alias meleetoggle melee1
alias melee1 "slot3; +attack; alias meleetoggle melee2"
alias melee2 "-attack; slot1; alias meleetoggle melee1; +attack; wait 200; -attack"

//Automelee Toggle Keybind
bind mouse4 meleetoggle

Auto reload

These functions have been patched, turn-on auto-reload from the options of the game instead.

WASD Auto reload

Auto-Reload Script on WASD movement.
Posted by Apathy
Note: There is some discussion about this script.
// Toggle auto-reload
bind "KEY" "auto"
alias "auto" "aron"
alias "aron" "bind w +w;bind s +s; bind a +a; bind d +d;alias auto aroff"
alias "aroff" "rw;rs;rl;rm;alias auto aron"
alias "rw" "bind w +forward"
alias "rs" "bind s +back"
alias "rl" "bind d +moveright"
alias "rm" "bind a +moveleft
alias +w "+forward;+reload"
alias -w "-forward;wait;-reload"
alias +s "+back;+reload"
alias -s "-back;wait;-reload"
alias +a "+moveleft;+reload"
alias -a "-moveleft;wait;-reload"
alias +d "+moveright;+reload"
alias -d "-moveright;wait;-reload"

Bind-Agnostic Movement Auto-Reload

Modification of the Auto-Reload Script on WASD movement by Apathy. Should work the exact same way as before, except it's bind-agnostic for those who don't use a WASD keyboard layout.
Posted by Kwogger
alias "aron" "alias +goF +onF;alias +goB +onB;alias +goR +onR;alias +goL +onL;alias -goF -onF;alias -goB -onB;alias -goR -onR;alias -goL -onL;alias auto aroff"
alias "aroff" "alias +goF +offF;alias +goB +offB;alias +goR +offR;alias +goL +offL;alias -goF -offF;alias -goB -offB;alias -goR -offR;alias -goL -offL;alias auto aron"
alias "+offF" "+forward"
alias "+offB" "+back"
alias "+offR" "+moveright"
alias "+offL" "+moveleft"
alias "-offF" "-forward"
alias "-offB" "-back"
alias "-offR" "-moveright"
alias "-offL" "-moveleft"
alias "+onF" "+forward;+reload"
alias "+onB" "+back;+reload"
alias "+onR" "+moveright;+reload"
alias "+onL" "+moveleft;+reload"
alias "-onF" "-forward;wait;-reload"
alias "-onB" "-back;wait;-reload"
alias "-onR" "-moveright;wait;-reload"
alias "-onL" "-moveleft;wait;-reload"
aron //Initialize Script - on by default

bind "W" "+goF" //Movement Forward
bind "S" "+goB" //Movement Back
bind "D" "+goR" //Movement Right
bind "A" "+goL" //Movement Left
bind "O" "auto" //Toggle auto-reload


Auto reload after firing

Posted by Bono
Here's a generic auto reload script that does not break Demoman sticky bombs, hwguy gun, or the Medic syringe gun. The trick is using the wait [x] command before the +reload. This works fine as long as you don't wait too long between releasing your bound key and pressing it again. For the hwguy gun and Medic syringes, you'll be holding down the button anyway.
There is some discussion about this script.
//Auto Reload after firing
alias +autoload "+attack;-reload"
alias -autoload "-attack;wait 25;+reload"
bind "[key]" "+autoload" 

This does result in a very slight delay in reloading compared to scripts with no wait commands before the +reload, but I find it negligible. The tradeoff between a delay of fractions of a second and an auto reload script that works for most of your weapons is worth it.

For rapid fire pistols (Engineer, Scout, etc.), you can try increasing the number after the wait (ex. wait 100) to give you time to get off shots before it interrupts and starts reloading. Using wait 100 before the +reload, I was able to rapid fire the Engineer pistol until 3 or 4 rounds were left (out of 12) before it began reloading.

Otherwise, as others have mentioned, your best best is to make class-specific configs and activiate +reload/-reload on a per-weapon basis.

Weapon specific auto reload

I made a simple modification to The404Error's No-Menus Weapon Switch to control which weapons I wanted to auto reload. Using this script does require class-specific configs, I use Shifty54's Class Config Switcher and loader for this. It will also require fast weapon switching. Here's an example of what I use for Scout.
Posted by Sicc
//Weapon Specific Auto Reload w/ No-Menu Cycle (scout.cfg)
alias weapon1 "+reload; slot1; bind MWHEELDOWN weapon2; bind MWHEELUP weapon3"
alias weapon2 "-reload; slot2; bind MWHEELDOWN weapon3; bind MWHEELUP weapon1"
alias weapon3 "-reload; slot3; bind MWHEELDOWN weapon1; bind MWHEELUP weapon2"
alias weapon4 "-reload; slot4; bind MWHEELDOWN weapon1; bind MWHEELUP weapon3"
alias weapon5 "-reload; slot5; bind MWHEELDOWN weapon1; bind MWHEELUP weapon3"
bind "1" "weapon1"
bind "2" "weapon2"
bind "3" "weapon3"
bind "4" "weapon4"
bind "5" "weapon5"
bind "MWHEELUP" weapon3
bind "MWHEELDOWN" weapon2

Unlike TFC, you can respawn while +reload is active, which is what makes this script possible. I included both the MWHEEL and number keys because I use both, so I need the wheel's next action to be in sync regardless of how I chose my current weapon. Using this script there is zero reload delay for compatable weapons, while allowing manual reload for those that require it. The only flaw I have found is I need to spin the wheel when I spawn to sync up the reload behavior.

Weapon Specific Auto-Reload w/ Toggle

Because Sicc's script did not work with the toggle last weapon button, I modified it to work. Note that with just a bit more modification, a custom reload sequence could be made for the pistol, but since those scripts are very unreliable, you are better off manually reloading.
Posted by Kwogger
//Set up the specific weapons so that they will change to auto-reload as required.
alias "weapon1" "+reload; slot1; alias nextweap select21; alias prevweap select31; alias select1 weapon1; alias select2 select21; alias select3 select31;"
alias "weapon2" "-reload; slot2; alias nextweap select32; alias prevweap select12; alias select1 select12; alias select2 weapon2; alias select3 select32;"
alias "weapon3" "-reload; slot3; alias nextweap select13; alias prevweap select23; alias select1 select13; alias select2 select23; alias select3 weapon3;"
//Set up the previous weapon toggle
alias "select12" "weapon1; alias toggleweap select21"
alias "select13" "weapon1; alias toggleweap select31"
alias "select21" "weapon2; alias toggleweap select12"
alias "select23" "weapon2; alias toggleweap select32"
alias "select31" "weapon3; alias toggleweap select13"
alias "select32" "weapon3; alias toggleweap select23"
//Initialize script
select12
//Binds
bind "q" "toggleweap"
bind "1" "select1"
bind "2" "select2"
bind "3" "select3"
bind "MWHEELUP" "prevweap"
bind "MWHEELDOWN" "nextweap"

Rapid Fire

Rapid Fire scripts don't do anything for pistols as these have been patched to always shoot at their maximum speed. Demoman-specific parts may remain valid.

This script implements rapid fire for the Scout's and Engineer's pistols and the Demoman's sticky-bomb launcher. For the Scout and Engineer, primary attack rapidly cycles +attack and -attack when held. For the Demoman, both attacks retain their functionality when pressed independently but rapidly cycle +attack, -attack, +attack2, and -attack2 when held together. To prevent the client from freezing, it reverts to normal attacks if the host has unset sv_allow_wait_command but may unavoidably leave either attack enabled if changed while the script is running. Should this situation occur, it can be remedied by pressing and releasing the conflicting attack button.

This algorithm is non-reentrant to prevent multiple loops from running in competition. Separate aliases are used for each attack step with the next step conditionally determined by the state of the attack buttons after the delay to avoid timing errors that could occur from pressing and releasing them too quickly.

in autoexec.cfg:

bind "mouse1" "+fire1"
bind "mouse2" "+fire2"

in core.cfg:

alias +fire1 "+f1"
alias -fire1 "-f1"
alias +fire2 "+f2"
alias -fire2 "-f2"

alias +f1    "+attack"
alias -f1    "-attack"
alias +f2    "+attack2"
alias -f2    "-attack2"

alias +e     "alias +e1 +d1; alias -e1 -a1; alias +e2 +d2; alias -e2 -a2"
alias -e     "alias +e1;     alias -e1;     alias +e2;     alias -e2"

alias +e1    "+d1"
alias +d1    "+a1"
alias +a1    "+attack;  wait 2; +b1"
alias +b1    "+c1"
alias +c1    "-a1"

alias -e1    "-a1"
alias -a1    "-attack;  wait 2; -b1"
alias -b1    "-c1"
alias -c1    "+e"

alias +e2    "+d2"
alias +d2    "+a2"
alias +a2    "+attack2; wait 2; +b2"
alias +b2    "+c2"
alias +c2    "-a2"

alias -e2    "-a2"
alias -a2    "-attack2; wait 2; -b2"
alias -b2    "-c2"
alias -c2    "+e"

alias wait   "echo WAIT DISABLED BY HOST; alias wait; exec restricted.cfg"
wait

in restricted.cfg:

alias +fire1 "+attack"
alias -fire1 "-attack"
alias +fire2 "+attack2"
alias -fire2 "-attack2"

alias +a1    "-attack; -attack2"
alias -a1    "-attack; -attack2"
alias +a2    "-attack; -attack2"
alias -a2    "-attack; -attack2"

in demoman.cfg:

exec core.cfg
alias +f1 "alias +c1 +e;  alias -c1 +a1; alias +b2 -a2; alias -b2 +a1; alias +d2 -a1; +e1; -e"
alias -f1 "alias +c1 -a1; alias -c1 +e;  alias +b2 +c2; alias -b2 -c2; alias +d2 +a2; -e1; -e"
alias +f2 "alias +b1 -a1; alias -b1 +a2; alias +c2 +e;  alias -c2 +a2; alias +d1 -a2; +e2; -e"
alias -f2 "alias +b1 +c1; alias -b1 -c1; alias +c2 -a2; alias -c2 +e;  alias +d1 +a1; -e2; -e"

in engineer.cfg & scout.cfg:

exec core.cfg
alias +f1 "alias -c1 +a1; +e1; -e"
alias -f1 "alias -c1 +e"

in heavyweapons.cfg, medic.cfg, pyro.cfg, sniper.cfg, soldier.cfg, & spy.cfg

exec core.cfg

Submitted by Vaeden 21:11, 27 May 2009 (UTC) (Updated 21:24, 29 June 2009 (UTC))



Personal tools