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"

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.

  • I would first get rid of those aliases for melee and secondary if they aren't doing anything else and just stick with "slot". Mousewheel up and down are MWHEELUP and MWHEELDOWN, respectively. Mousewheel click may not necessarily be MOUSE5 (it varies from mouse to mouse). The scripting page on the wiki suggests MOUSE3. – Austin Mohr May 22 '15 at 2:18

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.

  • I've copied your code, but replaced q with mousewheelup, e with mousewheeldown and f with mouse5, but it doesn't seem to be working. Do you know why this is? – alexqwx May 21 '15 at 20:49
  • @alexqwx What results are you getting? Is it possible that another script or in-game setting is also trying to make use of the mousewheel? – Austin Mohr May 21 '15 at 21:05
  • I just get viewmodels on all my weapons. See my edited question for my cfg text, to see if anything's wrong. – alexqwx May 21 '15 at 21:54
  • Awesome. Everything is working as I'd hoped. Thank you so much! – alexqwx May 22 '15 at 13:19


bindtoggle r r_drawviewmodel

to autoexec.cfg will allow you to press r (or whatever key you choose) in-game to toggle viewmodels on and off at will.

  • You should add extra info to your existing answer with an edit rather than making another answer. – DJ Pirtu May 21 '15 at 20:48
  • Adding alternatives to an existing answer should get you +1s for both methods. – DJ Pirtu May 21 '15 at 20:52

Make a toggle viewmodel:

Put in your class name.cfg:

bindtoogle [key] "r_drawviewmodel 0 1"

Then, change the [key] to a key of course and when you press your key, it will turn on and off viewmodels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.