setVehicleComponentPosition | Multi Theft Auto: Wiki Skip to content

setVehicleComponentPosition

Client-side
Server-side
Shared

Pair: getVehicleComponentPosition

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function sets the component position of a vehicle.

OOP Syntax Help! I don't understand this!

  • Method:vehicle:setComponentPosition(...)

Syntax

bool setVehicleComponentPosition ( vehicle theVehicle, string theComponent, float posX, float posY, float posZ, [ string base = "root" ] )
Required Arguments
  • theVehicle: The vehicle you wish to set component position.
  • theComponent: A vehicle component (this is the frame name from the model file of the component you wish to modify)
  • posX: The new x position of this component.
  • posY: The new y position of this component.
  • posZ: The new z position of this component.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • base (default: "root"): A string representing what the supplied position ( posX , posY , posZ ) is relative to. It can be one of the following values: parent : The position is relative to the parent component. root (default if not specified): The position is relative to the root component. world : The position is a world position, relative to the world's center of coordinates.

Returns

  • bool: value

Returns true if component position was set successfully, false otherwise.

Code Examples

shared

Example 1:This example would set the position of the component.

addCommandHandler("scp", -- short for 'set 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) --get the position of the component
setVehicleComponentPosition(theVeh, k, x+1, y+1, z+1) -- increases by 1 unit
end
end
end
)

See Also

Vehicle Functions