[**SixL server API**](../../README.md)

***

[SixL server API](../../README.md) / [player](../README.md) / PlayerMpPool

# Interface: PlayerMpPool

The pool of players: `mp.players`.

## Example

```ts
mp.players.forEach((p) => p.outputChatBox('Server restart in 5 minutes'));
```

## Extends

- [`EntityMpPool`](../../entity/interfaces/EntityMpPool.md)\<[`PlayerMp`](PlayerMp.md)\>

## Properties

### length

> `readonly` **length**: `number`

The number of entities in the pool.

#### Example

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`length`](../../entity/interfaces/EntityMpPool.md#length)

***

### size

> `readonly` **size**: `number`

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

#### Example

```ts
const online = mp.players.size;
```

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`size`](../../entity/interfaces/EntityMpPool.md#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

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`apply`](../../entity/interfaces/EntityMpPool.md#apply)

***

### at()

> **at**(`id`): [`PlayerMp`](PlayerMp.md)

Finds an entity by id.

#### Parameters

##### id

`number`

The entity's id.

#### Returns

[`PlayerMp`](PlayerMp.md)

The entity, or `null` when there is none.

#### Example

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`at`](../../entity/interfaces/EntityMpPool.md#at)

***

### broadcast()

> **broadcast**(`text`): `void`

Sends a chat line to every player.

#### Parameters

##### text

`string`

The text.

#### Returns

`void`

#### Example

```ts
mp.players.broadcast('Welcome to the server');
```

***

### broadcastInRange()

#### Call Signature

> **broadcastInRange**(`position`, `range`, `text`): `void`

Sends a chat line to the players within a radius.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The centre (metres).

###### range

`number`

The radius in metres (3D).

###### text

`string`

The text.

##### Returns

`void`

##### Example

```ts
mp.players.broadcastInRange(pos, 30, 'A bang!');
```

#### Call Signature

> **broadcastInRange**(`position`, `range`, `dimension`, `text`): `void`

Sends a chat line to the players within a radius, in one dimension.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The centre (metres).

###### range

`number`

The radius in metres (3D).

###### dimension

`number`

Only players of this dimension.

###### text

`string`

The text.

##### Returns

`void`

##### Example

```ts
mp.players.broadcastInRange(pos, 30, 0, 'A bang!');
```

***

### call()

> **call**(`eventName`, ...`args`): `void`

Calls a client event on every player.

#### Parameters

##### eventName

`string`

The client event name.

##### args

...`any`[]

The arguments, JSON-serialisable; a single array argument is spread (see [PlayerMp.call](PlayerMp.md#call)).

#### Returns

`void`

#### Remarks

The server relays the event to all players.

#### Example

```ts
mp.players.call('hud:message', ['Hello']);
```

***

### callInDimension()

> **callInDimension**(`dimension`, `eventName`, ...`args`): `void`

Calls a client event on the players of one dimension.

#### Parameters

##### dimension

`number`

The dimension to match exactly.

##### eventName

`string`

The client event name.

##### args

...`any`[]

The arguments, JSON-serialisable.

#### Returns

`void`

#### Example

```ts
mp.players.callInDimension(5, 'arena:start', []);
```

***

### callInDimensionUnreliable()

> **callInDimensionUnreliable**(`dimension`, `eventName`, ...`args`): `void`

Calls a client event on the players of one dimension, without the reliability guarantee.

#### Parameters

##### dimension

`number`

The dimension to match exactly.

##### eventName

`string`

The client event name.

##### args

...`any`[]

The arguments, JSON-serialisable.

#### Returns

`void`

#### Remarks

Partial: delivered reliably, like `callInDimension`.

#### Example

```ts
mp.players.callInDimensionUnreliable(5, 'arena:tick', [1]);
```

***

### callInRange()

#### Call Signature

> **callInRange**(`position`, `range`, `eventName`, ...`args`): `void`

Calls a client event on the players within a radius of a point.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The centre (metres).

###### range

`number`

The radius in metres (3D).

###### eventName

`string`

The client event name.

###### args

...`any`[]

The arguments, JSON-serialisable.

##### Returns

`void`

##### Example

```ts
mp.players.callInRange(pos, 50, 'fx:explosion', [pos.x, pos.y, pos.z]);
```

#### Call Signature

> **callInRange**(`position`, `range`, `dimension`, `eventName`, ...`args`): `void`

Calls a client event on the players within a radius of a point, in one dimension.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The centre (metres).

###### range

`number`

The radius in metres (3D).

###### dimension

`number`

Only players of this dimension.

###### eventName

`string`

The client event name.

###### args

...`any`[]

The arguments, JSON-serialisable.

##### Returns

`void`

##### Example

```ts
mp.players.callInRange(pos, 50, 0, 'fx:explosion', []);
```

***

### callInRangeUnreliable()

#### Call Signature

> **callInRangeUnreliable**(`position`, `range`, `eventName`, ...`args`): `void`

Calls a client event on the players within a radius, without the reliability guarantee.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The centre (metres).

###### range

`number`

The radius in metres (3D).

###### eventName

`string`

The client event name.

###### args

...`any`[]

The arguments, JSON-serialisable.

##### Returns

`void`

##### Remarks

Partial: delivered reliably, like `callInRange`.

##### Example

```ts
mp.players.callInRangeUnreliable(pos, 50, 'fx:tick', []);
```

#### Call Signature

> **callInRangeUnreliable**(`position`, `range`, `dimension`, `eventName`, ...`args`): `void`

Calls a client event on the players within a radius in one dimension, without the reliability guarantee.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The centre (metres).

###### range

`number`

The radius in metres (3D).

###### dimension

`number`

Only players of this dimension.

###### eventName

`string`

The client event name.

###### args

...`any`[]

The arguments, JSON-serialisable.

##### Returns

`void`

##### Remarks

Partial: delivered reliably.

##### Example

```ts
mp.players.callInRangeUnreliable(pos, 50, 0, 'fx:tick', []);
```

***

### callUnreliable()

> **callUnreliable**(`eventName`, ...`args`): `void`

Calls a client event on every player, without the reliability guarantee.

#### Parameters

##### eventName

`string`

The client event name.

##### args

...`any`[]

The arguments, as in [PlayerMpPool.call](#call).

#### Returns

`void`

#### Remarks

Partial: the server has no unreliable events, so it is delivered reliably.

#### Example

```ts
mp.players.callUnreliable('hudTick', [1]);
```

***

### exists()

> **exists**(`entity`): `boolean`

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

#### Parameters

##### entity

`number` \| [`PlayerMp`](PlayerMp.md)

An entity or its id.

#### Returns

`boolean`

True when it exists. `null` and `undefined` give false.

#### Example

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`exists`](../../entity/interfaces/EntityMpPool.md#exists)

***

### forEach()

> **forEach**(`callingFunction`): `void`

Calls a function for every entity.

#### Parameters

##### callingFunction

(`entity`) => `void`

Called with each entity.

#### Returns

`void`

#### Example

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`forEach`](../../entity/interfaces/EntityMpPool.md#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

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`forEachFast`](../../entity/interfaces/EntityMpPool.md#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

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`forEachInDimension`](../../entity/interfaces/EntityMpPool.md#foreachindimension)

***

### forEachInRange()

#### Call Signature

> **forEachInRange**(`position`, `range`, `callingFunction`): `void`

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

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

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

```ts
mp.vehicles.forEachInRange(pos, 50, (v) => v.repair());
```

##### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`forEachInRange`](../../entity/interfaces/EntityMpPool.md#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`](../../common/interfaces/Vector3.md)

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

```ts
mp.players.forEachInRange(pos, 20, 0, (p) => p.notify('near'));
```

##### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`forEachInRange`](../../entity/interfaces/EntityMpPool.md#foreachinrange)

***

### getClosest()

#### Call Signature

> **getClosest**(`position`): [`PlayerMp`](PlayerMp.md)

The entity closest to a point.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The point (metres).

##### Returns

[`PlayerMp`](PlayerMp.md)

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

##### Example

```ts
const nearest = mp.players.getClosest(pos);
```

##### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`getClosest`](../../entity/interfaces/EntityMpPool.md#getclosest)

#### Call Signature

> **getClosest**(`position`, `limit`): [`PlayerMp`](PlayerMp.md)[]

The `limit` entities closest to a point, nearest first.

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The point (metres).

###### limit

`number`

How many to return at most.

##### Returns

[`PlayerMp`](PlayerMp.md)[]

An array of up to `limit` entities.

##### Example

```ts
const three = mp.vehicles.getClosest(pos, 3);
```

##### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`getClosest`](../../entity/interfaces/EntityMpPool.md#getclosest)

***

### getClosestInDimension()

#### Call Signature

> **getClosestInDimension**(`position`, `dimension`): [`PlayerMp`](PlayerMp.md)

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

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The point (metres).

###### dimension

`number`

Only entities of this dimension.

##### Returns

[`PlayerMp`](PlayerMp.md)

The closest entity, or `null` when there is none.

##### Example

```ts
const nearest = mp.players.getClosestInDimension(pos, 2);
```

##### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`getClosestInDimension`](../../entity/interfaces/EntityMpPool.md#getclosestindimension)

#### Call Signature

> **getClosestInDimension**(`position`, `dimension`, `limit`): [`PlayerMp`](PlayerMp.md)[]

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

##### Parameters

###### position

[`Vector3`](../../common/interfaces/Vector3.md)

The point (metres).

###### dimension

`number`

Only entities of this dimension.

###### limit

`number`

How many to return at most.

##### Returns

[`PlayerMp`](PlayerMp.md)[]

An array of up to `limit` entities.

##### Example

```ts
const two = mp.players.getClosestInDimension(pos, 2, 2);
```

##### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`getClosestInDimension`](../../entity/interfaces/EntityMpPool.md#getclosestindimension)

***

### toArray()

> **toArray**(): [`PlayerMp`](PlayerMp.md)[]

A snapshot of all entities.

#### Returns

[`PlayerMp`](PlayerMp.md)[]

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

#### Example

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

#### Inherited from

[`EntityMpPool`](../../entity/interfaces/EntityMpPool.md).[`toArray`](../../entity/interfaces/EntityMpPool.md#toarray)
