Hi all,
so this is something I've been trying to work out for a while and I can't seem to figure it out. So now, I reach out to the community.
Does anyone know of a way to set a guns ViewModel to a .VMT file programmatically?
I can easily set a .VTF, or color to the gun but due to several factors I'd like to be able to have the gun be a VMT.
First reason, can it actually be done.
Second, my WorldModel currently is a VMT so I can't understand why it can't be set on ViewModel.
Setting the ViewModel to a .VTF file code:
[CODE]function SWEP:ViewModelDrawn( self )
Material("models/weapons/v_357/357_sheet"):SetTexture("$basetexture", "models/effects/com_shield001a" )
end[/CODE]
WorldModel code:
[CODE]function SWEP:Initialize()
self:SetMaterial("models/props_combine/com_shield001a")
end[/CODE].
This is all I can think that is need to know. If this is simple I will be very happy but as it stands I've been trying to accomplish this for near on a week, any help is greatly appreciated. Thanks
Just do the same thing you do with the world model, E.G.
[CODE]
LocalPlayer():GetViewModel():SetMaterial("models/props_combine/com_shield001a")
[/CODE]
I'm not sure if that works in the ViewModelDrawn function, or if you should even be using that function considering it gets called AFTER the viewmodel gets drawn (at least according to the wiki).
You might be able to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/PreDrawViewModel]SWEP:PreDrawViewModel[/url] or [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnViewModelChanged]GM:OnViewModelChanged[/url] to switch between materials
Thank you both for answering so quickly, I feel stupid now, I've looked at each method (except render.MaterialOverrideByIndex) that both of you provided before now with no success. But I didn't realise how PreDraw and PostDraw differed.
PreDraw - Allows you to modify viewmodel while the weapon in use before it is drawn
PostDraw - Allows you to modify viewmodel while the weapon in use after the view model has been drawn.
-Quotes from Wiki
This didn't make a lot of sense to me.
I would have taken a long time to understand the differences if it weren't for this thread: [url]https://facepunch.com/showthread.php?t=1338430[/url] last reply, combined with
[QUOTE=Shenesis;52222894](make sure to clear the material after drawing)[/QUOTE]
I don't know why this made me understand the difference but I thank you, as I said I've been trying to achieve this for a week.
End result:
The material working with this code, combining elements of both of your responses.
[CODE]function SWEP:PreDrawViewModel( vm )
self.Owner:GetViewModel():SetSubMaterial(1, "models/props_combine/com_shield001a")
end
function SWEP:PostDrawViewModel( vm )
self.Owner:GetViewModel():SetSubMaterial(1, nil)
end [/CODE]
[I]I can't thank you both enough, as I said, I've been working on this for a week and this was my last port of call, as seen, I was desperate enough to make a forum account, just to see what was needed.[/I]
Sorry, you need to Log In to post a reply to this thread.