- Documentation
- Shared functions
- setPedAnimation
Function
setPedAnimation
Plays an animation on a ped. The animation comes from a game animation block (e.g. ped, dancing, smoking) or from an IFP file loaded with engineLoadIFP. Calling it without a block stops the animation. On the server the animation reaches every player. On the client it only runs in this game: for the local player others see it through pose streaming; for a remote player the function returns false because their appearance comes from their own game.
Syntax
bool setPedAnimation(ped ped [, string block = nil, string anim = nil, int time = -1, bool loop = true, bool updatePosition = true, bool interruptable = true, bool freezeLastFrame = true, int blendTime = 250, bool retainPedState = false, bool movable = auto])Arguments
pedped- A player or an NPC.
blockstring, optional = nil- Animation block name, e.g.
"ped","dancing","BEACH", or a block fromengineLoadIFP. Omitted = stop the animation. animstring, optional = nil- Animation name within the block, e.g.
"WEAPON_crouch","dnce_M_a". timeint, optional = -1- How long the animation lasts in ms; -1 = all of it (or forever when looped).
loopbool, optional = truetrue= the animation loops.updatePositionbool, optional = truetrue= the animation moves the ped (e.g. walking),false= the ped stays in place.interruptablebool, optional = truetrue= the player can interrupt the animation by moving.freezeLastFramebool, optional = truetrue= after the animation ends, the ped holds the last frame.blendTimeint, optional = 250- Blend time from the previous pose in ms.
retainPedStatebool, optional = falsetrue= the ped keeps its state (e.g. weapon in hand) after the animation.movablebool, optional = autotrue= the animation plays on the upper body only and the ped can still walk, run and turn (like carrying a box withCARRY/crry_prtialin the game). Omitted =truefor animations withprtialin the name, otherwisefalse.Not in MTA:SA
Differences from MTA:SA
- Arguments in a different colour differ from MTA:SA.
In MTA:SA
setPedAnimation(ped thePed, string block = nil, string anim = nil, int time = -1, bool loop = true, bool updatePosition = true, bool interruptable = true, bool freezeLastFrame = true, int blendTime = 250, bool retainPedState = false)Returns
true on success.
Example
addCommandHandler("tancz", function(player)
setPedAnimation(player, "dancing", "dnce_M_a", -1, true, false)
end)
addCommandHandler("stop", function(player)
setPedAnimation(player)
end)
See also
getPedAnimationReturns the block and name of the animation a ped is playing (set withsetPedAnimation). On the client, for peds in this game, it also returns the progress (0-1) and speed of an IFP animation. Returnsfalsewhen the ped is not playing any animation.setPedAnimationProgressSeeks a ped's current animation to a chosen point (0 = start, 1 = end). On the server it applies to the animation set by the server'ssetPedAnimationand reaches every player. On the client it applies to an IFP file animation playing on a ped in this game, and the animation name must match the current one.setPedAnimationSpeedChanges the playback speed of a ped's current animation: 1 = normal, 0.5 = half speed, 0 = paused. On the server it applies to the animation from the server'ssetPedAnimation; on the client to an IFP file animation on a ped in this game.engineLoadIFPLoads an IFP animation library (ANPK from Vice City, ANP2/ANP3 from San Andreas) from a file or data under your own block name (preferably"resource.block"). Play animations withsetPedAnimation(ped, block, animation)or substitute them withengineReplaceAnimation. Stopping the resource frees the block.