Difference between revisions of "GetVehicleComponentPosition"

From Multi Theft Auto: Wiki
m
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
{{Client function}}
 
{{Client function}}
This function get component position for [[vehicle]].
+
This function gets the component position of a [[vehicle]]. The vehicle must be streamed in.
  
 
==Syntax==  
 
==Syntax==  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root"] )
+
float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root" ] )
 
</syntaxhighlight>
 
</syntaxhighlight>
 
{{OOP||[[vehicle]]:getComponentPosition||setVehicleComponentPosition}}
 
{{OOP||[[vehicle]]:getComponentPosition||setVehicleComponentPosition}}
  
 
===Required Arguments===  
 
===Required Arguments===  
*'''theVehicle:''' The [[vehicle]] you wish to get component position.
+
*'''theVehicle:''' The [[vehicle]] you wish to get component position of.
 
*'''theComponent:''' A [[Vehicle_Components|vehicle component]] (this is the frame name from the model file of the component you wish to modify)
 
*'''theComponent:''' A [[Vehicle_Components|vehicle component]] (this is the frame name from the model file of the component you wish to modify)
  
Line 25: Line 25:
  
 
==Example==
 
==Example==
This example gets the name and the position of the components and outputs it in the chat.
+
<section class="client" show="true" name="This example gets the name and the position of the components and outputs it in the chat.">
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
addCommandHandler("vcp", -- short for 'vehicle component position'
 
addCommandHandler("vcp", -- short for 'vehicle component position'
Line 40: Line 40:
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</section>
 +
 +
 +
<section class="client" show="true" name="This example shows every components name in 3D(Only for streamedin vehicles)">
 +
<syntaxhighlight lang="lua">
 +
local showComponents = false
 +
bindKey("f5", "down", function() showComponents = not showComponents end)
 +
 +
 +
addEventHandler("onClientRender", root,
 +
    function()
 +
 +
        if (showComponents) then
 +
            for _, veh in pairs(getElementsByType("vehicle", root, true)) do
 +
                for compname in pairs(veh:getComponents()) do
 +
                    local x, y = getScreenFromWorldPosition(veh:getComponentPosition(compname, "world"))
 +
 +
                    if (x) then
 +
                        dxDrawText(compname, x, y, 0, 0, tocolor(255, 255, 255))
 +
                    end
 +
                end
 +
            end
 +
        end
 +
 +
    end
 +
)
 +
</syntaxhighlight>
 +
</section>
  
 
==Changelog==
 
==Changelog==

Latest revision as of 23:14, 11 November 2019

This function gets the component position of a vehicle. The vehicle must be streamed in.

Syntax

float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root" ] )

OOP Syntax Help! I don't understand this!

Method: vehicle:getComponentPosition(...)
Counterpart: setVehicleComponentPosition

Required Arguments

  • theVehicle: The vehicle you wish to get component position of.
  • theComponent: A vehicle component (this is the frame name from the model file of the component you wish to modify)

Optional Arguments

  • base: A string representing what the returned position is relative to. It can be one of the following values:
    • parent: The position is relative to the parent component.
    • root: The position is relative to the root component.
    • world: The position is a world position.

Returns

Returns three floats indicating the position of the component, x, y and z respectively.

Example

Click to collapse [-]
This example gets the name and the position of the components and outputs it in the chat.
addCommandHandler("vcp", -- short for 'vehicle component position'
    function()
        local theVeh = getPedOccupiedVehicle(localPlayer)
	local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle
        if (theVeh) then
            for k in pairs (getComponent) do
		local x, y, z = getVehicleComponentPosition(theVeh, k)
                outputChatBox("Position of "..k.." is"..x.." "..y.." "..z)
            end
        end
    end
)


Click to collapse [-]
This example shows every components name in 3D(Only for streamedin vehicles)
local showComponents = false
bindKey("f5", "down", function() showComponents = not showComponents end)


addEventHandler("onClientRender", root,
    function()

        if (showComponents) then
            for _, veh in pairs(getElementsByType("vehicle", root, true)) do
                for compname in pairs(veh:getComponents()) do
                    local x, y = getScreenFromWorldPosition(veh:getComponentPosition(compname, "world"))

                    if (x) then
                        dxDrawText(compname, x, y, 0, 0, tocolor(255, 255, 255))
                    end
                end 
            end
        end

    end
)

Changelog

Version Description
1.4.0-9.07013 Added base argument

See Also

BETA: FROM VERSION 1.5.7 r19626 ONWARDS
BETA: FROM VERSION 1.6 r7485 ONWARDS
BETA: FROM VERSION 1.6 r7485 ONWARDS