Difference between revisions of "GetVehicleNameFromModel"

From Multi Theft Auto: Wiki
(New page: {{Server client function}} __NOTOC__ Gets the name of a vehicle by its model ID. ==Syntax== <syntaxhighlight lang="lua"> string getVehicleNameFromModel ( int model ) </syntaxhighlight> ===Required A...)
 
(updated returns, added reference to bugtrack issue)
Line 12: Line 12:
  
 
===Returns===
 
===Returns===
Returns the name of the vehicle if the model ID was valid, ''false'' otherwise.
+
Returns the name of the vehicle if the model ID was valid, empty string otherwise<ref>https://bugs.multitheftauto.com/view.php?id=8523</ref>.
  
 
==Example==  
 
==Example==  
Line 38: Line 38:
 
addCommandHandler ( "spawnvehicle", createVehicleCommand )
 
addCommandHandler ( "spawnvehicle", createVehicleCommand )
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== References ==
 +
<references />
  
 
==See Also==
 
==See Also==
 
{{Vehicle functions}}
 
{{Vehicle functions}}

Revision as of 13:28, 20 October 2014

Gets the name of a vehicle by its model ID.

Syntax

string getVehicleNameFromModel ( int model )            

Required Arguments

  • model: This is the vehicle model ID. See vehicle IDs to see what values will return names.

Returns

Returns the name of the vehicle if the model ID was valid, empty string otherwise[1].

Example

This will retrieve the name of a car so its name can be displayed when the player chooses to spawn a car by model ID.

function createVehicleCommand ( thePlayer, commandName, carModel )
    -- This function is triggered by the text "spawnvehicle" in the console.
    -- The player must specify the parameter 'carModel' to specify
    -- what car they wish to spawn.
    local x, y, z = getElementPosition ( thePlayer )
    -- Get the position of the player to spawn the car near this location
    local carName = getVehicleNameFromModel ( tonumber ( carModel ) )
    -- Get the name of the car the player asked for and store it in the
    -- variable 'carName'
    if not carname then
        outputChatBox ( "That is not a valid car model ID", thePlayer )
    else
        createVehicle ( tonumber ( carModel ), x + 5, y, z )
        -- Spawn the car at x + 5 from the player so it doesn't crush him
        outputChatBox ( "A " .. carName .. " was created!" )
    end
    -- If the entered car model ID is invalid, false will be returned.
    -- Otherwise a string is returned, we create the car and announce the car name in the chatbox.
end
addCommandHandler ( "spawnvehicle", createVehicleCommand )

References

See Also

BETA: FROM VERSION 1.6 r7485 ONWARDS
BETA: FROM VERSION 1.6 r7485 ONWARDS