GetClosestVehicle

From Liberty Unleashed Wiki
Jump to: navigation, search
Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This function looks for the closest vehicle to a player and returns a pointer to it. If there are no vehicles in-game, the function returns null.

Syntax

  1. Vehicle GetClosestVehicle( Player plr )

Arguments

  • plr - This is the player you wish to search the closest vehicle for

Example

This example command returns the health of the closest vehicle when a player types '/carhp'.

  1.  
  2. function onPlayerCommand( plr, cmd, text )
  3. {
  4. if ( cmd == "carhp" )
  5. {
  6. local veh = GetClosestVehicle( plr );
  7. if ( veh ) MessagePlayer( "The vehicle closest to you has " + veh.Health + " health.", plr );
  8. else MessagePlayer( "No vehicles nearby!", plr );
  9. }
  10. return 1;
  11. }
  12.  

Notes

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

Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox