How To: Changing View-Models

When making a SWep, how could I do this:

Step 1: Holster the weapon, [lua]self:SendWeaponAnim( ACT_VM_HOLSTER )[/lua]
Step 2: Change the View Model…
Step 3: Draw the new weapon out,
[lua]self:SendWeaponAnim( ACT_VM_DRAW )[/lua]

[sp]To be frank, and not the guy… it has been months since I’ve done any programming, and more than a year since I was actually good at it. I may have never released anything, except a HUD on my old account, but that was simply because I never thought anything I did was incredible enough to warrant a release.[/sp]

An example would be: The weapon starts out as the Half-Life: Source Regular Pistol, but it changes into the Half-Life: 2 Regular Pistol.

[editline]18th August 2013[/editline]

Of course, I know that if you just change the Variable and switch away From, then back To the weapon, it will update the View Model. The idea is to update it without requiring a weapon switch.

You won’t be able to do so because viewmodel animations will break then. You’ll have to use 2 sweps.


function SWEP:SwapViewModel( target_mdl, index )
  index = index or 0

  local vm = self.Owner:GetViewModel( index )
    vm:SetWeaponModel( target_mdl, self )
    vm:RemoveEffects( EF_NODRAW )
  self:SendWeaponAnim( ACT_VM_DRAW )
end

--And then where you would change the model:
self:SwapViewModel( "path/to/model" )

I don’t know about animations breaking, but that’s how you’d go about it, I think.

Would you mind further explaining that, please? For instance, what is with the EF_NODRAW part? Also, what about the index variable?

It isn’t working this way…

[editline]1st September 2013[/editline]

I added holster before it calls this, and a timer to call it… all that happens is the weapon goes down, half a second later it comes back the same.

[editline]1st September 2013[/editline]

wrong… it works, but I have to switch weapons away from it, and then back to it…
and the weapon keeps drawing after I shoot… the reload animation does not play, either…

[editline]2nd September 2013[/editline]

Now… I could use more than one weapon, but then I have three variables to transfer between them:
1-3 Firing Mode Upgrade (Semi=Default) (Burst, Auto, Switchable)
1-2 Damage Upgrade (Enable Critical Shots, Double Damage)
1-2 Clip Size Upgrade (12, 6, 7=Defaults), (Enable One In Chamber, Multiply Default by 1.5)

The idea is that if the Player had an upgrade, they would not lose it, but rather adapt it to the new model. Well, the real idea is that they are adaptive weapons that all accept the same programming card…

And I know L4D does some of this, sorta… by changing the weapon in the slot. I just have to make sure the player switches to it, and I don’t know how to guarantee that seemlessly… holster, then give the new one after words, telling the player to use it?

ply:Strip(“halflifesourcepistol”)
ply:Give(“halflife2pistol”)
on a timer that starts when drawing

don’t I have to tell the Player to use the new weapon?