GetVehicleNameFromID: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 24: Line 24:
local x, y, z = getElementPosition ( player )
local x, y, z = getElementPosition ( player )
--Get the position of the player to spawn the car near this location
--Get the position of the player to spawn the car near this location
createVehicle ( carid, x + 5, y, z )
--Spawn the car at x + 5 from the player so it doesn't crush him
carname = getVehicleNameFromID ( carid )
carname = getVehicleNameFromID ( carid )
--Get the name of the car the player asked for and store it to the
--Get the name of the car the player asked for and store it to the
--varible 'carname'
--varible 'carname'
if carname == "" then
if carname == false then
outputChatBox ( "That is not a valid car ID" )
outputChatBox ( "That is not a valid car ID" )
else
else
createVehicle ( carid, x + 5, y, z )
--Spawn the car at x + 5 from the player so it doesn't crush him
outputChatBox ( "A "..carname.." was created!" )
outputChatBox ( "A "..carname.." was created!" )
end
end
--A string is always returned in this situation, so if the car doesn't
--If the entered car ID returns no car name, the string will be empty and false will be returned.
--exist the string has no values. If the string does have any value, we
--If the string does have any value, we create the car and announce the car name in the chatbox,
--announce it in the chatbox because it is a vehicle.
--because a car did exist under the given car ID.
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 08:42, 11 April 2007

Allows you to input a vehicleID and return a vehicle name from that ID

Syntax

string getVehicleNameFromID ( int id )            

Required Arguments

  • id: This is a vehicle id. See vehicle to see what values will return names (true).

Returns

Returns true if vehicle exists, false otherwise.

Example

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

addCommandHandler ( "spawnvehicle", "createvehiclecommand" )
function createvehiclecommand ( player, commandName, carid )
--This function is triggered by the text "spawnvehicle" in the console.
--The player must also specify the added varible carid to specify
--what car they wish to spawn.
local x, y, z = getElementPosition ( player )
--Get the position of the player to spawn the car near this location
carname = getVehicleNameFromID ( carid )
--Get the name of the car the player asked for and store it to the
--varible 'carname'
	if carname == false then
	outputChatBox ( "That is not a valid car ID" )
	else
	createVehicle ( carid, 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 ID returns no car name, the string will be empty and false will be returned.
	--If the string does have any value, we create the car and announce the car name in the chatbox,
	--because a car did exist under the given car ID.
end

See Also