GetVehicleIDFromName: Difference between revisions
Jump to navigation
Jump to search
m (Visual improvement) |
|||
(9 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{server client function}} | |||
{{Deprecated|getVehicleModelFromName}} | |||
This function retrieves the ID of a vehicle as an integer value from its name. | This function retrieves the ID of a vehicle as an integer value from its name. | ||
Line 12: | Line 15: | ||
===Returns=== | ===Returns=== | ||
Returns an [[int]] if the name exists, ''false'' otherwise. | Returns an [[int]] if the name exists, ''false'' otherwise. | ||
If you use this function on vehicles with shared names, such as "police", it will return the earliest occurrence of that vehicle's ID. | |||
==Example== | ==Example== | ||
This will allow the player to create a vehicle by name and it's ID will be displayed in the chatbox when the vehicle is spawned. | This will allow the player to create a vehicle by name and it's ID will be displayed in the chatbox when the vehicle is spawned. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function createvehiclecommand ( sourcePlayer, commandName, carname ) | |||
function createvehiclecommand ( | -- This function is triggered by the text "spawnvehicle" in the console. | ||
--This function is triggered by the text " | -- The player must specify the added parameter 'carname' to specify | ||
--The player must | -- what car they wish to spawn. | ||
--what car they wish to spawn. | local carid = getVehicleIDFromName ( carname ) | ||
carid = getVehicleIDFromName ( carname ) | -- Get the ID of the car the player asked for and store it to the | ||
--Get the ID of the car the player asked for and store it to the | -- variable 'carid' | ||
-- | local x, y, z = getElementPosition ( sourcePlayer ) | ||
local x, y, z = getElementPosition ( | -- 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 | |||
if carid == false then | if carid == false then | ||
outputChatBox ( "That is not a valid car name" ) | |||
else | else | ||
createVehicle ( carid, x + 5, y, z ) | |||
-- Spawn the car using its ID. Spawn it at x + 5 from the player so it doesn't crush him | |||
outputChatBox ( "A vehicle with an ID of " .. carid .. " was created!" ) | |||
end | end | ||
--If the entered car name returns no car ID, the string will be empty and false will be returned. | -- If the entered car name returns no car ID, 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 ID in the chatbox, | -- If the string does have any value, we create the car and announce the car ID in the chatbox, | ||
--because a car did exist under the given car name. | -- because a car did exist under the given car name. | ||
end | end | ||
addCommandHandler ( "spawnvehicle", createvehiclecommand ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Vehicle functions}} | {{Vehicle functions}} |
Latest revision as of 11:29, 26 June 2014
This function is deprecated. This means that its use is discouraged and that it might not exist in future versions. | |
Please use getVehicleModelFromName instead. |
This function retrieves the ID of a vehicle as an integer value from its name.
Syntax
int getVehicleIDFromName ( string name )
Required Arguments
- name: A string containing the name of the vehicle.
Returns
Returns an int if the name exists, false otherwise. If you use this function on vehicles with shared names, such as "police", it will return the earliest occurrence of that vehicle's ID.
Example
This will allow the player to create a vehicle by name and it's ID will be displayed in the chatbox when the vehicle is spawned.
function createvehiclecommand ( sourcePlayer, commandName, carname ) -- This function is triggered by the text "spawnvehicle" in the console. -- The player must specify the added parameter 'carname' to specify -- what car they wish to spawn. local carid = getVehicleIDFromName ( carname ) -- Get the ID of the car the player asked for and store it to the -- variable 'carid' local x, y, z = getElementPosition ( sourcePlayer ) -- Get the position of the player to spawn the car near this location if carid == false then outputChatBox ( "That is not a valid car name" ) else createVehicle ( carid, x + 5, y, z ) -- Spawn the car using its ID. Spawn it at x + 5 from the player so it doesn't crush him outputChatBox ( "A vehicle with an ID of " .. carid .. " was created!" ) end -- If the entered car name returns no car ID, 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 ID in the chatbox, -- because a car did exist under the given car name. end addCommandHandler ( "spawnvehicle", createvehiclecommand )
See Also
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates