Garry's Mod Wiki

ENTITY:HandleAnimEvent

  boolean ENTITY:HandleAnimEvent( number event, number eventTime, number cycle, number type, string options )

Description

Called before firing serverside animation events, such as weapon reload, drawing and holstering for NPCs, scripted sequences, etc.

See ENTITY:FireAnimationEvent for the clientside version.

This hook only works on "anim", "ai" and "nextbot" type entities.

Arguments

1 number event
The ID of the event. See this page for a list of default events, and see util.GetAnimEventNameByID for a helper function in handing custom events.
2 number eventTime
The absolute time this event occurred using CurTime.
3 number cycle
The frame this event occurred as a number between 0 and 1.
4 number type
Event type. See the Source SDK.
5 string options
Name or options of this event.

Returns

1 boolean
Return true to mark the event as handled.

Example

Handle a custom animation event.

The .qc of the model would look something like this:

$sequence my_sequence_name "my_smd_name" ..... { { event MY_CUSTOM_ANIM_EVENT 2 "my custom options" } }
function ENT:HandleAnimEvent( event, eventTime, cycle, type, options ) if ( util.GetAnimEventNameByID( event ) == "MY_CUSTOM_ANIM_EVENT" ) then print( "Do something..." ) return true end end