• Changing the viewmodel of a SINGLE swep
    4 replies, posted
Hi. I'm making a swep and I ran into a problem that makes my ass clench, cause no matter what I try I can't get it to work. I've already admitted defeat so I came here for help. Here's some script: function SWEP:PreDrawViewModel(vm, wep, ply )     vm:SetMaterial("models/rendertarget",true) end This affects all my weapons and I want to change the material of my custom swep only. I've tried doing IF statements that check if the active weapon is my swep - didn't work. I've tried running a think hook that checks if my swep isn't active to revert the material - didn't work. I've tried the same thing as above but in the GM:PostDrawViewModel hook - didn't work + I noticed I couldn't even change the viewmodel material in GM:PostDrawViewModel, it worked only in the SWEP hook. Also, just to make sure, to change the material to original should I just use this?: vm:SetMaterial("",true) Any help appreciated, thanks.
You can set it to the material you want in SWEP:Deploy and restore the original in SWEP:Holster. The default ViewModel is 1 entity used by all weapons, unless you are using a custom viewmodel entity in your SWEP.
I think in SWEP:PostDrawViewModel() you need to reset the model's material to its original material. For the CS:S M4A1, it would be something like function SWEP:PreDrawViewModel( vm ) vm:SetMaterial( "models/rendertarget", true ) end function SWEP:PostDrawViewModel( vm ) vm:SetMaterial( "models/weapons/v_models/rif_m4a1/rif_m4a1", true ) end
This would work if you use SetMaterial("") at the end. If you set the original material, that material will stick even after you change weapons - not to mention that same material will apply to the hands or other parts of the weapon as well. But even with the fix, it still feels bad to change the material twice per frame (and it's possible this will make a noticeable framerate impact). This is a good solution, unfortunately in singleplayer it won't work as easily because WEAPON/Holster is predicted. Not a huge difference though.
Works fine, thanks
Sorry, you need to Log In to post a reply to this thread.