Squirrel/Server/Functions/Vehicles/GetClosestVehicle

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with '{{Squirrel/Title|GetClosestVehicle}} 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 '…')
 

Latest revision as of 18:38, 29 September 2010

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.

[edit] Syntax

  1. Vehicle GetClosestVehicle( Player plr )

[edit] Arguments

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

[edit] 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.  

[edit] Notes

The functions MessagePlayer, Vehicle.Health 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