From Multi Theft Auto: Wiki
Jump to navigation Jump to search

Gets the animation of a player or ped that was set using setPedAnimation.

[[{{{image}}}|link=|]] Note: Use getPedTask to monitor what movements the player is currently doing.


BEFORE VERSION 1.5.7 r20450:
string, string getPedAnimation ( ped thePed )
 string, string, int, int, bool, bool, bool, int, bool getPedAnimation ( ped thePed )

OOP Syntax Help! I don't understand this!

Method: ped:getAnimation(...)
Counterpart: setPedAnimation

Required Arguments


BEFORE VERSION 1.5.7 r20450:
Returns two strings: the first is the name of the block, the second is the name of the animation. Returns false if there was an error or if the ped is not doing an animation.

The function returns 9 values in the same order as required by setPedAnimation:

string block, string anim, int time, bool loop, bool updatePosition, bool interruptable, bool freezeLastFrame, int blendTime, bool restoreTaskOnAnimEnd


This example adds a command that allows you to copy the animation being used by another player using /copyanim theirName

function CopyAnimation(theCommand, thePlayer) -- The Command Function
	if thePlayer then -- If a player name entered then
		thePlayerToCopyFrom = getPlayerFromName(thePlayer) -- get player from his name
		block, anim = getPedAnimation(thePlayerToCopyFrom) -- get the player animation
		if block then -- if got the animation successfully then
			setPedAnimation(localPlayer, block, anim) -- set my animation the same
			outputChatBox("* Copied Successfully !") -- output chat message
		outputChatBox("* Please Enter a Player Name To Copy From !") -- if you didnt entered a player name , then output a chat box message
addCommandHandler("copyanim", CopyAnimation) --  adding the Command Handler

Example 2

This example shows what block and animation your player is currently performing. Note this will return "N/A" if you did not set an animation with setPedAnimation. If you want to see what the player ped is doing as you control them that is getPedTask.

	function ()
    local block, animation = getPedAnimation(localPlayer)
	dxDrawText ( "CURRENT ANIMATION INFO...", 100, 300 )
	if not block then block = "N/A" end
	if not animation then animation = "N/A" end
	dxDrawText ( "Block = "..block.." Animation = "..animation, 100, 315 )
end )

See Also