Engine icon indicating copy to clipboard operation
Engine copied to clipboard

Impossibility of a dynamic viewmodel change

Open Hambrix opened this issue 2 years ago • 1 comments

Describe the bug

It's possible to change player's model via 'setmodel' command in real time, but for some reason that doesn't work for the viewmodel.

VScript implementation example:

function SwapViewmodel()
{
EntityGroup[2].SetModel("models/weapons/v_viewmodelname.mdl");
EntityGroup[3].SetModel("models/weapons/v_viewmodelname.mdl");
}

image

To Reproduce

Make it possible to change the viewmodel in real time.

Issue Map


Expected Behavior

Current viewmodel will change to a different one.

Operating System

No response

Hambrix avatar Jan 09 '24 16:01 Hambrix

I feel like this is more overcomplicated than it should be. You can just get the ViewModel using Entities.FindByClassname. The only pitfall with this is that in SP it's viewmodel, in MP it's predicted_viewmodel.

local entity = Entities.FindByClassname(null, "viewmodel");
entity.SetModel("models/weapons/v_357.mdl");

or this in the console

script Entities.FindByClassname(null, "viewmodel").SetModel("models/weapons/v_357.mdl")

Maybe we could expose this in a better way, but if you're doing it through vscript this is the preferred method.

AWildErin avatar Jan 19 '24 05:01 AWildErin