SixL client API / player / PlayerMpPool
Interface: PlayerMpPool
The players the server has streamed in to this client, and the local player.
Remarks
The pool has the local player as local and every other streamed player; length and toArray include the local player, streamed does not (see EntityMpPool.streamed).
Example
mp.players.forEach((player) => player.name);
Extends
Properties
length
readonlylength:number
The number of entities in the pool.
Remarks
For mp.players this counts the local player too; for the other pools it counts the streamed entities.
Example
console.log(`${mp.vehicles.length} vehicles in range`);
Inherited from
local
readonlylocal:PlayerMp
The local player: the player this client is. Always present, with pool id 0; its remoteId is the server's id for it.
Remarks
Its position, heading, health, armour, velocity and vehicle are refreshed from the world every frame.
Example
const me = mp.players.local;
maxStreamed
maxStreamed: number
The most entities the script wants streamed at once in this pool.
Remarks
Partial: the number is kept as set and nothing else happens. The client does not stream entities itself: the server decides which ones reach it (at most 128 of the nearest players). It starts at 128 for mp.players and at 0 for the other pools.
Example
mp.vehicles.maxStreamed = 100;
Inherited from
size
readonlysize:number
The number of entities in the pool: the same as length.
Example
for (let i = 0; i < mp.peds.size; i++) { }
Inherited from
streamed
readonlystreamed:PlayerMp[]
The streamed entities.
Remarks
For mp.players this is the other players only: the local player is left out, use EntityMpPool.toArray to get it too. For mp.peds, mp.vehicles and mp.objects it is every entity in the pool.
Example
const others = mp.players.streamed;
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.peds.apply((ped, tag) => console.log(tag, ped.id), 'ped');
Inherited from
at()
at(id):PlayerMp
Finds an entity by its pool id.
Parameters
id
number
The entity's pool id (see EntityMp.id).
Returns
The entity, or undefined when the pool has none with that id.
Remarks
For mp.players the local player has id 0.
Example
const other = mp.players.at(1);
Inherited from
atHandle()
atHandle(handle):PlayerMp
Finds an entity by its game handle.
Parameters
handle
number
The entity's handle.
Returns
The entity, or undefined when none has this handle. Handle 0 (an entity not yet shown in the game) matches nothing.
Remarks
A remote player that has no puppet in the game has the local player's handle: the lookup then gives the local player.
Example
const car = mp.vehicles.atHandle(vehicleHandle);
Inherited from
atRemoteId()
atRemoteId(remoteId):PlayerMp
Finds an entity by its server id.
Parameters
remoteId
number
The entity's server id (see EntityMp.remoteId).
Returns
The entity, or undefined when it is not in the pool.
Example
const ped = mp.peds.atRemoteId(serverId);
Inherited from
exists()
exists(entity):boolean
Whether an entity is still in the pool.
Parameters
entity
number | PlayerMp
The entity. For mp.peds, mp.vehicles and mp.objects a pool id is accepted too.
Returns
boolean
True when the entity is in the pool; a number is false for mp.players.
Example
if (mp.vehicles.exists(vehicle)) { }
Inherited from
forEach()
forEach(callingFunction):void
Calls a function for every entity in the pool.
Parameters
callingFunction
(entity) => void
Called with each entity.
Returns
void
Example
mp.vehicles.forEach((car) => console.log(car.id));
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.objects.forEachInDimension(0, (obj) => console.log(obj.id));
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 distance is measured to the entity's last known position: a vehicle or ped is where the server put it when it streamed in, and a remote player where its latest update put it.
Example
mp.vehicles.forEachInRange(mp.players.local.position, 50, (car) => console.log(car.id));
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 and the edge counts as inside.
dimension
number
Only entities of this dimension.
callingFunction
(entity) => void
Called with each entity.
Returns
void
Example
mp.peds.forEachInRange(mp.players.local.position, 20, 0, (ped) => console.log(ped.id));
Inherited from
forEachInStreamRange()
forEachInStreamRange(callingFunction):void
Calls a function for every entity that is streamed in to this client.
Parameters
callingFunction
(entity) => void
Called with each entity.
Returns
void
Remarks
The pool holds only streamed entities, so for mp.peds, mp.vehicles and mp.objects this is the same as forEach; for mp.players the local player is left out (see EntityMpPool.streamed).
Example
mp.players.forEachInStreamRange((other) => console.log(other.name));
Inherited from
EntityMpPool.forEachInStreamRange
getClosest()
Call Signature
getClosest(position):PlayerMp
The entity closest to a point.
Parameters
position
The point (metres).
Returns
The closest entity (3D distance to its last known position), or null when the pool is empty.
Example
const nearest = mp.vehicles.getClosest(mp.players.local.position);
Inherited from
Call Signature
getClosest(position,limit):PlayerMp[]
The limit entities closest to a point, nearest first.
Parameters
position
The point (metres).
limit
number
How many to return at most.
Returns
PlayerMp[]
An array of up to limit entities.
Example
const [nearest] = mp.vehicles.getClosest(mp.players.local.position, 1);
Inherited from
toArray()
toArray(): PlayerMp[]
A snapshot of the pool's entities.
Returns
PlayerMp[]
A new array; changing it does not change the pool. For mp.players it includes the local player.
Example
const names = mp.players.toArray().map((p) => p.name);
Inherited from
toArrayFast()
toArrayFast(): PlayerMp[]
Like toArray, but without a new array on every call: the same array is filled again and returned.
Returns
PlayerMp[]
The pool's array, valid until the next call; copy it to keep it. For mp.players it includes the local player.
Example
for (const ped of mp.peds.toArrayFast()) { }