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

***

[SixL server API](../../README.md) / [events](../README.md) / EventMpPool

# Interface: EventMpPool

The event registry: `mp.events`.

## Example

```ts
mp.events.add('playerChat', (player, text) => { });
```

## Properties

### delayInitialization

> **delayInitialization**: `boolean`

A stored flag only.

#### Remarks

Partial: the field exists but nothing is delayed.

#### Example

```ts
mp.events.delayInitialization = true;
```

***

### delayShutdown

> **delayShutdown**: `boolean`

A stored flag, kept so that RAGE MP scripts that set it keep working.

#### Remarks

Partial: the field exists but nothing is delayed.

#### Example

```ts
mp.events.delayShutdown = true;
```

***

### delayTermination

> **delayTermination**: `boolean`

A stored flag only.

#### Remarks

Partial: the field exists but nothing is delayed.

#### Example

```ts
mp.events.delayTermination = true;
```

## Methods

### add()

#### Call Signature

> **add**\<`K`\>(`eventName`, `callback`): `void`

Registers an event handler.

##### Type Parameters

###### K

`K` *extends* keyof [`IServerEvents`](IServerEvents.md)

##### Parameters

###### eventName

`K`

A server event (see [IServerEvents](IServerEvents.md)), or any name: an event from a client
(`mp.events.callRemote`) arrives as `(player, ...args)` with the client's arguments spread.

###### callback

[`IServerEvents`](IServerEvents.md)\[`K`\]

The handler.

##### Returns

`void`

##### Remarks

A value that is not a function is skipped with a warning. The handler is not given a `this.cancel`.

##### Example

```ts
mp.events.add('playerJoin', (player) => { });
```

#### Call Signature

> **add**(`eventHandlers`): `void`

Registers several handlers from an object of event name to handler.

##### Parameters

###### eventHandlers

[`MultiEventHandlers`](../type-aliases/MultiEventHandlers.md)

The handlers by event name.

##### Returns

`void`

##### Example

```ts
mp.events.add({ playerJoin: (player) => { }, playerQuit: (player) => { } });
```

#### Call Signature

> **add**(`eventName`, `callback`): `void`

Registers a handler for any event name.

##### Parameters

###### eventName

`string`

The event name.

###### callback

(...`args`) => `void`

The handler.

##### Returns

`void`

##### Example

```ts
mp.events.add('shop:buy', (player, itemId) => { });
```

***

### addCommand()

#### Call Signature

> **addCommand**(`commandName`, `callback`): `void`

Registers a chat command.

##### Parameters

###### commandName

`string`

The command, with or without the slash; matched without case.

###### callback

(`player`, `fullText`, ...`args`) => `void`

Called with the player, the text after the command, then that text split on spaces.

##### Returns

`void`

##### Remarks

While a command has a handler, the `playerCommand` event is not raised for it.

##### Example

```ts
mp.events.addCommand('hp', (player, fullText) => { player.health = 100; });
```

#### Call Signature

> **addCommand**(`commands`): `void`

Registers several chat commands from an object of name to handler.

##### Parameters

###### commands

\{\[`commandName`: `string`\]: (`player`, `fullText`, ...`args`) => `void`; \}

The handlers by command name.

##### Returns

`void`

##### Example

```ts
mp.events.addCommand({ hp: (player) => { player.health = 100; } });
```

***

### addProc()

#### Call Signature

> **addProc**(`procedureName`, `callback`): `void`

Registers a procedure a client can call and wait for (`mp.events.callRemoteProc` on the client).

##### Parameters

###### procedureName

`string`

The procedure's name.

###### callback

(...`args`) => `any`

Called with the player and the client's arguments; its return value, or the value its promise
resolves to, goes back. A throw or a rejection sends the error text back, and the client's promise rejects.

##### Returns

`void`

##### Example

```ts
mp.events.addProc('getCash', (player) => player.getVariable('cash'));
```

#### Call Signature

> **addProc**(`procedures`): `void`

Registers several procedures from an object of name to function.

##### Parameters

###### procedures

\{\[`name`: `string`\]: (...`args`) => `any`; \}

The functions by name.

##### Returns

`void`

##### Example

```ts
mp.events.addProc({ getCash: (player) => 0 });
```

***

### binded()

> **binded**(`eventName`): `boolean`

Whether an event has a handler, or a procedure or command is registered under that name.

#### Parameters

##### eventName

`string`

The name (commands match without case).

#### Returns

`boolean`

True if something is registered.

#### Remarks

RAGE MP's typings declare `binded` as a property; in SixL it is a function.

#### Example

```ts
if (mp.events.binded('playerJoin')) { }
```

***

### call()

#### Call Signature

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

Raises an event locally: calls its handlers in this script host at once.

##### Type Parameters

###### K

`K` *extends* keyof [`IServerEvents`](IServerEvents.md)

##### Parameters

###### eventName

`K`

The event name.

###### args

...`any`[]

The arguments the handlers get.

##### Returns

`void`

##### Remarks

Nothing is sent to any client; use `player.call` for that.

##### Example

```ts
mp.events.call('shop:opened', player, 3);
```

#### Call Signature

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

Raises any event locally, by name: calls its handlers in this script host at once.

##### Parameters

###### eventName

`string`

The event name.

###### args

...`any`[]

The arguments the handlers get.

##### Returns

`void`

##### Remarks

Nothing is sent to any client; use `player.call` for that.

##### Example

```ts
mp.events.call('shop:opened', player, 3);
```

***

### getAllOf()

#### Call Signature

> **getAllOf**\<`K`\>(`eventName`): `Function`[]

The handlers registered for an event.

##### Type Parameters

###### K

`K` *extends* keyof [`IServerEvents`](IServerEvents.md)

##### Parameters

###### eventName

`K`

The event name.

##### Returns

`Function`[]

An array of functions.

##### Example

```ts
const count = mp.events.getAllOf('playerJoin').length;
```

#### Call Signature

> **getAllOf**(`eventName`): `Function`[]

The handlers registered for any event name.

##### Parameters

###### eventName

`string`

The event name.

##### Returns

`Function`[]

An array of functions.

##### Example

```ts
const count = mp.events.getAllOf('shop:buy').length;
```

***

### remove()

#### Call Signature

> **remove**\<`K`\>(`eventName`, `callback`): `void`

Removes a handler.

##### Type Parameters

###### K

`K` *extends* keyof [`IServerEvents`](IServerEvents.md)

##### Parameters

###### eventName

`K`

The event name.

###### callback

[`IServerEvents`](IServerEvents.md)\[`K`\]

The handler to remove.

##### Returns

`void`

##### Remarks

Partial: a handler is required here (RAGE MP also lets you drop every handler of the name, or pass an
array of names).

##### Example

```ts
mp.events.remove('playerJoin', onJoin);
```

#### Call Signature

> **remove**(`eventName`, `callback`): `void`

Removes a handler of any event name.

##### Parameters

###### eventName

`string`

The event name.

###### callback

(...`args`) => `void`

The handler to remove.

##### Returns

`void`

##### Example

```ts
mp.events.remove('shop:buy', onBuy);
```

***

### reset()

> **reset**(): `void`

Removes every event handler. Chat commands and procedures are kept.

#### Returns

`void`

#### Example

```ts
mp.events.reset();
```
