weapon animation

Help, I have no animation on the weapon is the reason?






if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	SWEP.HoldType			= "melee2"
	
end

if ( CLIENT ) then

         SWEP.PrintName	            = "Sledge Hammer"	 
         SWEP.Author				= "Ryan Kingstone"
         SWEP.Category				= "Simple Melee"
         SWEP.Slot			        = 0					 
         SWEP.SlotPos		        = 1
         SWEP.DrawAmmo                  = false					 
         SWEP.IconLetter			= "w"

         killicon.AddFont( "weapon_crowbar", 	"HL2MPTypeDeath", 	"6", 	Color( 255, 80, 0, 255 ) )

end


SWEP.Base				= "weapon_base"

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel		= "models/weapons/v_sledgehammer/v_sledgehammer.mdl"	 
SWEP.WorldModel		= "models/weapons/w_sledgehammer.mdl"	
SWEP.DrawCrosshair              = false

SWEP.ViewModelFOV = 60
SWEP.ViewModelFlip = false


SWEP.Weight				= 1			 
SWEP.AutoSwitchTo		= true		 
SWEP.AutoSwitchFrom		= false	
SWEP.CSMuzzleFlashes		= false	  	 		 
		 
SWEP.Primary.Damage			= 52						 			  
SWEP.Primary.ClipSize		= -1		
SWEP.Primary.Delay			= 2.0 		  
SWEP.Primary.DefaultClip	= 1		 
SWEP.Primary.Automatic		= true		 
SWEP.Primary.Ammo			= "none"	 

SWEP.Secondary.ClipSize		= -1			
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Damage			= 0		 
SWEP.Secondary.Automatic		= false		 
SWEP.Secondary.Ammo			= "none"

SWEP.MissSound 				= Sound("weapons/knife/knife_slash1.wav")
SWEP.WallSound 				= Sound("weapons/melee/shovel/shovel_hit-04.wav")

function SWEP:Initialize()
	self:SetWeaponHoldType( "melee2" )
end

function SWEP:SecondaryAttack()
	return false
end

/*---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
	self.Owner:LagCompensation( true )
	local tr = {}
	tr.start = self.Owner:GetShootPos()
	tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 95 )
	tr.filter = self.Owner
	tr.mask = MASK_SHOT
	local trace = util.TraceLine( tr )

	self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
	self.Owner:SetAnimation( PLAYER_ATTACK1 )

	if ( trace.Hit ) then

		if trace.Entity:IsPlayer() or string.find(trace.Entity:GetClass(),"npc") or string.find(trace.Entity:GetClass(),"prop_ragdoll") then
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
			bullet = {}
			bullet.Num    = 1
			bullet.Src    = self.Owner:GetShootPos()
			bullet.Dir    = self.Owner:GetAimVector()
			bullet.Spread = Vector(0, 0, 0)
			bullet.Tracer = 0
			bullet.Force  = 1
			bullet.Damage = self.Primary.Damage
			self.Owner:FireBullets(bullet) 
		else
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
			bullet = {}
			bullet.Num    = 1
			bullet.Src    = self.Owner:GetShootPos()
			bullet.Dir    = self.Owner:GetAimVector()
			bullet.Spread = Vector(0, 0, 0)
			bullet.Tracer = 0
			bullet.Force  = 1
			bullet.Damage = self.Primary.Damage
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound( self.WallSound )		
			util.Decal("ManhackCut", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
		end
	else
		self.Weapon:EmitSound(self.MissSound,100,math.random(90,120))
		self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
	end
	
	timer.Simple( 0.05, function()
			self.Owner:ViewPunch( Angle( 20, 45, 0 ) )
	end )

	timer.Simple( 0.2, function()
			self.Owner:ViewPunch( Angle( 17, 30, 0 ) )
	end )
		
	self.Owner:LagCompensation( false )
end

/*---------------------------------------------------------
Reload
---------------------------------------------------------*/
function SWEP:Reload()

	return false
end

/*---------------------------------------------------------
OnRemove
---------------------------------------------------------*/
function SWEP:OnRemove()

return true
end

/*---------------------------------------------------------
Holster
---------------------------------------------------------*/
function SWEP:Holster()

	return true
end


Using timers in PrimaryAttack or SecondaryAttack isn’t wise because of the way SWEPs work. Basically the CLIENT spams the function call while the server calls it once ( and this may or may not repeat depending on automatic setting; but each time the server calls it once, the client could be calling it 10 times ).

Also, View-punch alone is not a good recoil system because despite the point of “aim” shifting, the point of impact will remain the same for each successive frame, meaning it serves only to confuse those that don’t know what it is doing. For those that know, they know not to move their mouse up or down and they’ll get perfect shots all day long. Use Set Eye Angles; maybe even in conjunction with view-punch…

Next, self.Weapon is deprecated. A SWEP is the weapon meaning self is the weapon, no need to use self.Weapon because self describes the weapon…

Animations can be tricky or won’t work if not done correctly. I’m no expert but I’ve always called weapon animation first, followed by the thirdperson animation which everyone else sees. Make sure the weapon model HAS the animation you’re trying to play.

For certain actions, you may want to use IsFirstTimePredicted for some of the CLIENT side to ensure it executes once, when the server and client sync up.

The bottom line is that if you look from the first person there is always a animation, but from the third is not.

I looked over my files and I use the following:


self.Owner:SetAnimation( PLAYER_ATTACK1 );
self:SendWeaponAnim( ACT_VM_MISSCENTER );
	


function SWEP:ShootEffects( muzzle, ejectionPort )
	if ( !muzzle ) then return; end


	if ( self.PrimaryAnimation ) then
		self:SendWeaponAnim( self.Animations.vmprimaryattack );
		self.Owner:SetAnimation( self.Animations.primaryattack );
	



SWEP.Animations = {
	melee_attack				= ACT_VM_HITCENTER;
	melee_miss					= ACT_VM_MISSCENTER;

	primaryattack 				= PLAYER_ATTACK1;
	vmprimaryattack 			= ACT_VM_PRIMARYATTACK;

	reload 						= PLAYER_RELOAD;
	vmreload 					= ACT_VM_RELOAD;
};
	

I haven’t had a weapon that I’ve had to alter these form, they seem to work fine… I don’t use LagCompensation in my Primary Attack though ( remember that’s being called many times over by the client )…

Also, the client-side Fire Animation Event does play a part in certain things…


//
// Fixes Double MuzzleFlash and other issues = Josh 'Acecool' Moser
//
function SWEP:FireAnimationEvent( _pos, _ang, _event, _options )
	-- Disables animation based muzzle _event
	if ( _event == 20 ) then return true end

	-- Disable thirdperson muzzle flash
	if ( _event == 5001 ) then return true end
end

	-- if ( _event == 5003 ) then return true end
	-- print( "FireAnimationEvent", _pos, _ang, _event, _options );
	

Are you testing in SRCDS or ListenServer ( server started from gmod client ) or SinglePlayer ( maxplayers == 1 )?

I highly recommend using SRCDS: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html

You can even launch multiple GMod clients by adding -multirun -steam to your launch options, and adding sv_lan 1 to server.cfg

You can put the clients side by side and see what other players would see…