Animations
The Animations module provides a comprehensive animation system for FiveM resources with advanced features including prop handling, animation sequences, scenarios, and automatic cleanup.
play
Plays an animation on an entity with comprehensive options and tracking.
B2Lib.Animations.play(entity, animDict, animName, options)
Parameters:
entity
(number): The entity to animate (ped, vehicle, etc.)animDict
(string): The animation dictionary nameanimName
(string): The animation name within the dictionaryoptions
(table, optional): Animation configuration optionsflag
(number): Animation flags (default: 0)blendInSpeed
(number): Blend in speed (default: 8.0)blendOutSpeed
(number): Blend out speed (default: 8.0)duration
(number): Duration in ms (-1 for infinite, default: -1)playbackRate
(number): Animation speed multiplier (default: 1.0)lockX
(boolean): Lock X movement (default: false)lockY
(boolean): Lock Y movement (default: false)lockZ
(boolean): Lock Z movement (default: false)onStart
(function): Start callbackonComplete
(function): Completion callbackonStop
(function): Stop callback
Returns: number|nil - Animation ID for tracking, nil if failed
Example:
local animId = B2Lib.Animations.play(PlayerPedId(), "mp_player_inteat@burger", "mp_player_int_eat_burger", {
duration = 5000,
flag = 49,
onComplete = function(id, entity)
print("Animation completed!")
end
})
playWithProp
Plays an animation with an attached prop.
B2Lib.Animations.playWithProp(entity, animDict, animName, propModel, options)
Parameters:
entity
(number): The entity to animateanimDict
(string): The animation dictionary nameanimName
(string): The animation namepropModel
(string|number): The prop model name or hashoptions
(table, optional): Animation and prop configuration optionsbone
(number): Attachment bone (default: 18905)offset
(table): Position offset {x, y, z} (default: {x=0, y=0, z=0})rotation
(table): Rotation offset {x, y, z} (default: {x=0, y=0, z=0})deleteOnStop
(boolean): Delete prop when animation stops (default: true)networkOwned
(boolean): Network ownership (default: false)Plus all animation options from
play
Returns: number|nil - Animation ID for tracking, nil if failed
Example:
local eatId = B2Lib.Animations.playWithProp(
PlayerPedId(),
"mp_player_inteat@burger",
"mp_player_int_eat_burger",
"prop_cs_burger_01",
{
duration = 8000,
bone = 18905,
offset = {x = 0.12, y = 0.028, z = 0.001},
deleteOnStop = true
}
)
stop
Stops a specific animation by its tracking ID.
B2Lib.Animations.stop(animId)
Parameters:
animId
(number): The animation ID to stop
Returns: boolean - True if animation was stopped, false if not found
stopAllOnEntity
Stops all animations currently playing on a specific entity.
B2Lib.Animations.stopAllOnEntity(entity)
Parameters:
entity
(number): The entity to stop animations on
Returns: number - The number of animations that were stopped
isPlaying
Checks if a specific animation is currently playing.
B2Lib.Animations.isPlaying(animId)
Parameters:
animId
(number): The animation ID to check
Returns: boolean - True if the animation is playing, false otherwise
getProgress
Gets the progress of a timed animation (0.0 to 1.0).
B2Lib.Animations.getProgress(animId)
Parameters:
animId
(number): The animation ID to check
Returns: number - Animation progress (0.0-1.0), or -1 if not found or infinite duration
playSequence
Plays a sequence of animations in order.
B2Lib.Animations.playSequence(entity, sequence, options)
Parameters:
entity
(number): The entity to animatesequence
(table): Array of animation stepsoptions
(table, optional): Sequence configuration optionsloop
(boolean): Loop the sequence (default: false)onSequenceComplete
(function): Callback when sequence completesonStepComplete
(function): Callback when each step completes
Returns: number|nil - Sequence ID for tracking, nil if failed
playScenario
Plays a scenario animation (ambient animations).
B2Lib.Animations.playScenario(entity, scenarioName, options)
Parameters:
entity
(number): The entity to animatescenarioName
(string): The scenario nameoptions
(table, optional): Scenario configuration optionsduration
(number): Duration in ms (-1 for infinite, default: -1)onStart
(function): Start callbackonComplete
(function): Completion callback
Returns: number|nil - Scenario ID for tracking, nil if failed
stopScenario
Stops a scenario animation.
B2Lib.Animations.stopScenario(scenarioId)
Parameters:
scenarioId
(number): The scenario ID to stop
Returns: boolean - True if scenario was stopped, false if not found
getActiveAnimations
Gets all active animations for an entity.
B2Lib.Animations.getActiveAnimations(entity)
Parameters:
entity
(number): The entity to check (optional, returns all if not provided)
Returns: table - Array of active animation objects
cleanup
Manually triggers cleanup of expired animations.
B2Lib.Animations.cleanup()
Returns: number - Number of animations cleaned up
Configuration
Configure the animation system in config.lua
:
Config.Animations = {
cleanupInterval = 30000, -- Cleanup every 30 seconds
maxAnimationsPerEntity = 10, -- Prevent animation spam
defaultBlendSpeed = 8.0, -- Default blend in/out speed
debugMode = false -- Enable debug logging
}
Troubleshooting
Animations Not Playing
Check that the animation dictionary exists and is loaded
Verify the animation name is correct
Ensure the entity is valid and exists
Check console for error messages
Props Not Attaching
Verify the prop model exists
Check bone ID is correct (18905 for right hand)
Ensure prop model is loaded before use
Verify offset and rotation values
Performance Issues
Use cleanup() to remove expired animations
Limit animations per entity using maxAnimationsPerEntity
Set reasonable durations to prevent buildup
Monitor active animations with getActiveAnimations()
Memory Leaks
Always stop animations when no longer needed
Enable automatic cleanup in configuration
Use deleteOnStop for props
Monitor animation count in production
Last updated