GetVehicleDoorState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Made the argument and return sections clearer.)
(Added an example.)
Line 26: Line 26:


==Example==
==Example==
<syntaxhighlight lang="lua">local newcar = createVehicle ( 520, 1024, 1024, 1024 )
This example implements a doesVehicleHaveDoorOpen() function, that returns true if any of the doors on a vehicle are open.
local state = getVehicleDoorState ( newcar, 2 )
<syntaxhighlight lang="lua">function doesVehicleHaveDoorOpen(vehicle)
outputChatBox ( "The 3rd door state on this car: " .. state )</syntaxhighlight>
local isDoorAjar = false
for i=0,5 do
local doorState = getVehicleDoorState(vehicle, i)
if doorState == 1 or doorState == 3 or doorState == 4 then
isDoorAjar = true
end
end
return isDoorAjar
end</syntaxhighlight>


==See Also==
==See Also==
{{Vehicle functions}}
{{Vehicle functions}}

Revision as of 04:01, 24 December 2011

This function returns the current state of the specifed door on the vehicle.

Syntax

int getVehicleDoorState ( vehicle theVehicle, int door )

Required Arguments

  • theVehicle: The vehicle you want to get the door status of.
  • door: A whole number representing which door to get the status of. Valid values are:
    • 0: Hood
    • 1: Trunk
    • 2: Front left
    • 3: Front right
    • 4: Rear left
    • 5: Rear right

Returns

If successful, one of the following integers will be returned:

  • 0: Shut (Undamaged) (also returned if no such door exists on the vehicle)
  • 1: Open (Undamaged)
  • 2: Shut (Damaged)
  • 3: Open (Damaged)
  • 4: Fallen off


Example

This example implements a doesVehicleHaveDoorOpen() function, that returns true if any of the doors on a vehicle are open.

function doesVehicleHaveDoorOpen(vehicle)
	local isDoorAjar = false
	for i=0,5 do
		local doorState = getVehicleDoorState(vehicle, i)
		if doorState == 1 or doorState == 3 or doorState == 4 then
			isDoorAjar = true
		end
	end
	
	return isDoorAjar
end

See Also