Facepunch / garrysmod-issues

Garry's Mod issue tracker
144 stars 56 forks source link

weapon:SetModel() causes vm sequences to mess up #5935

Closed mage-tearz closed 1 month ago

mage-tearz commented 3 months ago

Details

Setting the model of an active weapon causes its viewmodel sequences to mess up. By 'mess up' I mean they all become instant and the animations play as though they don't exist. This is being done with the base Half-Life 2 weapons. I am on the x86-64 branch, this is the version info:

Protocol version 24
Exe version 2023.06.28 (garrysmod)
Exe build: 19:41:45 Jun 17 2024 (9354) (4000)
GMod version 2024.07.10, branch: x86-64, multicore: 1
Windows 64bit

No console output is shown when running the below Lua script. Printing both the weapon's viewmodel and worldmodel clientside and serverside both return the proper results.

Steps to reproduce

  1. Set the player's weapon model to its current weapon model. wep:SetModel( wep:GetModel() )
  2. Reload the weapon after firing and see what happens
mage-tearz commented 3 months ago

If this somehow isn't a bug with the game and is intentional, is there a workaround for it? Some way to initialize the model's sequences and/or attachments without this happening?

robotboy655 commented 3 months ago

This is because there's a lot of spaghetti code when it comes to source weapons, while the weapon entity itself renders as the world model, its actually internally set to the "viewmodel model" most of the time, NOT the "worldmodel model". This happens when player equips the weapon.

You calling Entity:SetModel stomps that out, so serverside, when playing stuff like ACT_VM_RELOAD, it will search for that activity on the world model now (which doesn't have that activity), instead of the view model. You will notice that calling local wep = Entity(1):GetActiveWeapon() wep:SetModel( wep:GetWeaponViewModel() ) makes it work properly again.

mage-tearz commented 3 months ago

Thanks for explaining, i'll test it when I'm available. There's no way I would've figured that out without you telling me.