GetElementBoneRotation: Difference between revisions

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


addCommandHandler ("getbonerotation", getBoneRotation)
addCommandHandler ("getbonerotation", getBoneRotation)
</syntaxhighlight>


-- Other Example.
==Example==
 
This example takes the current rotation of all player bones.
<syntaxhighlight lang="lua">
local settings = {
local settings = {
     copyDiscord = false; -- true = "yes" // false = "no" - Copy to paste table in discord.
     copyDiscord = false; -- true = "yes" // false = "no" - Copy to paste table in discord.

Revision as of 18:30, 11 December 2021

Returns the orientation of a specific bone relative to the element. Currently the Player and Ped element types are accepted.

[[{{{image}}}|link=|]] Tip: If you want to attach an element to a bone, see attachElementToBone.

Syntax

float, float, float getElementBoneRotation ( element theElement, int boneId )
Rotation axes

Required Arguments

  • theElement: the element to get the bone rotation on.
  • boneId: the ID of the bone to get the rotation of. See Bone IDs.

Returns

Returns 3 floats, representing the yaw, pitch, roll rotation values.

Example

This example outputs the yaw, pitch and roll orientation of a specific bone relative to the local player bone specified through a command:

function getBoneRotation (commandName, boneId)
    if not tonumber (boneId) then
        outputChatBox ("You didn't insert an bone ID!", 255, 0, 0)
        return false
    end

    local x, y, z = getElementBoneRotation (localPlayer, boneId)
    outputChatBox ("The bone rotation is: "..x..", "..y..", "..z)
end

addCommandHandler ("getbonerotation", getBoneRotation)

Example

This example takes the current rotation of all player bones.

local settings = {
    copyDiscord = false; -- true = "yes" // false = "no" - Copy to paste table in discord.
    tableName = "bonesPos"; -- Table name to be copied.
}

local boneIDs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 21, 22, 23, 24, 25, 26, 31, 32, 33, 34, 35, 36, 41, 42, 43, 44, 51, 52, 53, 54, 201, 301, 302}

addCommandHandler ("getbonerotation", function ()
    local bonesPositions = { }
    local bonesConverted = ""
    for _, v in ipairs (boneIDs) do
        local x, y, z = getElementBoneRotation (localPlayer, v)
        table.insert (bonesPositions, "["..v.."] = {"..x..", "..y..", "..z.."};")
    end
    for i, v in ipairs (bonesPositions) do
        bonesConverted = "    "..bonesConverted.."\n".."    "..v
    end
    setClipboard ((settings["copyDiscord"] and "```lua\nlocal "..string.gsub(settings["tableName"], " ", "_").." = {"..bonesConverted.."\n}\n```" or "local "..string.gsub(settings["tableName"], " ", "_").." = {"..bonesConverted.."\n}"))
    outputChatBox (settings["messageSend"])
end)

Requirements

This template will be deleted.

See Also