View Model Color Change

I’m trying to change the color of a view model for the player. I tried all of these:

function SWEP:Initialize()
   local viewModel = LocalPlayer():GetViewModel()
   viewModel:SetColor(255, 0, 0, 255)

function SWEP:Initialize()
   if CLIENT then
	  self:SetColor(255, 0, 0, 255)

function SWEP:Initialize()
   self:SetColor(255, 0, 0, 255)

Nothing worked. Any ideas?

One little hack I found:

hook.Add("PreDrawViewModel", "colorchange", function(viewmodel, ply, weapon)
    render.SetColorModulation(1, 0, 0)

Edit: Actually, setting the color of the viewmodel entity worked for me. Make sure you do it client-side though, won’t do anything server-side.

LocalPlayer():GetViewModel():SetColor(Color(255, 0, 0))

I’ll try it tomorrow. While we’re here. How would I format that so it affects the world model instead? And also how would I format that to affect both the view and world model? Thanks for your response!

use Entity:SetRenderMode(RENDERMODE_TRANSCOLOR) before you use SetColor. (Or TRANSALPHA if you want to use transparency as well.)

I think this is what you are looking for:

ply:SetPlayerColor( Vector( 1,0,0 ) )

No, I only want to set the color of the gun in the player’s hands. (World model)

[editline]26th December 2013[/editline]

Okay, Ronny, so I set this:

And it still looks like this:

My objective is for the view model, and the world model (Only the gun, not the player), to look like this:

Hopefully the images help shed some light.

You gotta use this hook to alter the view model: ( Choose one that works )

function SWEP:Initialize()
   if CLIENT then
      LocalPlayer():GetViewModel():SetColor(Color(255, 0, 0, 255))

This seems to have worked, but only in direct light, and it changes the hands too. Is there a workaround for that?

The hands and gun are the same model, but I’m sure there is some crazy bone stuff you could try.

Yeah there is a way using material parameters

Can find the material for the deagle and set $color2. Running this in console should set the deagle’s color to red.

lua_run_cl Material("models/weapons/v_models/pist_deagle/deagle_skin1"):SetVector("$color2", Vector(1, 0, 0))

But I’m not sure how to find the specific path based on the model.

The View Model entity is not weapon specific, there’s only one instance of it for each player. So if you change the color you should do it in the OnDeploy hook and set it back in the OnHolster hook so it doesn’t affect other weapons.

I get:

I was just about to post the exact same thing, the only thing is yeah it will affect every other thing using that material.

Luckily it seems view model uses a different texture for the gun than the world model so it doesn’t conflict.

Let me explain how I was going to use this. I was going to use it to make a Flare Gun for TTT using the Deagle model, but colored red. So from what you’re saying, that means if I use this technique, if the player has a Flare Gun and Deagle at the same time, they would both be red? Or can that be avoided using the OnDeploy and OnHolster?

In most cases they even have different models. viewmodels are usually more detailed and only designed to be seen in first person. World models are less detailed because you won’t be viewing them as close, so they save resources.

They probably also use much lower resolution textures.

Anything that uses the same texture will have whatever you’ve applied to the texture until you undo it.

Make the guns viewmodel material red, and SetColor the worldmodel red, so it won’t affect any other world models. Then change the viewmodel material back to white whenever the player holsters/dies etc.

Changing the viewmodel material is client side right? So anyone else using that model on a different entity wouldn’t be changed?

If you change the view model material and you don’t revert it back, if you spectate someone with a gun using that texture, they’ll have whatever you’ve applied to it.

Okay, would the texture revert upon rejoining the server / relaunching the game or would it stick like that permanently?

Would this be right? I’ve never used this function before.

function SWEP:Equip()
	RunConsoleCommand(lua_run_cl Material("models/weapons/v_models/pist_deagle/deagle_skin1"):SetVector("$color2", Vector(1, 0, 0)))

function SWEP:OnDrop()
	RunConsoleCommand(lua_run_cl Material("models/weapons/v_models/pist_deagle/deagle_skin1"):SetVector("$color2", Vector(0, 0, 0)))

Also, would I just set the world model with SetColor? Or would that only apply to the wielder? If so, how would I change that model so it appears to the whole server as red, but only for that entity, not for normal deagles?

Bump. Been busy the last few weeks. So in summary, I need to change both the view and world models, only the gun, not the player’s color, and only for a specific entity, not effecting any other entities that use that model or texture.