SWEP idle animations (HELP)

Hey, so ive been trying to add a idle animation: self.SendWeaponAnim(ACT_VM_IDLE) to my swep, but i want it to stop playing the idle animation when i either switch weapons, fire the weapon (secondary and primary), reload the weapon, or deploy the weapon. After that, if im not doing anything else i want it to play the idle animation over again. Any thoughts???

shared.lua :



if (SERVER) then
	AddCSLuaFile("shared.lua")
	SWEP.HoldType = "ar2"
end

if (CLIENT) then
	SWEP.PrintName = "HL:S MP5"			
	SWEP.ViewModelFOV = 90
    SWEP.Author = "DEATHMACHINEXI, Telemax, and KaleidonKep99 and not FiLzO :3"
	SWEP.Purpose = "Shoot Baddies Up"
	SWEP.Instructions = "MOUSE1: Fire/n/nFixed by KaleidonKep99"
	SWEP.Slot = 3
	SWEP.SlotPos = 5
	SWEP.IconLetter = "l"
end

function SWEP:Deploy()
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
end

function SWEP:PrimaryAttack()
	if (!self:CanPrimaryAttack()) then return end
	local bullet = {}
		bullet.Num = self.Primary.NumShots 
		bullet.Src = self.Owner:GetShootPos() 
		bullet.Dir = self.Owner:GetAimVector()
		bullet.Tracer = 1 
		bullet.Spread = Vector(0.04,0.04,0.04)
		bullet.Damage = self.Primary.Damage
		bullet.AmmoType = self.Primary.Ammo
		self.Owner:FireBullets( bullet )
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	self.Owner:MuzzleFlash()
	self.Owner:SetAnimation(PLAYER_ATTACK1)
	self.Weapon:EmitSound(Sound(self.Primary.Sound))
	self.Owner:ViewPunch(Angle( math.random(0.1,-1), math.random(-0.2,0.2), 0 ))
	if (self.Primary.TakeAmmoPerBullet) then
		self:TakePrimaryAmmo(self.Primary.NumShots)
	else
		if !self.Owner:IsNPC() then
			self:TakePrimaryAmmo(1)
		end
	end
	self.Owner:ViewPunch(Angle(-0.2,0.1,0))
	self.Owner:ViewPunch(Angle(0.4,0,0))
	self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
end

function SWEP:SecondaryAttack()
	if ( self:Ammo2() <= 0 ) then return end
	if ( !self:CanSecondaryAttack() ) and self.Weapon:WaterLevel() < 2 then return end
	local shoot_angle = Vector(0,0,0)
	local shoot_angle = self.Owner:GetAimVector()
	local shoot_pos   = self.Owner:GetPos() + self.Owner:GetRight() * 5 + self.Owner:GetUp() * 55 + shoot_angle * 100
	
		
	local shot = ents.Create( "grenade_ar2" )
	if ( IsValid( shot ) ) then
	
			shot:SetPos( shoot_pos )
			shot:SetAngles( shoot_angle:Angle() )
			shot:SetOwner( self.Owner )
			shot:SetModel("models/grenade.mdl")
			--shot:EmitSound("Weapon_Mortar.Incomming")
			shot.trail = util.SpriteTrail(shot, 0, Color(0,0,0,255), false, 10, 0, 0.5, 0, "trails/smoke.vmt");
			shot:Spawn()
			shot:SetVelocity( shoot_angle * 1000 )
	
	end
	self.Owner:MuzzleFlash()
	self.Weapon:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	self.Weapon:EmitSound(Sound(self.Secondary.Sound))
	self:TakeSecondaryAmmo(1)
	
	self.Weapon:SetNextSecondaryFire(CurTime() + 1.55)
	self.FireDelay = CurTime() + self.Primary.Delay
	self.Owner:ViewPunch(Angle( -8, 0, 0 ))
end

function SWEP:TakeSecondaryAmmo( num )

	if ( self.Weapon:Clip2() > 0 ) then 
	
		if ( self:Ammo2() <= 0 ) then return end
		
		self.Owner:RemoveAmmo( num, self.Weapon:GetSecondaryAmmoType() )
	
	return end
	
	self.Weapon:SetClip2( self.Weapon:Clip2() - num )
end

function SWEP:Ammo2()
	return self.Owner:GetAmmoCount( self.Weapon:GetSecondaryAmmoType() )
end

SWEP.Base = "weapon_base"
SWEP.Category = "Half-Life: Source"
SWEP.Spawnable = true
SWEP.ViewModel = "models/v_9mmar.mdl"
SWEP.WorldModel = "models/w_9mmar.mdl"
SWEP.Weight = 5
SWEP.FiresUnderwater	= false
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Primary.Sound = Sound("weapons/hl1/hks" .. math.random(1,3) .. ".wav")
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 5
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0.03
SWEP.Primary.ClipSize = 50
SWEP.Primary.Delay = 0.10
SWEP.Primary.DefaultClip = 100
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "SMG1"
SWEP.Secondary.Sound = Sound("9mmGrenade.Play")
SWEP.Secondary.DefaultClip = 2
SWEP.Secondary.NumShots = 1
SWEP.Secondary.Ammo = "SMG1_Grenade"
SWEP.Secondary.ClipSize = 10

local Time = CurTime()

function SWEP:Reload()
	if ( self.Weapon:Ammo1() <= 0 ) then return end
	if ( self.Weapon:Clip1() >= self.Primary.ClipSize ) then return end
	if (CurTime() < Time + 0.5) then return end --Replace here
	Time = CurTime()
	
       --And between these
	timer.Simple(0.25,function() 
	if IsValid(self.Weapon) then
	self.Weapon:EmitSound("weapons/hl1/9mmarclip2.wav") 
	end
	end)
       --And between these
	
	self.Owner:SetAnimation(PLAYER_RELOAD)
	self.Weapon:DefaultReload(ACT_VM_RELOAD)
end


Any help is greatly appreciated and helpful for future knowledge and know-how. :):):smiley:

bump

anyone?

Look at how the fists does it with the NextIdle NetworkVar: https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/weapons/weapon_fists.lua

After attacking and sending the firing animation, it sets the idle animation to play after the last anim has completed by comparing the time in a think hook. That’s how Source weapons typically handle “smooth” animations, except it checks before a frame is ran.

I’ll try using that line!

[editline]1st October 2015[/editline]

Didnt work :frowning: i used all instances of update next idle and set next idle aswell

Post your new code

I just figured out that nothing except the line: self.SendWeaponAnim(ACT_VM_IDLE) will work because these weapons dont support the hl2 weapons base. I had to manually script the weapon myself because there was no support for default animations. Thats why all the other animation lines had to be implemented in manually such as: self.Weapon:SendWeaponAnim(ACT_VM_DRAW) for deploy…This one is tricky :frown: