SixL server API / vehicle / VehicleMpPool

Interface: VehicleMpPool

The pool of vehicles: mp.vehicles.

Example

mp.vehicles.forEach((car) => { if (car.dead) car.destroy(); });

Extends

Properties

length

readonly length: number

The number of entities in the pool.

Example

console.log(`${mp.players.length} online`);

Inherited from

EntityMpPool.length


size

readonly size: number

The number of entities in the pool; the same as length.

Example

const online = mp.players.size;

Inherited from

EntityMpPool.size

Methods

apply()

apply(callingFunction, ...args): void

Calls a function for every entity, giving it extra arguments: fn(entity, ...args).

Parameters

callingFunction

(...args) => void

Called with each entity, then with args.

args

...any[]

Passed after the entity.

Returns

void

Example

mp.players.apply((p, text) => p.outputChatBox(text), 'server restart');

Inherited from

EntityMpPool.apply


at()

at(id): VehicleMp

Finds an entity by id.

Parameters

id

number

The entity's id.

Returns

VehicleMp

The entity, or null when there is none.

Example

const player = mp.players.at(3);

Inherited from

EntityMpPool.at


exists()

exists(entity): boolean

Whether an entity (or an id) is still in the pool.

Parameters

entity

number | VehicleMp

An entity or its id.

Returns

boolean

True when it exists. null and undefined give false.

Example

if (mp.vehicles.exists(vehicle)) { }

Inherited from

EntityMpPool.exists


forEach()

forEach(callingFunction): void

Calls a function for every entity.

Parameters

callingFunction

(entity) => void

Called with each entity.

Returns

void

Example

mp.vehicles.forEach((v) => v.repair());

Inherited from

EntityMpPool.forEach


forEachFast()

forEachFast(callingFunction): void

Calls a function for every entity; the same as forEach in SixL.

Parameters

callingFunction

(entity) => void

Called with each entity.

Returns

void

Remarks

Not faster than forEach: a SixL pool is already a plain loop.

Example

mp.players.forEachFast((p) => p.notify('tick'));

Inherited from

EntityMpPool.forEachFast


forEachInDimension()

forEachInDimension(dimension, callingFunction): void

Calls a function for every entity in a dimension.

Parameters

dimension

number

The dimension to match exactly.

callingFunction

(entity) => void

Called with each entity.

Returns

void

Example

mp.players.forEachInDimension(5, (p) => p.outputChatBox('hi'));

Inherited from

EntityMpPool.forEachInDimension


forEachInRange()

Call Signature

forEachInRange(position, range, callingFunction): void

Calls a function for every entity within a radius of a point.

Parameters
position

Vector3

The centre (metres).

range

number

The radius in metres; the distance is 3D and the edge counts as inside.

callingFunction

(entity) => void

Called with each entity.

Returns

void

Remarks

The matches are collected first, so the function may move or destroy entities safely.

Example
mp.vehicles.forEachInRange(pos, 50, (v) => v.repair());
Inherited from

EntityMpPool.forEachInRange

Call Signature

forEachInRange(position, range, dimension, callingFunction): void

Calls a function for every entity within a radius of a point, in one dimension.

Parameters
position

Vector3

The centre (metres).

range

number

The radius in metres; the distance is 3D.

dimension

number

Only entities of this dimension.

callingFunction

(entity) => void

Called with each entity.

Returns

void

Example
mp.players.forEachInRange(pos, 20, 0, (p) => p.notify('near'));
Inherited from

EntityMpPool.forEachInRange


getClosest()

Call Signature

getClosest(position): VehicleMp

The entity closest to a point.

Parameters
position

Vector3

The point (metres).

Returns

VehicleMp

The closest entity (3D distance), or null when the pool is empty.

Example
const nearest = mp.players.getClosest(pos);
Inherited from

EntityMpPool.getClosest

Call Signature

getClosest(position, limit): VehicleMp[]

The limit entities closest to a point, nearest first.

Parameters
position

Vector3

The point (metres).

limit

number

How many to return at most.

Returns

VehicleMp[]

An array of up to limit entities.

Example
const three = mp.vehicles.getClosest(pos, 3);
Inherited from

EntityMpPool.getClosest


getClosestInDimension()

Call Signature

getClosestInDimension(position, dimension): VehicleMp

The entity closest to a point among those of one dimension.

Parameters
position

Vector3

The point (metres).

dimension

number

Only entities of this dimension.

Returns

VehicleMp

The closest entity, or null when there is none.

Example
const nearest = mp.players.getClosestInDimension(pos, 2);
Inherited from

EntityMpPool.getClosestInDimension

Call Signature

getClosestInDimension(position, dimension, limit): VehicleMp[]

The limit entities of one dimension closest to a point, nearest first.

Parameters
position

Vector3

The point (metres).

dimension

number

Only entities of this dimension.

limit

number

How many to return at most.

Returns

VehicleMp[]

An array of up to limit entities.

Example
const two = mp.players.getClosestInDimension(pos, 2, 2);
Inherited from

EntityMpPool.getClosestInDimension


new()

new(model, position, options?): VehicleMp

Creates a vehicle.

Parameters

model

HashOrNumberOrString

The model: a name, or a hash that mp.joaat computed earlier in this run (it is turned back to its name; an unknown hash is passed on as its decimal string).

position

Vector3

Where (metres).

options?

number | VehicleCreateOptions

Optional. A heading in degrees, or an options object.

Returns

VehicleMp

The vehicle, at once: the server hears of it a moment later.

Remarks

Partial. VI's vehicle models are 64-bit keys and GTA V's model names are not found; use a VI name or key. The options heading, dimension and numberPlate work; color1 / color2 are ignored by the server and the plate does not reach the clients' game yet. RAGE MP's alpha, color, engine and locked options are not read: set the properties afterwards.

Example

const car = mp.vehicles.new('sultan', new mp.Vector3(0, 0, 70), { heading: 90, dimension: 0 });

toArray()

toArray(): VehicleMp[]

A snapshot of all entities.

Returns

VehicleMp[]

A new array; changing it does not change the pool.

Example

const names = mp.players.toArray().map((p) => p.name);

Inherited from

EntityMpPool.toArray