I've been trying to make a grenade and I've been using the Counter Strike: Source model, I'm trying to make it so that when you hold down primary fire it would play the ACT_VM_PULLPIN animation until you release it to throw a grenade and when you press primary fire once it would also play the ACT_VM_PULLPIN throw out a grenade. I'm done with the pressed once animation, but I've been having a hard time with the held primary fire one.
Here's my code:
function SWEP:PrimaryAttack()
if !SERVER or self:Ammo1() <= 0 then return end
if self.pin == false then
self.pin = true
self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN)
end
if self.holding == false then
self.holding = true
end
self:SetNextPrimaryFire(CurTime() + 2)
end
function SWEP:Think()
if CLIENT or !IsValid(self) then return end
if self.holding == true and !self.Owner:KeyDown(IN_ATTACK) then
self.holding = false
if self.Weapon:GetSequence() == "idk" and self.anim2 == false then
self.anim2 = true
self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN)
timer.Simple(self.Weapon:SequenceDuration(), function()
self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:SendWeaponAnim(ACT_VM_THROW)
self:throw("grenade_ent")
self.anim2 = false
self.pin = false
self.holding = false
self.thrown = true
end)
else
self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:SendWeaponAnim(ACT_VM_THROW)
self:throw("grenade_ent")
self.anim2 = false
self.pin = false
self.holding = false
self.thrown = true
end
endend
I've been trying to use GetSequence() but for some reason it's always the ACT_WALK( 6 ) sequence and when the ACT_VM_PULLPIN the Sequence turns into ACT_COVER_LOW( 5 )
TL;DR
When I hold down the primary fire it plays the animation again when I release it.
I notice you send the ACT_VM_PULLPIN twice, once in the PrimaryFire and once in THINK, in the code block called when you release. This means you'll run the pullpin animation both when you click and release. Also, after the ACT_VM_THROW sequence has ended, you need to set ACT_VM_IDLE else a new grenade won't appear.
Sorry, you need to Log In to post a reply to this thread.