How to make the HoldType change of a weapon when being fired?

Is there a way I can make a holdtype change of a weapon when its firing and then back when you have stopped firing?

Just call the self:SetHoldType(str) ( Both serverside and clientside on all players )

Yas, but how would I make it change when it is being fired and being idle

Just call it when you shoot the bullet? Then use timer to create set it to idle?

I tried that but function SWEP:PrimaryWeapon and SecondaryWeapon are only in Client side. I can’t get it to be server side at the same time.

Shared.lua (Its under if CLIENT)



if (SERVER) then

	AddCSLuaFile( "shared.lua" )
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo			= false
	SWEP.AutoSwitchFrom		= false
	SWEP.HoldType			= "fist"

	local ActIndex = {}
		ActIndex[ "fist" ]		= ACT_HL2MP_IDLE_FIST

	function SWEP:SetWeaponHoldType( t )

		local index 								= ActIndex[ t ]
			
		if (index == nil) then
			return
		end

		self.ActivityTranslate 							= {}
		self.ActivityTranslate [ ACT_HL2MP_IDLE ] 			= index
		self.ActivityTranslate [ ACT_HL2MP_WALK ] 			= index + 1
		self.ActivityTranslate [ ACT_HL2MP_RUN ] 				= index + 2
		self.ActivityTranslate [ ACT_HL2MP_IDLE_CROUCH ] 		= index + 3
		self.ActivityTranslate [ ACT_HL2MP_WALK_CROUCH ] 		= index + 4
		self.ActivityTranslate [ ACT_HL2MP_GESTURE_RANGE_ATTACK ] 	= index + 5
		self.ActivityTranslate [ ACT_HL2MP_GESTURE_RELOAD ] 		= index + 6
		self.ActivityTranslate [ ACT_HL2MP_JUMP ] 			= index + 7
		self.ActivityTranslate [ ACT_RANGE_ATTACK1 ] 			= index + 8
	
		self:SetupWeaponHoldTypeForAI( t )
	end

end


if ( CLIENT ) then
	SWEP.PrintName			= "Fists"	
	SWEP.Author				= "Arken"
	SWEP.Purpose			= "Beating the crap out of people"
	SWEP.Instructions		= "Right-click to punch with Right Hand and Left-click ot punch with left hand"
	SWEP.DrawAmmo 			= false
	SWEP.DrawCrosshair 		= false
	SWEP.ViewModelFOV			= 57
	SWEP.ViewModelFlip		= false
	SWEP.CSMuzzleFlashes		= false
	
	SWEP.Slot				= 3
	SWEP.SlotPos			= 0
	SWEP.IconLetter			= "C"
end



SWEP.Category				= "leeroy weapon"

SWEP.Spawnable				= true
SWEP.AdminSpawnable			= true

SWEP.ViewModel 				= "models/weapons/v_fists.mdl"
SWEP.WorldModel 				= "" 

SWEP.Weight					= 5
SWEP.AutoSwitchTo				= false
SWEP.AutoSwitchFrom			= false

SWEP.Primary.ClipSize			= -1
SWEP.Primary.Damage			= 10
SWEP.Primary.DefaultClip		= -1
SWEP.Primary.Automatic			= false
SWEP.Primary.Ammo				= "none"

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


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


end

/*---------------------------------------------------------
Initialize
---------------------------------------------------------*/
function SWEP:Initialize() 
    
self:SetWeaponHoldType("fist")

 	if ( SERVER ) then 
 		self:SetWeaponHoldType( self.HoldType ) 
 	end 

util.PrecacheSound("physics/body/body_medium_impact_hard6.wav")
util.PrecacheSound("physics/body/body_medium_impact_hard5.wav")
util.PrecacheSound("physics/body/body_medium_impact_hard4.wav")
util.PrecacheSound("physics/body/body_medium_impact_hard2.wav")
util.PrecacheSound("physics/body/body_medium_impact_hard3.wav")
util.PrecacheSound("physics/body/body_medium_impact_hard1.wav")
util.PrecacheSound("weapons/iceaxe/iceaxe_swing1.wav")
util.PrecacheSound("weapons/slam/throw.wav")
 end 

/*---------------------------------------------------------
Deploy
---------------------------------------------------------*/
function SWEP:Deploy()
	self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
	self.Weapon:SetNextPrimaryFire(CurTime() + 0.7)
        self:DoIdle(3)
	return true
end

/*---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)

	local tr = {}
	tr.start = self.Owner:GetShootPos()
	tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 50 )
	tr.filter = self.Owner
	tr.mask = MASK_SHOT
	local trace = util.TraceLine( tr ) 

self:DoIdle(3) -- run our idle animation
        self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
	self.Weapon:SetNextSecondaryFire(CurTime() + 0.5)
	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_SECONDARYATTACK)
			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  = 10
			bullet.Damage = 20
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound( "physics/body/body_medium_impact_hard" .. math.random(1, 6) .. ".wav" )
		else
			self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
			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  = 10
			bullet.Damage = 20
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound( "physics/body/body_medium_impact_hard" .. math.random(1, 6) .. ".wav" )	
		end
	else
		self.Weapon:EmitSound( "weapons/slam/throw.wav" )
  self.Weapon:SetNextSecondaryFire(CurTime() + 0.5)
		self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
end
end

/*---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)

	local tr = {}
	tr.start = self.Owner:GetShootPos()
	tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 50 )
	tr.filter = self.Owner
	tr.mask = MASK_SHOT
	local trace = util.TraceLine( tr ) 

self:DoIdle(3) -- run our idle animation
        self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
	self.Weapon:SetNextSecondaryFire(CurTime() + 0.5)
	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_PRIMARYATTACK)
			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  = 10
			bullet.Damage = 10
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound( "physics/body/body_medium_impact_hard" .. math.random(1, 6) .. ".wav" )
		else
			self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
			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  = 10
			bullet.Damage = 10
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound( "physics/body/body_medium_impact_hard" .. math.random(1, 6) .. ".wav" )	
		end
	else
		self.Weapon:EmitSound( "weapons/slam/throw.wav" )
  self.Weapon:SetNextSecondaryFire(CurTime() + 0.5)
		self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
end
end

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

	return false
end

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

return true
end

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

timer.Destroy("PunchIdle")
	return true
end

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

end


/*---------------------------------------------------------
DrawWeaponSelection
---------------------------------------------------------*/
function SWEP:DoIdle(seconds)
	timer.Destroy("PunchIdle")
end


bumb