Squirrel/Server/Functions/Vehicles/GetVehicleName

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
(Made the examples more general, optimisation)
 
Line 14: Line 14:
  
 
== Example ==
 
== Example ==
 +
 +
These two example commands return the name of the vehicle from model ID or the name of the vehicle the player is currently occupying.
  
 
<code lang="squirrel">
 
<code lang="squirrel">
Line 20: Line 22:
 
if ( szCommand == "vehname" )
 
if ( szCommand == "vehname" )
 
{
 
{
local szName = GetVehicleModelFromName( VEH_INFERNUS );
+
local iID = szText ? szText.tointeger() : VEH_LANDSTALKER;
if ( szName ) MessagePlayer( "Vehicle model id - " + VEH_INFERNUS + ", name " + szName, pPlayer );
+
local szName = GetVehicleName( iID );
 +
MessagePlayer( "Vehicle model id - " + iID + ", name - " + szName, pPlayer );
 
}
 
}
 
 
if ( szCommand == "vehname2" )
+
else if ( szCommand == "vehname2" )
 
{
 
{
local pVehicle = FindVehicle( 0 ), szName;
+
local pVehicle = pPlayer.Vehicle;
 
if ( pVehicle )
 
if ( pVehicle )
 
{
 
{
szName = GetVehicleModelFromName( pVehicle )
+
local szName = GetVehicleName( pVehicle )
if ( szName ) MessagePlayer( "Vehicle model id - " + pVehicle.Model + ", name " + szName, pPlayer );
+
MessagePlayer( "Vehicle model id - " + pVehicle.Model + ", name " + szName, pPlayer );
 
}
 
}
 
}
 
}
Line 40: Line 43:
 
=== Notes ===
 
=== Notes ===
  
The functions [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and [[Squirrel/Server/Functions/Vehicles/FindVehicle|FindVehicle]] and event [[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
+
The functions [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]], [[Squirrel/Server/Functions/Players/Vehicle|Player.Vehicle]] and event [[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
  
 
== Related Functions ==
 
== Related Functions ==
  
 
{{Squirrel/Server/Functions/Vehicles}}
 
{{Squirrel/Server/Functions/Vehicles}}

Latest revision as of 19:14, 29 September 2010

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This function returns the name of the vehicle. The function can be used to retrieve the name of a specific vehicle or return the name of a model ID.

[edit] Syntax

GetVehicleName can take different lists of parameters:

  1. string GetVehicleName( int model )
  1. string GetVehicleName( Vehicle veh )

[edit] Arguments

  • model - The model you wish to return the name for
  • veh - A Vehicle instance you wish to return the name for

[edit] Example

These two example commands return the name of the vehicle from model ID or the name of the vehicle the player is currently occupying.

  1.  
  2. function onPlayerCommand( pPlayer, szCommand, szText )
  3. {
  4. if ( szCommand == "vehname" )
  5. {
  6. local iID = szText ? szText.tointeger() : VEH_LANDSTALKER;
  7. local szName = GetVehicleName( iID );
  8. MessagePlayer( "Vehicle model id - " + iID + ", name - " + szName, pPlayer );
  9. }
  10. else if ( szCommand == "vehname2" )
  11. {
  12. local pVehicle = pPlayer.Vehicle;
  13. if ( pVehicle )
  14. {
  15. local szName = GetVehicleName( pVehicle )
  16. MessagePlayer( "Vehicle model id - " + pVehicle.Model + ", name " + szName, pPlayer );
  17. }
  18. }
  19. return 1;
  20. }
  21.  

[edit] Notes

The functions MessagePlayer, Player.Vehicle and event onPlayerCommand were used in this example. More info about them in the corresponding pages.

[edit] Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox