Difference between revisions of "GetPedAnimation"

From Multi Theft Auto: Wiki
 
(18 intermediate revisions by 10 users not shown)
Line 2: Line 2:
 
{{Client function}}
 
{{Client function}}
  
Gets the animation data of a player or ped that was set using [[setPedAnimation]] or [[blendPedAnimation]].
+
Gets the animation of a player or ped that was set using [[setPedAnimation]].
 +
{{Note|Use [[getPedTask]] to monitor what movements the player is currently doing.''}}
  
 
==Syntax==
 
==Syntax==
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
... getPedAnimationData ( ped thePed, string dataType )
+
string, string getPedAnimation ( ped thePed )
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
{{OOP||[[ped]]:getAnimation||setPedAnimation}}
  
 
===Required Arguments===
 
===Required Arguments===
*'''thePed:''' the player or ped you want to get the animation data of.
+
*'''thePed:''' the [[player]] or [[ped]] you want to get the [[animations|animation]] of.
*'''dataType:''' A string representing the type of data you want to retrieve:
 
 
 
==Data-types==
 
*'''name:''' string - name of animation.
 
*'''blockName:''' string - name of animation block.
 
*'''loop:''' boolean - looping.
 
*'''updatePosition:''' boolean - updating position.
 
*'''interruptable:''' boolean - interruptable.
 
*'''time:''' float - duration.
 
*'''startTime:''' float - starting point.
 
*'''finished:''' boolean - finished playing.
 
*'''speed:''' float - speed.
 
*'''blendSpeed:''' float - blending speed.
 
  
 
===Returns===
 
===Returns===
Returns various arguments depending on the 'dataType' specified.
+
Returns two [[string|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.
  
 
==Example==
 
==Example==
 +
This example adds a command that allows you to copy the animation being used by another player using /copyanim theirName
 +
<syntaxhighlight lang="lua">
 +
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
 +
end
 +
else
 +
outputChatBox("* Please Enter a Player Name To Copy From !") -- if you didnt entered a player name , then output a chat box message
 +
end
 +
end
 +
addCommandHandler("copyanim", CopyAnimation) --  adding the Command Handler
 +
</syntaxhighlight>
 +
 +
==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]].
 +
<syntaxhighlight lang="lua">
 +
addEventHandler("onClientPreRender",root,
 +
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 )
 +
</syntaxhighlight>
  
 
==See Also==
 
==See Also==
{{Ped_functions}}
+
{{Client_ped_functions}}
 +
 
 +
[[hu:getPedAnimation]]

Latest revision as of 05:19, 11 August 2019

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.

Syntax

string, string getPedAnimation ( ped thePed )

OOP Syntax Help! I don't understand this!

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

Required Arguments

Returns

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.

Example

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
		end
	else	
		outputChatBox("* Please Enter a Player Name To Copy From !") -- if you didnt entered a player name , then output a chat box message
	end
end
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.

addEventHandler("onClientPreRender",root,
	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

FROM VERSION 1.5.7 r19626 ONWARDS
FROM VERSION 1.5.7 r19626 ONWARDS