I'm trying to create fully server-side custom viewmodels that are predicted by the client.
Doing this for No More Room in Hell but process probably translates over to other games.
All videos were recorded with net_fakelag 200 and changing the original model from a Glock to an M92FS
Approach #1:
Edit the existing predicted_viewmodel.
Pros: Client predicts properly ..sorta
Dealbreaker: Viewmodel flickers when the animations loop around, even if they are the same length. This issue doesn't seem to affect CSGO for some reason.
https://gfycat.com/passionateunawareaztecant
PHP Code:
public Action OverrideViewmodel(int client, int args)
{
int vm = GetEntPropEnt(client, Prop_Data, "m_hViewModel", 0);
SetEntProp(vm, Prop_Send, "m_nModelIndex", customModel);
return Plugin_Handled;
}
Approach #2:
Create a prop_dynamic and bonemerge to the original viewmodel
Pros: Perfect client side prediction!
Dealbreaker: Model is offset forward and cannot be repositioned. It also clips the player hull making it not render properly. I could painstakingly fix the FOV by editing the .mdl file but the clipping issue remains
https://gfycat.com/athleticexemplaryglassfrog
PHP Code:
public Action CreateFakeViewmodel(int client, int args)
{
int prop = CreateEntityByName("prop_dynamic_override");
DispatchKeyValue(prop, "model", "models/weapons/fa_m92fs/v_fa_m92fs.mdl");
DispatchKeyValue(prop, "disablereceiveshadows", "1");
DispatchKeyValue(prop, "disableshadows", "1");
DispatchKeyValue(prop, "solid", "0");
DispatchSpawn(prop);
SetEntityMoveType(prop, MOVETYPE_NONE); // Needed to animate
int viewmodel = GetEntPropEnt(client, Prop_Data, "m_hViewModel", 0);
SetVariantString("!activator");
AcceptEntityInput(prop, "SetParent", viewmodel);
SetEntProp(prop, Prop_Send, "m_fEffects", EF_BONEMERGE); // Also needed to animate
ReplyToCommand(client, "Created fake viewmodel %d", prop);
return Plugin_Handled;
}
Approach #3:
Create a new predicted_viewmodel (CCSPlayer::CreateViewModel)
Pros: Displays at the right position and doesn't clip
Dealbreaker: Can't get it to animate without manually setting the sequence, which wouldn't play nicely with client prediction
https://gfycat.com/smartpettyacouchi
PHP Code:
public Action CreateRealViewmodel(int client, int args)
{
int index = 1;
SDKCall(fnCreateViewmodel, client, index);
int vm2 = GetEntPropEnt(client, Prop_Data, "m_hViewModel", index);
SetEntityModel(vm2, "models/weapons/fa_m92fs/v_fa_m92fs.mdl");
// ... What to do now? Setting m_hWeapon doesn't help
ReplyToCommand(client, "Created real viewmodel %d", vm2);
}
So yeah, curious if anyone knows how to fix any of these or has another working method, I'm out of ideas at this point
Here's the full test script
https://hatebin.com/wsyflqvnqc