• Proper way to holster a weapon with animation?
    7 replies, posted
I'm confused as to why this code isn't working: [CODE] function SWEP:Holster() self:SetNWBool("Reloading",false) if (timer.Exists(self:EntIndex().."HolsterTimer")) then timer.Destroy(self:EntIndex().."HolsterTimer") end if (timer.Exists(self:EntIndex().."DrawTimer")) then timer.Destroy(self:EntIndex().."DrawTimer") end if (timer.Exists(self:EntIndex().."ReloadTimer")) then timer.Destroy(self:EntIndex().."ReloadTimer") end print(self.canholster) if self.canholster==false then self.Weapon:SendWeaponAnim( ACT_VM_HOLSTER ) local AnimationTime = self.Owner:GetViewModel():SequenceDuration() print(AnimationTime) timer.Create( self:EntIndex().."HolsterTimer",AnimationTime, 1, function() if IsValid(self) then self.canholster=true self:Holster() end end) end if self.canholster==true then return true end end [/CODE] Any help would be appreciated, and quickly if possible!
What model are you using
A custom viewmodel I made with a proper holster sequence. The QC lines in question: [code] $sequence "holster" "anims\holster.smd" { fps 26 activity "ACT_VM_HOLSTER" 1 { event 5004 24 "SF2Bow.Deploy" } { event 5004 26 "SF2Bow.String" } { event 5004 29 "SF2Bow.Nock" } } [/code]
Is it just not printing to console or does it error [editline]15th February 2015[/editline] Also I reccommend you turn this [code]if self.canholster==false then[/code] into a networked variable using either SetNWBool or the data table system; this is the most likely reason your code isn't working from the information you've given You see, the viewmodel animation system is a funny one - it needs to be animated on both server and client to work.
It was printing to console, and even printing true on both the client and server. However, I would have to hit the holster button again to switch.
[QUOTE=GreyGeist;47151352]It was printing to console, and even printing true on both the client and server. However, I would have to hit the holster button again to switch.[/QUOTE] Well the variable you use has to be networked otherwise it'll sometimes be false on server while on client it could be true.
[QUOTE=BFG9000;47151558]Well the variable you use has to be networked otherwise it'll sometimes be false on server while on client it could be true.[/QUOTE] I get the same problem with a NWBoolean. Code: [code] function SWEP:Holster() self:SetNWBool("Reloading",false) if (timer.Exists(self:EntIndex().."HolsterTimer")) then timer.Destroy(self:EntIndex().."HolsterTimer") end if (timer.Exists(self:EntIndex().."DrawTimer")) then timer.Destroy(self:EntIndex().."DrawTimer") end if (timer.Exists(self:EntIndex().."ReloadTimer")) then timer.Destroy(self:EntIndex().."ReloadTimer") end print(self.Weapon:GetNWBool("CanHolster",false)) if self.Weapon:GetNWBool("CanHolster",false)==false then if !( timer.Exists( self:EntIndex().."HolsterTimer" ) ) then self.Weapon:SendWeaponAnim( ACT_VM_HOLSTER ) local AnimationTime = self.Owner:GetViewModel():SequenceDuration() print(AnimationTime) timer.Create( self:EntIndex().."HolsterTimer",AnimationTime, 1, function() if IsValid(self) then self.Weapon:SetNWBool("CanHolster",true) self:Holster() end end) end end if self.Weapon:GetNWBool("CanHolster",false)==true then return true end end [/code] Console output in MP: [code] false 1.1923077278412 false 1.1923077278412 false 1.1923077278412 false 1.1923077278412 false 1.1923077278412 false 1.1923077278412 true true [/code] Console output in SP: [code] false 1.1923077278412 true [/code]
Got it working. The only remaining problem is that the weapon you're switching FROM doesn't get marked as your previous weapon. Is it possible to see/create a backup function of the default holster code? [CODE] function SWEP:Holster( switchtowep ) if switchtowep then self.Weapon:SetNWEntity("SwitchToWep",switchtowep) end self:SetNWBool("Reloading",false) if (timer.Exists(self:EntIndex().."DrawTimer")) then timer.Destroy(self:EntIndex().."DrawTimer") end if (timer.Exists(self:EntIndex().."ReloadTimer")) then timer.Destroy(self:EntIndex().."ReloadTimer") end if self.Weapon:GetNWBool("CanHolster",false)==false then if !( timer.Exists( self:EntIndex() .."HolsterTimer" ) ) then self.Weapon:SendWeaponAnim( ACT_VM_HOLSTER ) local AnimationTime = self.Owner:GetViewModel():SequenceDuration() timer.Create( self:EntIndex().."HolsterTimer",AnimationTime, 1, function() self.Weapon:SetNWBool("CanHolster",true) self.Weapon:Holster( ) end end) else if timer.TimeLeft( self:EntIndex() .."HolsterTimer" )<0.02 then self.Weapon:SetNWBool("CanHolster",true) self.Weapon:Holster( ) return true end end else local wep=self.Weapon:GetNWEntity("SwitchToWep",switchtowep) if IsValid( wep ) and IsValid(self.Owner) and self.Owner:HasWeapon( wep:GetClass() ) then if self.Owner.SetActiveWeapon then self.Owner:SetActiveWeapon( wep ) if wep.Deploy then wep:Deploy() else wep:SendWeaponAnim( ACT_VM_DRAW ) end end end return true end end [/CODE]
Sorry, you need to Log In to post a reply to this thread.