SixL server API / world-entities / ObjectMpPool
Interface: ObjectMpPool
The pool of objects: mp.objects.
Example
mp.objects.forEachInRange(pos, 10, (o) => o.destroy());
Extends
Properties
length
readonlylength:number
The number of entities in the pool.
Example
console.log(`${mp.players.length} online`);
Inherited from
size
readonlysize:number
The number of entities in the pool; the same as length.
Example
const online = mp.players.size;
Inherited from
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
at()
at(id):ObjectMp
Finds an entity by id.
Parameters
id
number
The entity's id.
Returns
The entity, or null when there is none.
Example
const player = mp.players.at(3);
Inherited from
exists()
exists(entity):boolean
Whether an entity (or an id) is still in the pool.
Parameters
entity
number | ObjectMp
An entity or its id.
Returns
boolean
True when it exists. null and undefined give false.
Example
if (mp.vehicles.exists(vehicle)) { }
Inherited from
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
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
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
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
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
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
getClosest()
Call Signature
getClosest(position):ObjectMp
The entity closest to a point.
Parameters
position
The point (metres).
Returns
The closest entity (3D distance), or null when the pool is empty.
Example
const nearest = mp.players.getClosest(pos);
Inherited from
Call Signature
getClosest(position,limit):ObjectMp[]
The limit entities closest to a point, nearest first.
Parameters
position
The point (metres).
limit
number
How many to return at most.
Returns
ObjectMp[]
An array of up to limit entities.
Example
const three = mp.vehicles.getClosest(pos, 3);
Inherited from
getClosestInDimension()
Call Signature
getClosestInDimension(position,dimension):ObjectMp
The entity closest to a point among those of one dimension.
Parameters
position
The point (metres).
dimension
number
Only entities of this dimension.
Returns
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):ObjectMp[]
The limit entities of one dimension closest to a point, nearest first.
Parameters
position
The point (metres).
dimension
number
Only entities of this dimension.
limit
number
How many to return at most.
Returns
ObjectMp[]
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?):ObjectMp
Creates an object.
Parameters
model
The model: a name, or a hash (a number becomes its decimal string).
position
Where (metres).
options?
Optional. rotation (degrees) and dimension.
dimension?
number
rotation?
Returns
The object, at once; the server streams it to the clients, who create it in the game.
Remarks
Partial. VI's model keys are 64-bit and GTA V's model names are not found: use a key the game knows, e.g. 0x<hash> (a VI model key); the core takes a 0x... key as it is. Only the yaw of rotation is applied in the game. A destroyed object is hidden in the game (the game cannot free it). RAGE MP's alpha option is not read: set alpha afterwards.
Example
const prop = mp.objects.new('0x<hash>', new mp.Vector3(0, 0, 70), { rotation: new mp.Vector3(0, 0, 90) });
toArray()
toArray(): ObjectMp[]
A snapshot of all entities.
Returns
ObjectMp[]
A new array; changing it does not change the pool.
Example
const names = mp.players.toArray().map((p) => p.name);