GetVehicleType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 35: Line 35:


==Example==
==Example==
In this example when a player enters an airplane, it displays a message welcoming the player onboard.
'''Example 1:''' In this example when a player enters an airplane, it displays a message welcoming the player onboard.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function enterPlane(theVehicle, seat, jacked)
function enterPlane(theVehicle, seat, jacked)
Line 46: Line 46:
</syntaxhighlight>
</syntaxhighlight>


In this another example player gets message what type of vehicle he just entered.
'''Example 2:''' In this example player gets message what type of vehicle he just entered.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function enteredVehicleType(theVehicle, seat, jacked)
function enteredVehicleType(theVehicle, seat, jacked)

Revision as of 22:43, 22 September 2009

This function retrieves the type of a vehicle (such as if it is a car or a boat).

Syntax

string getVehicleType ( vehicle theVehicle )

OR

string getVehicleType ( int modelId )

Required Arguments

  • vehicle: The vehicle element to get the type of.
  • modelId: A vehicle model id

Returns

Returns a string with vehicle type or false if an invalid modelID has been supplied, or an empty string if the vehicle is blocked internally (some trailers).

Possible strings returned:

  • Automobile: Cars, vans and trucks
  • Plane
  • Bike: Motorbikes
  • Helicopter
  • Boat
  • Train
  • Trailer: A trailer for a truck
  • BMX
  • Monster Truck
  • Quad: Quadbikes

Example

Example 1: In this example when a player enters an airplane, it displays a message welcoming the player onboard.

function enterPlane(theVehicle, seat, jacked)
    if (getVehicleType(theVehicle) == "Plane") then
        outputChatBox("Welcome onboard!", source)
    end
end

addEventHandler("onPlayerVehicleEnter", getRootElement(), enterPlane)

Example 2: In this example player gets message what type of vehicle he just entered.

function enteredVehicleType(theVehicle, seat, jacked)
	outputChatBox("You entered ".. getVehicleType(theVehicle) ..".", source)
    end
end

addEventHandler("onPlayerVehicleEnter", getRootElement(), enteredVehicleType)

See Also