Change weapon view model/world model

Hi,
How do you change a weapon view model and world model (clientside) ?

I tried this, but it seems to do nothing:



local knife = weapons.GetStored("weapon_mu_knife")
local gun = weapons.GetStored("weapon_mu_magnum")

local defaultKnifeViewModel = "models/weapons/v_smg1.mdl"
local defaultKnifeWorldModel = "models/weapons/w_smg1.mdl"

local defaultGunViewModel = "models/weapons/v_smg1.mdl"
local defaultGunWorldModel = "models/weapons/w_smg1.mdl"

local function updateKnifeViewModel(knifeViewModel)
	if knife ~= nil then
		knife.ViewModel = knifeViewModel
	end
end

local function updateKnifeWorldModel(knifeWorldModel)
	if knife ~= nil then
		knife.WorldModel = knifeWorldModel
	end
end

local function updateGunViewModel(gunViewModel)
	if gun ~= nil then
		gun.ViewModel = gunViewModel
	end
end

local function updateGunWorldModel(gunWorldModel)
	if gun ~= nil then
		gun.WorldModel = gunWorldModel
	end
end

updateKnifeViewModel(defaultKnifeViewModel)
updateKnifeWorldModel(defaultKnifeWorldModel)
updateGunViewModel(defaultGunViewModel)
updateGunWorldModel(defaultGunWorldModel)


Thanks,

I believe weapon:GetViewModel():SetModel(modelname) would do the job better.

It’s doesn’t work, GetViewModel() is for the player not the weapon



knife.ViewModel = defaultKnifeViewModel


should do the trick? Simply edit its ViewModel variable.

[editline]27th July 2016[/editline]

You cant set a model on a string.

You cannot just edit a variable and expect it to change immediately. You need to call a function which does that. Also, my mistake, should have written weapon.Owner:GetViewModel():SetModel(modelname), and whitestar, GetViewModel returns the entity, not string.

This code change the model of the view model, so it’s change when I take another weapon ?
I just want to change the model of a specific weapon.
By the way weapon.Owner return nil for me

What are you even trying to do? Why dont you just change the models in the weapons shared.lua?

I am trying to do it client side, so I can’t edit server files.

Unless the server has clientside scripts enabled, you cannot do it.

Yes it’s enabled. So I can

try



LocalPlayer():GetViewModel():SetModel(YourModelHere)


Since if I understood right, you only want to draw it for 1 specific player, with sv_allowcslua. Then it SHOULD work.

I don’t want to set the viewmodel of the player, but overwrite the model of a specific weapon.

But you cannot do that.