GetPedBonePosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(9 intermediate revisions by 8 users not shown)
Line 2: Line 2:
{{Client function}}
{{Client function}}
Returns the 3D world coordinates of a specific bone of a given ped.
Returns the 3D world coordinates of a specific bone of a given ped.
{{Tip|If you want attach element to ped bone, use [[https://github.com/Patrick2562/mtasa-pAttach pAttach]] resource}}


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float float float getPedBonePosition ( ped thePed, int bone )
float, float, float getPedBonePosition ( ped thePed, int bone )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[ped]]:getBonePosition||}}


===Required Arguments===
===Required Arguments===
Line 55: Line 57:
       local px, py, pz, tx, ty, tz, dist
       local px, py, pz, tx, ty, tz, dist
       px, py, pz = getCameraMatrix( )
       px, py, pz = getCameraMatrix( )
      for _, v in ipairs( getElementsByType 'player' ) do
      for _, v in ipairs( getElementsByType ( 'player' ) ) do
         tx, ty, tz = getElementPosition( v )
         tx, ty, tz = getElementPosition( v )
         dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 )
         dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 )
Line 70: Line 72:
   end
   end
)
)
</syntaxhighlight>
==Example 2==
This one draw all local player's bones
<syntaxhighlight lang="lua">
addEventHandler('onClientRender', root, function()
for bone = 1, 54 do
local bonePos = {getPedBonePosition(localPlayer, bone)}
if bonePos[1] then
local screen = {getScreenFromWorldPosition(unpack(bonePos))}
if screen[1] then
dxDrawText(''..bone, screen[1], screen[2])
end
end
end
end)
</syntaxhighlight>
</syntaxhighlight>


Line 75: Line 93:
{{Client_ped_functions}}
{{Client_ped_functions}}


[[hu:getPedBonePosition]]
[[ru:GetPedBonePosition]]
[[ru:GetPedBonePosition]]

Latest revision as of 17:47, 18 July 2023

Returns the 3D world coordinates of a specific bone of a given ped.

[[{{{image}}}|link=|]] Tip: If you want attach element to ped bone, use [pAttach] resource

Syntax

float, float, float getPedBonePosition ( ped thePed, int bone )

OOP Syntax Help! I don't understand this!

Method: ped:getBonePosition(...)


Required Arguments

  • thePed: the ped you want to inspect.
  • bone: the number of the bone to get the position of.
Bone numbers
  • 1: BONE_PELVIS1
  • 2: BONE_PELVIS
  • 3: BONE_SPINE1
  • 4: BONE_UPPERTORSO
  • 5: BONE_NECK
  • 6: BONE_HEAD2
  • 7: BONE_HEAD1
  • 8: BONE_HEAD
  • 21: BONE_RIGHTUPPERTORSO
  • 22: BONE_RIGHTSHOULDER
  • 23: BONE_RIGHTELBOW
  • 24: BONE_RIGHTWRIST
  • 25: BONE_RIGHTHAND
  • 26: BONE_RIGHTTHUMB
  • 31: BONE_LEFTUPPERTORSO
  • 32: BONE_LEFTSHOULDER
  • 33: BONE_LEFTELBOW
  • 34: BONE_LEFTWRIST
  • 35: BONE_LEFTHAND
  • 36: BONE_LEFTTHUMB
  • 41: BONE_LEFTHIP
  • 42: BONE_LEFTKNEE
  • 43: BONE_LEFTANKLE
  • 44: BONE_LEFTFOOT
  • 51: BONE_RIGHTHIP
  • 52: BONE_RIGHTKNEE
  • 53: BONE_RIGHTANKLE
  • 54: BONE_RIGHTFOOT

Returns

Returns the x, y, z world position of the bone.

Example

This example renders name tags above a player's head bone.

addEventHandler( "onClientRender",root,
   function( )
      local px, py, pz, tx, ty, tz, dist
      px, py, pz = getCameraMatrix( )
       for _, v in ipairs( getElementsByType ( 'player' ) ) do
         tx, ty, tz = getElementPosition( v )
         dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 )
         if dist < 30.0 then
            if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then
               local sx, sy, sz = getPedBonePosition( v, 5 )
               local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 )
               if x then -- getScreenFromWorldPosition returns false if the point isn't on screen
                dxDrawText( getPlayerName( v ), x, y, x, y, tocolor(150, 50, 0), 0.85 + ( 15 - dist ) * 0.02, "bankgothic" )
               end
            end
         end
      end
   end
)

Example 2

This one draw all local player's bones

addEventHandler('onClientRender', root, function()
	for bone = 1, 54 do
	 local bonePos = {getPedBonePosition(localPlayer, bone)}
		if bonePos[1] then
		 local screen = {getScreenFromWorldPosition(unpack(bonePos))}
			if screen[1] then
			 dxDrawText(''..bone, screen[1], screen[2])
			end
		end
	end
end)

See Also