GetVehicleTurretPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 25: Line 25:
x, y = getVehicleTurretPosition ( vehicleValue )  
x, y = getVehicleTurretPosition ( vehicleValue )  
-- If the vehicle has a turret (the function will return false if it doesn't) then
-- If the vehicle has a turret (the function will return false if it doesn't) then
if ( x ~= false )
if ( x ~= false ) then
-- Tell everyone in the chat the turret's position
-- Tell everyone in the chat the turret's position
outputChatBox ( "Turret position: " .. x .. ", " .. y .. "." )
outputChatBox ( "Turret position: " .. x .. ", " .. y .. "." )

Revision as of 15:00, 18 August 2007

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.

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. 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.

Template:UsingRadians

Example

-- Find all the vehicles, and store them in a vehicles variable
vehicles = getElementsByType ( "vehicle" )
-- Loop through the vehicle list
for vehicleKey, vehicleValue in ipairs(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 ) then
		-- Tell everyone in the chat the turret's position
		outputChatBox ( "Turret position: " .. x .. ", " .. y .. "." )	
	end
end

See Also