Player/AnimRestartGesture

From Garry's Mod
Jump to: navigation, search
 Player:AnimRestartGesture( )

Contents

Description

Restart a gesture on a player, within a gesture slot.

WARNING

This is not automatically networked. This function has to be called on the client to be seen by said client.

Arguments

number slot

Gesture slot using GESTURE_SLOT_ Enums

Arguments

number activity

The activity ( see ACT_ Enums ) or sequence that should be played

Arguments

boolean autokill=false

Whether the animation should be automatically stopped. true = stops the animation, false = the animation keeps playing/looping

Examples

Example

Defines part of a SWEP with pistol whipping functionality by using a pistol hold type and AnimRestartGesture for the melee attack animation.

function SWEP:Initialize()
	self:SetHoldType("pistol")
end

function SWEP:PrimaryAttack()

	-- Weapon attack delay
	self:SetNextPrimaryFire(CurTime()+0.5)

	-- Get entity in front of us
	local tr = util.TraceLine(util.GetPlayerTrace(self.Owner))
	
	local ent = tr.Entity
	
	-- If there's an enemy under 50 units in front of us
	if(IsValid(ent) && self.Owner:GetShootPos():Distance(tr.HitPos) < 50) then
	
		-- Play the melee attack animation
		self.Owner:AnimRestartGesture(GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, true)
		
		-- Create damage info (server-side)
		if SERVER then
		
			local dmg = DamageInfo()		
			dmg:SetDamage(math.random(5, 10))
			dmg:SetAttacker(self.Owner)
			dmg:SetInflictor(self)
			dmg:SetDamageForce(self.Owner:GetAimVector()*300)
			dmg:SetDamagePosition(tr.HitPos)
			dmg:SetDamageType(DMG_CLUB)
		
			-- Apply damage to enemy
			ent:TakeDamageInfo(dmg)
			
		end
		
		-- Play impact sound
		ent:EmitSound("physics/flesh/flesh_impact_bullet"..math.random(1, 5)..".wav")
		
		-- Make viewmodel pistol whip effect
		self.Owner:ViewPunch(Angle(0, 45, 0))
		
	else
	
		-- Typical pistol shot code goes here
		-- Some can be found in 'weapon_base/shared.lua'
	
	end
	
end


Personal tools
Navigation