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

***

[SixL client API](../../README.md) / [object](../README.md) / ObjectMpPool

# Interface: ObjectMpPool

The pool of the objects the server streamed in to this client: `mp.objects`.

## Remarks

The members of EntityMpPool (`length`, `at`, `exists`, `forEach`, `toArray`) are there too. Objects made on the
client are not supported yet, so there is no `new` here.

## Example

```ts
mp.objects.forEach((obj) => console.log(obj.model));
```

## Extends

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

## Constructors

### Constructor

> **new ObjectMpPool**(`model`, `position`, `options?`): [`ObjectMp`](ObjectMp.md)

Makes an object on this client only (a prop for a mapping, a preview): no other player sees it, the server does
not know it.

#### Parameters

##### model

`string` \| `number`

The model: a name, its hash, or a "0x" model key.

##### position

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

Where it stands, metres.

##### options?

`rotation` in degrees (the game takes the yaw, `z`); `alpha` and `dimension` are accepted and not
applied yet.

###### alpha?

`number`

###### dimension?

`number`

###### rotation?

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

#### Returns

[`ObjectMp`](ObjectMp.md)

The object at once; its `handle` is 0 until the game made it (a fraction of a second).

#### Remarks

Partial: at most 128 client-made objects at once; `destroy()` deletes one. Not yet confirmed in the game.

#### Example

```ts
const prop = mp.objects.new(modelName, new mp.Vector3(10, 20, 30), { rotation: new mp.Vector3(0, 0, 90) });
```

#### Inherited from

`EntityMpPool<ObjectMp>.constructor`

## Properties

### length

> `readonly` **length**: `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

```ts
console.log(`${mp.vehicles.length} vehicles in range`);
```

#### Inherited from

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

***

### 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

```ts
mp.vehicles.maxStreamed = 100;
```

#### Inherited from

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

***

### size

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

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

#### Example

```ts
for (let i = 0; i < mp.peds.size; i++) { }
```

#### Inherited from

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

***

### streamed

> `readonly` **streamed**: [`ObjectMp`](ObjectMp.md)[]

The streamed objects, as an array.

#### Remarks

A snapshot: it does not change when objects stream in or out later.

#### Example

```ts
const count = mp.objects.streamed.length;
```

#### Overrides

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

## 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.peds.apply((ped, tag) => console.log(tag, ped.id), 'ped');
```

#### Inherited from

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

***

### at()

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

Finds an entity by its pool id.

#### Parameters

##### id

`number`

The entity's pool id (see [EntityMp.id](../../entity/interfaces/EntityMp.md#id)).

#### Returns

[`ObjectMp`](ObjectMp.md)

The entity, or `undefined` when the pool has none with that id.

#### Remarks

For `mp.players` the local player has id 0.

#### Example

```ts
const other = mp.players.at(1);
```

#### Inherited from

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

***

### atHandle()

> **atHandle**(`handle`): [`ObjectMp`](ObjectMp.md)

Finds an object by its game handle.

#### Parameters

##### handle

`number`

The object's game handle, as `obj.handle` gives it.

#### Returns

[`ObjectMp`](ObjectMp.md)

The object, or `undefined` when there is none.

#### Example

```ts
const obj = mp.objects.atHandle(obj.handle);
```

#### Overrides

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

***

### atRemoteId()

> **atRemoteId**(`remoteId`): [`ObjectMp`](ObjectMp.md)

Finds an object by the id the server gave it.

#### Parameters

##### remoteId

`number`

The server's id of the object.

#### Returns

[`ObjectMp`](ObjectMp.md)

The object, or `undefined` when the server has not streamed it in.

#### Example

```ts
const obj = mp.objects.atRemoteId(7);
```

#### Overrides

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

***

### exists()

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

Whether an entity is still in the pool.

#### Parameters

##### entity

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

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

```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 in the pool.

#### Parameters

##### callingFunction

(`entity`) => `void`

Called with each entity.

#### Returns

`void`

#### Example

```ts
mp.vehicles.forEach((car) => console.log(car.id));
```

#### Inherited from

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

***

### 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.objects.forEachInDimension(0, (obj) => console.log(obj.id));
```

#### 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 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

```ts
mp.vehicles.forEachInRange(mp.players.local.position, 50, (car) => console.log(car.id));
```

##### 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 and the edge counts as inside.

###### dimension

`number`

Only entities of this dimension.

###### callingFunction

(`entity`) => `void`

Called with each entity.

##### Returns

`void`

##### Example

```ts
mp.peds.forEachInRange(mp.players.local.position, 20, 0, (ped) => console.log(ped.id));
```

##### Inherited from

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

***

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

#### Example

```ts
mp.players.forEachInStreamRange((other) => console.log(other.name));
```

#### Inherited from

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

***

### getClosest()

#### Call Signature

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

The entity closest to a point.

##### Parameters

###### position

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

The point (metres).

##### Returns

[`ObjectMp`](ObjectMp.md)

The closest entity (3D distance to its last known `position`), or `null` when the pool is empty.

##### Example

```ts
const nearest = mp.vehicles.getClosest(mp.players.local.position);
```

##### Inherited from

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

#### Call Signature

> **getClosest**(`position`, `limit`): [`ObjectMp`](ObjectMp.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

[`ObjectMp`](ObjectMp.md)[]

An array of up to `limit` entities.

##### Example

```ts
const [nearest] = mp.vehicles.getClosest(mp.players.local.position, 1);
```

##### Inherited from

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

***

### toArray()

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

A snapshot of the pool's entities.

#### Returns

[`ObjectMp`](ObjectMp.md)[]

A new array; changing it does not change the pool. For `mp.players` it includes the local player.

#### Example

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

#### Inherited from

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

***

### toArrayFast()

> **toArrayFast**(): [`ObjectMp`](ObjectMp.md)[]

Like `toArray`, but without a new array on every call: the same array is filled again and returned.

#### Returns

[`ObjectMp`](ObjectMp.md)[]

The pool's array, valid until the next call; copy it to keep it. For `mp.players` it includes the local player.

#### Example

```ts
for (const ped of mp.peds.toArrayFast()) { }
```

#### Inherited from

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