How to turn off viewmodels for certain weapons

team-fortress-2

I know that I can turn off the viewmodels of all weapons of a specific class by typing r_drawviewmodel "0" into the cfg file of that class, but how can I (with or without scripts) turn the viewmodels off for one weapon, but on for another?

e.g. I want my viewmodel to be on for my flamethrower and melee weapon for the pyro, but I want my shotgun's viewmodel off (as it helps me aim better). Is there any way I can do this?

In response to Austin's answer, I thought I'd post my entire cfg for my Pyro, to see if there are any conflictions:

cl_autoreload 1

unbind mouse3

//Secondary weapon
alias +secondary "slot2"
alias -secondary "slot1"

//Melee weapon
alias +melee "slot3"
alias -melee "slot1"

//Binds
bind "mouse5" "+melee;r_drawviewmodel 1"

bind mwheelup "slot1;r_drawviewmodel 1"

bind mwheeldown "slot2;r_drawviewmodel 0"**

There is a bit in there about when I hold mouse5, I switch to melee, and, upon release, I switch back to my primary weapon, but I don't know if this is relevant.

Best Answer

To preface, I find it more reliable in general to use the keyboard to switch between weapons rather than the mouse wheel. Doing so seems particularly helpful with "combo" attacks like flamethrower + axetinguisher.

If you are willing to select your weapons from the keyboard, then you could add

bind q "slot1;r_drawviewmodel 1"
bind e "slot2;r_drawviewmodel 0"
bind f "slot3;r_drawviewmodel 1"

to pyro.cfg. The example above would allow you to select (as Pyro) your primary with viewmodel by pressing q, your secondary without viewmodel by pressing e, and your melee with viewmodel by pressing f.