Code issue

Notice the barrel:

This is the code demonstrated in the video above:


function SWEP:Deploy()
			self.Weapon:SendWeaponAnim(ACT_VM_ATTACH_SILENCER)
			self.Primary.Sound			= Sound("weapons/sk_m4a1/m4a1-1.wav")
 			self.data.silenced = true
end

Any help is appreciated
Thanks

Show the primary fire code, you probably made it so when it shoots, there’s the non-silenced version.


function SWEP:PrimaryAttack()

if self:CanPrimaryAttack() then
		self:FireRocket()
		self.Weapon:EmitSound(self.Primary.Sound)
		self.Weapon:TakePrimaryAmmo(1)
		self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
		local fx 		= EffectData()
		fx:SetEntity(self.Weapon)
		fx:SetOrigin(self.Owner:GetShootPos())
		fx:SetNormal(self.Owner:GetAimVector())
		fx:SetAttachment(self.MuzzleAttachment)
		util.Effect("gdcw_muzzle",fx)
		self.Owner:SetAnimation( PLAYER_ATTACK1 )
		self.Owner:MuzzleFlash()
		self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
		self.data.silenced = true

	end
end

I believe you should add the following to your primary fire:

self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_SILENCED);

And in the Think:

self.Weapon:SendWeaponAnim(ACT_VM_IDLE_SILENCED);

Thanks, but I get an error: [addons\m4\lua\weapons\sk_m4a1\shared.lua:50] ‘)’ expected near ‘LENCED’

EDIT: Wait no that worked, there was a space in SILENCED.
Thanks again.

EDIT2: No animations are playing now.
Here’s some code:


function SWEP:PrimaryAttack()

if self:CanPrimaryAttack() then
		self:FireRocket()
		self.Weapon:EmitSound(self.Primary.Sound)
		self.Weapon:TakePrimaryAmmo(1)
		self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_SILENCED);
		self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
		local fx 		= EffectData()
		fx:SetEntity(self.Weapon)
		fx:SetOrigin(self.Owner:GetShootPos())
		fx:SetNormal(self.Owner:GetAimVector())
		fx:SetAttachment(self.MuzzleAttachment)
		util.Effect("gdcw_muzzle",fx)
		self.Owner:SetAnimation( PLAYER_ATTACK1 )
		self.Owner:MuzzleFlash()
		self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
		

	end
end

function SWEP:Deploy()
			self.Weapon:SendWeaponAnim(ACT_VM_ATTACH_SILENCER)
			self.Primary.Sound			= Sound("weapons/sk_m4a1/m4a1-1.wav")
 			self.data.silenced = true
end

function SWEP:Think()

self:IronSight()
self.Weapon:SendWeaponAnim(ACT_VM_IDLE_SILENCED);

end

function SWEP:Reload()

	self.Weapon:DefaultReload(ACT_VM_RELOAD) 
	if !self.Owner:IsNPC() then
	self.ResetSights = CurTime() + self.Owner:GetViewModel():SequenceDuration() end


	if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and !self.Owner:IsNPC() then
	

		self.Owner:SetFOV( 0, 0.3 )
		

		self:SetIronsights(false)
		

end
	
end

[LUA]
self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_SILENCED);
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
[/LUA]

Remove the second one.

Still no animations.

Does the model have animations for firing with a silencer?

Are you sure the one in the Think function should be there?

I don’t know for sure but from looking at it whenever you change the animation think is going to change it back to idle immediately?

This is what’s happening

Thank you, so much. It’s working now, thank you everyone for the help.