GetVehicleTurretPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function returns two floats containing the rotational position of the vehicle's turret along the horizontal and vertical axes (X and Y) respectively. This function can fail if the player is not in a vehicle, or if the vehicle does not have a turret. Vehicles with turrets include tanks and fire trucks. If this function does fail, the first argument will be set to 'false'.
This function gets the position of a vehicle's turret, if it has one. Vehicles with turrets include firetrucks and tanks.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">float float getVehicleTurretPosition ( vehicle )</syntaxhighlight>
<syntaxhighlight lang="lua">float float getVehicleTurretPosition ( vehicle turretVehicle )</syntaxhighlight>


This function also has two variants that allow you to retrieve data from just one of the two axes.
This function also has two variants that allow you to retrieve data from just one of the two axes.
Line 10: Line 10:


===Required Arguments===
===Required Arguments===
*'''vehicle''': The vehicle whose rotation you want to retrieve.
*'''turretVehicle''': The vehicle whose rotation you want to retrieve. This should be a vehicle with a turret with a player in.


===Returns===
===Returns===
Returns two [[float]]s for the X and Y axis rotation respectively.
Returns two [[float]]s for the X (horizontal) and Y (vertical) axis rotation respectively. The function will return ''false'' in the first return value if the vehicle does not have a driver or the vehicle is not a vehicle with a turret.


==Example==
==Example==
<syntaxhighlight lang="lua">newcar = createVehicle ( 520, 1024, 1024, 1024 )
<syntaxhighlight lang="lua">
x, y = GetVehicleTurretPosition ( newcar )  
-- Find all the vehicles, and store them in a vehicles variable
if (x)
vehicles = getElementsByType ( "vehicle" )
serverChat ( "Turret position: ",x,",",y,"." )
-- Loop through the vehicle list
end</syntaxhighlight>
for vehicleKey, vehicleValue in vehicles do
-- Get the vehicle's turret position
x, y = getVehicleTurretPosition ( vehicleValue )  
-- If the vehicle has a turret (the function will return false if it doesn't) then
if ( x ~= false )
-- Tell everyone in the chat the turret's position
outputChatBox ( "Turret position: " .. x .. ", " .. y .. "." )
end
end
</syntaxhighlight>

Revision as of 00:10, 19 May 2006

This function gets the position of a vehicle's turret, if it has one. Vehicles with turrets include firetrucks and tanks.

Syntax

float float getVehicleTurretPosition ( vehicle turretVehicle )

This function also has two variants that allow you to retrieve data from just one of the two axes.

Template:UsingRadians

Required Arguments

  • turretVehicle: The vehicle whose rotation you want to retrieve. This should be a vehicle with a turret with a player in.

Returns

Returns two floats for the X (horizontal) and Y (vertical) axis rotation respectively. The function will return false in the first return value if the vehicle does not have a driver or the vehicle is not a vehicle with a turret.

Example

-- Find all the vehicles, and store them in a vehicles variable
vehicles = getElementsByType ( "vehicle" )
-- Loop through the vehicle list
for vehicleKey, vehicleValue in vehicles do
	-- Get the vehicle's turret position
	x, y = getVehicleTurretPosition ( vehicleValue ) 
	-- If the vehicle has a turret (the function will return false if it doesn't) then
	if ( x ~= false )
		-- Tell everyone in the chat the turret's position
		outputChatBox ( "Turret position: " .. x .. ", " .. y .. "." )	
	end
end