VehicleClient

getRandomVehicleInSphere

GET_RANDOM_VEHICLE_IN_SPHERE0x386F6CE5BAF6091C

The GTA V native GET_RANDOM_VEHICLE_IN_SPHERE of the VEHICLE namespace, as LS:MP client scripts call it: the global function getRandomVehicleInSphere, in JavaScript and in Lua.

SignatureJavaScript
getRandomVehicleInSphere(
  x: number,
  y: number,
  z: number,
  radius: number,
  modelHash: Hash,
  flags: number
): Vehicle
SignatureLua
getRandomVehicleInSphere(
  x: number,
  y: number,
  z: number,
  radius: number,
  modelHash: Hash,
  flags: integer
): Vehicle

Usage

JavaScript
const vehicle = getRandomVehicleInSphere(x, y, z, radius, modelHash, flags);
Lua
local vehicle = getRandomVehicleInSphere(x, y, z, radius, modelHash, flags)

Three consecutive numbers can be given as one vector: { x, y, z } (or [x, y, z]) in JavaScript, a Vector3 in Lua.

JavaScript · with vectors
const vehicle = getRandomVehicleInSphere(pos, radius, modelHash, flags);
Lua · with vectors
local vehicle = getRandomVehicleInSphere(pos, radius, modelHash, flags)

Parameters

ParameterTypeJavaScriptLuaDescription
xfloatnumbernumberThe X-component of the position of the sphere.
yfloatnumbernumberThe Y-component of the position of the sphere.
zfloatnumbernumberThe Z-component of the position of the sphere.
radiusfloatnumbernumberThe radius of the sphere. Max is 9999.9004.
modelHashHashnumberintegerThe vehicle model to limit the selection to. Pass 0 for any model.
flagsintnumberintegerThe bitwise flags that modifies the behaviour of this function.

Returns

Vehicle JavaScript number, Lua integer

Game handle of a vehicle. Not an LS:MP netId. Convert one with lsmp.getEntityFromNetId.

Notes

From the community native database. Names are LS:MP’s; samples may be written for C++ or another framework.

Gets a random vehicle in a sphere at the specified position, of the specified radius.

Full list of vehicles by DurtyFree: https://github.com/DurtyFree/gta-v-data-dumps/blob/master/vehicles.json

Reference

Namespace
Vehicle VEHICLE
In the game
Vehicle GET_RANDOM_VEHICLE_IN_SPHERE(float x, float y, float z, float radius, Hash modelHash, int flags)
Hash
0x386F6CE5BAF6091C

Open in the interactive natives reference