GetVehicleTurretPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(OOP)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
{{Server client function}}
{{Server client function}}
__NOTOC__
This function gets the position of a vehicle's turret, if it has one. Vehicles with turrets include firetrucks and tanks.
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 turretVehicle )</syntaxhighlight>
<syntaxhighlight lang="lua">float, float getVehicleTurretPosition ( vehicle turretVehicle )</syntaxhighlight>
 
{{OOP||[[vehicle]]:getTurretPosition|turretPosition|setVehicleTurretPosition}}
This function also has two variants that allow you to retrieve data from just one of the two axes.
 
===Required Arguments===
===Required Arguments===
*'''turretVehicle''': The [[vehicle]] whose rotation you want to retrieve. This should be a vehicle with a turret with a player in.
*'''turretVehicle''': The [[vehicle]] whose turret position you want to retrieve. This should be a vehicle with a turret.


===Returns===
===Returns===
Returns two [[float]]s for the X (horizontal) and Y (vertical) axis rotation respectively. These values are in radians. 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.  
Returns two [[float]]s for the X (horizontal) and Y (vertical) axis rotation respectively. These values are in radians. The function will return ''0, 0'' if the vehicle is not a vehicle with a turret.  
 
{{UsingRadians}}


==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Find all the vehicles, and store them in a vehicles variable
-- Find all the vehicles, and store them in a vehicles variable
vehicles = getElementsByType ( "vehicle" )
local vehicles = getElementsByType ( "vehicle" )
-- Loop through the vehicle list
-- Loop through the vehicle list
for vehicleKey, vehicleValue in ipairs(vehicles) do
for vehicleKey, vehicleValue in ipairs(vehicles) do
-- Get the vehicle's turret position
-- Get the vehicle's turret position
x, y = getVehicleTurretPosition ( vehicleValue )  
local x, y = getVehicleTurretPosition ( vehicleValue )  
-- If the vehicle has a turret (the function will return false if it doesn't) then
-- Convert the positions to degrees, as that's much more useful if you'd want to output it
if ( x ~= false ) then
x = math.deg ( x )
-- Tell everyone in the chat the turret's position
y = math.deg ( y )
outputChatBox ( "Turret position: " .. x .. ", " .. y .. "." )
-- Get the vehicle's name
end
local vehicleName = getVehicleName ( vehicleValue )
-- Tell everyone in the F8 console the turret's position
outputConsole ( vehicleName .. "'s turret rotation: " .. x .. ", " .. y .. "." )
end
end
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 23:35, 17 December 2014

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 )

OOP Syntax Help! I don't understand this!

Method: vehicle:getTurretPosition(...)
Variable: .turretPosition
Counterpart: setVehicleTurretPosition


Required Arguments

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

Returns

Returns two floats for the X (horizontal) and Y (vertical) axis rotation respectively. These values are in radians. The function will return 0, 0 if the vehicle is not a vehicle with a turret.

Example

-- Find all the vehicles, and store them in a vehicles variable
local vehicles = getElementsByType ( "vehicle" )
-- Loop through the vehicle list
for vehicleKey, vehicleValue in ipairs(vehicles) do
	-- Get the vehicle's turret position
	local x, y = getVehicleTurretPosition ( vehicleValue ) 
	-- Convert the positions to degrees, as that's much more useful if you'd want to output it
	x = math.deg ( x )
	y = math.deg ( y )
	-- Get the vehicle's name
	local vehicleName = getVehicleName ( vehicleValue )
	-- Tell everyone in the F8 console the turret's position
	outputConsole ( vehicleName .. "'s turret rotation: " .. x .. ", " .. y .. "." )	
end

See Also