SetElementBonePosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} {{New feature/item|3.0160|1.5.8|20704|This function sets the position of a bone to the specified coordinates. Currently the following element typ...")
 
(Syntax updated)
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{New feature/item|3.0160|1.5.8|20704|This function sets the position of a bone to the specified coordinates. Currently the following element types are accepted:
{{Added feature/item|1.5.9|1.5.8|20704|This function sets the position of a bone to the specified coordinates. Currently the [[Element/Player|Player]] and [[Element/Ped|Ped]] element types are accepted.}}
* [[Element/Player|Player]]
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}
* [[Element/Ped|Ped]]
{{Note|You need to use this function together with [[onClientPedsProcessed]].}}
}}
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]]}}


==Syntax==
==Syntax==
Line 13: Line 11:


===Required Arguments===
===Required Arguments===
*'''theElement:''' the element to set the bone position on.
*'''theElement:''' the [[Element|element]] to set the bone position on.
*'''bone:''' the ID of the bone to set the position of. See [[Bone IDs]]
*'''bone:''' the ID of the bone to set the position of. See [[Bone IDs]].
*'''x:''' The x coordinate of the destination.
*'''x:''' The X coordinate of the destination.
*'''y:''' The y coordinate of the destination.
*'''y:''' The Y coordinate of the destination.
*'''z:''' The z coordinate of the destination.
*'''z:''' The Z coordinate of the destination.


===Returns===
===Returns===
Line 23: Line 21:


==Example==
==Example==
{{Needs Example}}
[[File:CJ with long neck.png|thumb|alt=CJ with long neck|Example preview]]
This example shows a surprised CJ with a long neck
<syntaxhighlight lang="lua">
local bones = {
    [4] = Vector3(0, 0, 0.15),
    [5] = Vector3(0, 0, 0.15),
    [6] = Vector3(0, 0, 0.13),
    [7] = Vector3(0, 0, 0.13),
    [8] = Vector3(0, 0, 0.1),
}
function updatePed()
    for bone,v in pairs(bones) do
        local pos = localPlayer:getBonePosition(bone)+v
        setElementBonePosition(localPlayer, bone, pos)
    end
end
addEventHandler("onClientPedsProcessed", root, updatePed)
</syntaxhighlight>
 
==Requirements==
{{Requirements|n/a|1.5.8-9.20704|}}


==See Also==
==See Also==
{{Client_element_functions}}
{{Client_element_functions}}

Revision as of 07:08, 7 December 2021

This function sets the position of a bone to the specified coordinates. Currently the Player and Ped element types are accepted.

[[{{{image}}}|link=|]] Tip: If you want to attach an element to a bone, see attachElementToBone.
[[{{{image}}}|link=|]] Note: You need to use this function together with onClientPedsProcessed.

Syntax

bool setElementBonePosition ( element theElement, int bone, float x, float y, float z )

Required Arguments

  • theElement: the element to set the bone position on.
  • bone: the ID of the bone to set the position of. See Bone IDs.
  • x: The X coordinate of the destination.
  • y: The Y coordinate of the destination.
  • z: The Z coordinate of the destination.

Returns

Returns true if the function was successful, false otherwise.

Example

CJ with long neck
Example preview

This example shows a surprised CJ with a long neck

local bones = {
    [4] = Vector3(0, 0, 0.15),
    [5] = Vector3(0, 0, 0.15),
    [6] = Vector3(0, 0, 0.13),
    [7] = Vector3(0, 0, 0.13),
    [8] = Vector3(0, 0, 0.1),
}
function updatePed()
    for bone,v in pairs(bones) do
        local pos = localPlayer:getBonePosition(bone)+v
        setElementBonePosition(localPlayer, bone, pos)
    end
end
addEventHandler("onClientPedsProcessed", root, updatePed)

Requirements

Minimum server version n/a
Minimum client version 1.5.8-9.20704

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.5.8-9.20704" />

See Also