GM:DoAnimationEvent

From Garry's Mod
Jump to: navigation, search
 GM:DoAnimationEvent( )

Contents

Description

Called upon an animation event, this is the ideal place to call player animation functions such as Player:AddVCDSequenceToGestureSlot, Player:AnimRestartGesture and so on.

Arguments

Player ply

Player who is being animated

Arguments

number event

Animation event. See PLAYERANIMEVENT_ Enums

Arguments

number data=0

The data for the event.

Returns

number

The translated activity to use. See ACT_ Enums, return ACT_INVALID if you don't want to send an activity.

Examples

Example

Fires a custom animation event with PLAYERANIMEVENT_ATTACK_GRENADE as the event, and 123 as the extra data on primary attack, and 321 as the secondary attack. The player will play the item throw gesture on the primary attack, and the drop one on secondary.

function SWEP:PrimaryAttack()
	self.Owner:DoCustomAnimEvent( PLAYERANIMEVENT_ATTACK_GRENADE , 123 )
	self:SetNextPrimaryFire(CurTime() + 0.5 )
	self:SetNextSecondaryFire(CurTime() + 0.5 )
end

function SWEP:SecondaryAttack()
	self.Owner:DoCustomAnimEvent( PLAYERANIMEVENT_ATTACK_GRENADE , 321 )
	self:SetNextPrimaryFire(CurTime() + 0.5 )
	self:SetNextSecondaryFire(CurTime() + 0.5 )
end

hook.Add("DoAnimationEvent" , "AnimEventTest" , function( ply , event , data )
	if event == PLAYERANIMEVENT_ATTACK_GRENADE then
		if data == 123 then
			ply:AnimRestartGesture( GESTURE_SLOT_GRENADE, ACT_GMOD_GESTURE_ITEM_THROW, true )
		end
		
		if data == 321 then
			ply:AnimRestartGesture( GESTURE_SLOT_GRENADE, ACT_GMOD_GESTURE_ITEM_DROP, true )
		end
		
		return ACT_INVALID
	end
end)


Personal tools
Navigation