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

***

[SixL client API](../../README.md) / [events](../README.md) / IClientEvents

# Interface: IClientEvents

Client events: the events the client raises, with their handler signatures. Register a handler with `mp.events.add(name, fn)`.
Events the server sends to this client (`player.call` on the server) and events your own scripts raise with
`mp.events.call` use plain string names and are not listed here.

## Remarks

Only the events the client itself raises are listed. A handler that throws is reported to the log and the other
handlers still run; the runtime keeps going.

## Example

```ts
mp.events.add('playerReady', () => mp.console.logInfo('ready'));
```

## Properties

### browserCreated

> **browserCreated**: (`browser`) => `void`

A browser was created with `mp.browsers.new`.

#### Parameters

##### browser

[`BrowserMp`](../../browser/interfaces/BrowserMp.md)

The new browser.

#### Returns

`void`

#### Remarks

Raised after `mp.browsers.new` has returned, so a handler added right after the call still sees it.

#### Example

```ts
mp.events.add('browserCreated', (browser) => mp.console.logInfo('browser ' + browser.id));
```

***

### browserDomReady

> **browserDomReady**: (`browser`) => `void`

A browser's page finished loading its document, so its scripts can be called.

#### Parameters

##### browser

[`BrowserMp`](../../browser/interfaces/BrowserMp.md)

The browser whose page is ready.

#### Returns

`void`

#### Example

```ts
mp.events.add('browserDomReady', (browser) => browser.execute('init()'));
```

***

### browserLoadingFailed

> **browserLoadingFailed**: (`browser`, `url`, `reason`) => `void`

A browser's page failed to load.

#### Parameters

##### browser

[`BrowserMp`](../../browser/interfaces/BrowserMp.md)

The browser whose page failed.

##### url

`string`

The address that failed to load.

##### reason

`string`

A short text saying why it failed.

#### Returns

`void`

#### Remarks

SixL passes `url` and `reason` after the browser; RAGE MP's handler gets the browser only. A handler
written for RAGE MP ignores the extra arguments.

#### Example

```ts
mp.events.add('browserLoadingFailed', (browser, url, reason) => mp.console.logError(url + ': ' + reason));
```

***

### dummyEntityCreated

> **dummyEntityCreated**: (`dummyType`, `dummy`) => `void`

A dummy entity of the server's scripts is known to this client: made by the server, or there when the client joined.

#### Parameters

##### dummyType

`number`

The dummy's type.

##### dummy

[`DummyEntityMp`](../../dummies/interfaces/DummyEntityMp.md)

The dummy; its variables are already readable.

#### Returns

`void`

#### Remarks

Partial: raised again for every dummy after the client's scripts restart. Not yet confirmed in the game.

#### Example

```ts
mp.events.add('dummyEntityCreated', (dummyType, dummy) => mp.console.logInfo(String(dummy.getVariable('owner'))));
```

***

### dummyEntityDestroyed

> **dummyEntityDestroyed**: (`dummyType`, `dummy`) => `void`

A dummy entity of the server's scripts was destroyed (or the client left the server).

#### Parameters

##### dummyType

`number`

The dummy's type.

##### dummy

[`DummyEntityMp`](../../dummies/interfaces/DummyEntityMp.md)

The dummy, still readable in the handler.

#### Returns

`void`

#### Remarks

Partial: not yet confirmed in the game.

#### Example

```ts
mp.events.add('dummyEntityDestroyed', (dummyType, dummy) => mp.console.logInfo('gone ' + dummy.id));
```

***

### entityStreamIn

> **entityStreamIn**: (`entity`) => `void`

An entity came into the client's range: a player, ped, vehicle, object, blip, marker, label or checkpoint.

#### Parameters

##### entity

[`EntityMp`](../../entity/interfaces/EntityMp.md)

The new entity, an instance of its client class.

#### Returns

`void`

#### Remarks

Partial: RAGE MP raises it for players, peds, vehicles and objects only. SixL also raises it for the
world entities of the server (blips, markers, labels, checkpoints), which RAGE MP does not stream. A player's
entry is created before the handler runs.

#### Example

```ts
mp.events.add('entityStreamIn', (entity) => mp.console.logInfo(String(entity.type)));
```

***

### entityStreamOut

> **entityStreamOut**: (`entity`) => `void`

An entity left the client's range, before it is removed from its pool. The entity is still readable here.

#### Parameters

##### entity

[`EntityMp`](../../entity/interfaces/EntityMp.md)

The entity that is leaving.

#### Returns

`void`

#### Remarks

Partial: the same kinds as `entityStreamIn`, including the world entities RAGE MP does not stream.

#### Example

```ts
mp.events.add('entityStreamOut', (entity) => mp.console.logInfo('out: ' + entity.remoteId));
```

***

### incomingDamage

> **incomingDamage**: (`sourceEntity`, `sourcePlayer`, `targetEntity`, `weapon`, `boneIndex`, `damage`) => `void`

The local player was hurt: damage from a shot, a vehicle, a fall, an explosion or anything else the game does.

#### Parameters

##### sourceEntity

[`EntityMp`](../../entity/interfaces/EntityMp.md)

Who did it: a player, a ped or a vehicle of the server. `undefined` for the world (a fall, an
explosion, fire) and when the source is an entity this client does not hold.

##### sourcePlayer

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The player who did it; `undefined` when the source is not a player.

##### targetEntity

[`EntityMp`](../../entity/interfaces/EntityMp.md)

The local player.

##### weapon

`number`

The weapon's hash. For a fall, an explosion or fire it names that source; `0` when unknown.

##### boneIndex

`number`

The bone that was hit: the hash of the bone's name, not a bone index (SixL has no index).
`0` when unknown.

##### damage

`number`

The damage the game dealt, in health points.

#### Returns

`void`

#### Remarks

Partial: raised after the damage has landed in the game, so returning `true` from the handler does not
cancel it. The server hears of the same hit as `playerHurt` and, from the new health, as `playerDamage`.

#### Example

```ts
mp.events.add('incomingDamage', (source, sourcePlayer, target, weapon, bone, damage) => { });
```

***

### outgoingDamage

> **outgoingDamage**: (`sourceEntity`, `targetEntity`, `targetPlayer`, `weapon`, `boneIndex`, `damage`) => `void`

The local player's shot hit a player or a ped of the server, and the hit went to the server.

#### Parameters

##### sourceEntity

[`EntityMp`](../../entity/interfaces/EntityMp.md)

The shooter: the local player.

##### targetEntity

[`EntityMp`](../../entity/interfaces/EntityMp.md)

The player or ped that was hit.

##### targetPlayer

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The player that was hit; `undefined` when a ped was hit.

##### weapon

`number`

The weapon's hash.

##### boneIndex

`number`

The bone that was hit: the hash of the bone's name, not a bone index (SixL has no index).
`0` when unknown.

##### damage

`number`

The damage of the hit, in health points, as the client reports it. The server decides the real
damage.

#### Returns

`void`

#### Remarks

Partial: raised after the hit report is already on its way to the server, so returning `true` from the
handler does not cancel it. Hits on vehicles and on entities of the game itself are not reported, and
`boneIndex` is a name hash, unlike RAGE MP's bone index.

#### Example

```ts
mp.events.add('outgoingDamage', (source, target, targetPlayer, weapon, bone, damage) => { });
```

***

### playerChat

> **playerChat**: (`text`) => `void`

The player sent a chat line from the built-in chat (a line that does not start with `/`).

#### Parameters

##### text

`string`

The line as typed, trimmed.

#### Returns

`void`

#### Remarks

Raised before the line goes to the server; it cannot be stopped. Not raised for a line dropped by the
chat's rate limit (5 lines in 3 seconds) or while the chat is off (`mp.gui.chat.activate(false)`).

#### Example

```ts
mp.events.add('playerChat', (text) => mp.console.logInfo(text));
```

***

### playerCommand

> **playerCommand**: (`command`) => `void`

The player sent a command from the built-in chat (a line that starts with `/`).

#### Parameters

##### command

`string`

The line without the leading slash, with its arguments: `/hello 1 2` gives `hello 1 2`.

#### Returns

`void`

#### Remarks

Raised before the line goes to the server's `playerCommand`; it cannot be stopped.

#### Example

```ts
mp.events.add('playerCommand', (command) => mp.console.logInfo(command));
```

***

### playerCreateWaypoint

> **playerCreateWaypoint**: (`position`) => `void`

The player set a waypoint on the map.

#### Parameters

##### position

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

Where the waypoint is.

#### Returns

`void`

#### Remarks

Partial: the game is asked about the waypoint once a second while a script has a handler for this event or `playerReachWaypoint`, so it comes up to a second late. Not yet confirmed in the game.

#### Example

```ts
mp.events.add('playerCreateWaypoint', (pos) => mp.console.logInfo('waypoint ' + pos.x));
```

***

### playerDeath

> **playerDeath**: (`player`, `reason`, `killer`) => `void`

The local player died.

#### Parameters

##### player

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The local player.

##### reason

`number`

The weapon hash of the last hit on the local player, when one came within 5 seconds before the death
(see `incomingDamage`); otherwise `0`.

##### killer

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The player who made that hit; `undefined` when there was no such hit, or when the hit came from a
ped, a vehicle or the world (a fall, an explosion).

#### Returns

`void`

#### Remarks

Partial: only the local player. A hit explains one death. Raised once per death.
Same name on the server: `playerDeath(player, reason, killer)`, raised for every player; its reason is the weapon
hash of a recent hit report and its killer the attacker, when the server has them.

#### Example

```ts
mp.events.add('playerDeath', (player) => mp.console.logInfo('dead'));
```

***

### playerEnterCheckpoint

> **playerEnterCheckpoint**: (`checkpoint`) => `void`

The local player came within a checkpoint's radius.

#### Parameters

##### checkpoint

[`CheckpointMp`](../../world-entities/interfaces/CheckpointMp.md)

The checkpoint (the server's or this client's own).

#### Returns

`void`

#### Remarks

Partial: decided each frame from the local player's position (a sphere of the checkpoint's radius), in its dimension. Not yet confirmed in the game.

#### Example

```ts
mp.events.add('playerEnterCheckpoint', (cp) => mp.console.logInfo('checkpoint ' + cp.id));
```

***

### playerEnterColshape

> **playerEnterColshape**: (`shape`) => `void`

The local player came into a colshape this client made.

#### Parameters

##### shape

[`ColshapeMp`](../../colshapes/interfaces/ColshapeMp.md)

The colshape.

#### Returns

`void`

#### Remarks

Partial: decided each frame from the local player's position, in the colshape's dimension; once per crossing. Not yet confirmed in the game.

#### Example

```ts
mp.events.add('playerEnterColshape', (shape) => mp.console.logInfo('in ' + shape.id));
```

***

### playerEnterVehicle

> **playerEnterVehicle**: (`vehicle`, `seat`) => `void`

The local player sat in a vehicle of the server.

#### Parameters

##### vehicle

[`VehicleMp`](../../vehicle/interfaces/VehicleMp.md)

The vehicle.

##### seat

`number`

The seat, 0 = driver (the core's seat index).

#### Returns

`void`

#### Remarks

Partial: only vehicles of the server are reported. A vehicle the server did not make has no entity here,
so no event is raised for it. Seat numbering follows the server's (0 = driver); RAGE MP's client numbering was
not checked. Raised again, after `playerLeaveVehicle`, when the player moves to another seat.
Same name on the server: `playerEnterVehicle(player, vehicle, seat)`, raised for every player, not only the local one,
and for every vehicle the server knows.

#### Example

```ts
mp.events.add('playerEnterVehicle', (vehicle, seat) => mp.console.logInfo('seat ' + seat));
```

***

### playerExitCheckpoint

> **playerExitCheckpoint**: (`checkpoint`) => `void`

The local player left a checkpoint's radius.

#### Parameters

##### checkpoint

[`CheckpointMp`](../../world-entities/interfaces/CheckpointMp.md)

The checkpoint.

#### Returns

`void`

#### Remarks

Partial: once per crossing; a destroyed checkpoint raises none. Not yet confirmed in the game.

#### Example

```ts
mp.events.add('playerExitCheckpoint', (cp) => mp.console.logInfo('left ' + cp.id));
```

***

### playerExitColshape

> **playerExitColshape**: (`shape`) => `void`

The local player left a colshape this client made.

#### Parameters

##### shape

[`ColshapeMp`](../../colshapes/interfaces/ColshapeMp.md)

The colshape.

#### Returns

`void`

#### Remarks

Partial: once per crossing; a destroyed colshape raises none. Not yet confirmed in the game.

#### Example

```ts
mp.events.add('playerExitColshape', (shape) => mp.console.logInfo('out of ' + shape.id));
```

***

### playerJoin

> **playerJoin**: (`player`) => `void`

A player became known to this client. Raised the first time a player comes into range, once until it quits.

#### Parameters

##### player

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The player.

#### Returns

`void`

#### Remarks

Partial: the client learns of a player only when it streams in, so this is not raised for a player who
joined the server out of range, and not for the local player. Raised before `entityStreamIn` for that player.
Same name on the server: `playerJoin(player)`, raised when the player connects, before its client is ready. The
client's event is about a player it has in range; the server's is about any connection.

#### Example

```ts
mp.events.add('playerJoin', (player) => mp.console.logInfo(player.name + ' joined'));
```

***

### playerLeaveVehicle

> **playerLeaveVehicle**: (`vehicle`, `seat`) => `void`

The local player left a seat of a vehicle of the server.

#### Parameters

##### vehicle

[`VehicleMp`](../../vehicle/interfaces/VehicleMp.md)

The vehicle.

##### seat

`number`

The seat the player had, 0 = driver.

#### Returns

`void`

#### Remarks

Partial: the same limits as `playerEnterVehicle` (server vehicles only, seat numbering unchecked against
RAGE MP). Also raised when the player moves to another seat, before the enter event for the new seat.

#### Example

```ts
mp.events.add('playerLeaveVehicle', (vehicle, seat) => mp.console.logInfo('left seat ' + seat));
```

***

### playerQuit

> **playerQuit**: (`player`) => `void`

A player left the server. Raised only for a player this client had in range, before its `entityStreamOut`.

#### Parameters

##### player

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The player; still readable in the handler.

#### Returns

`void`

#### Remarks

Partial: a player who left while out of range is not reported. RAGE MP's client handler gets the player
only, as here.
Same name on the server: `playerQuit(player, exitType, reason)`, raised for every player who leaves, with how the
connection ended. The client's event covers only the players it had in range.

#### Example

```ts
mp.events.add('playerQuit', (player) => mp.console.logInfo(player.name + ' left'));
```

***

### playerReachWaypoint

> **playerReachWaypoint**: (`player`) => `void`

The player reached the map's waypoint: it went away with the player near it.

#### Parameters

##### player

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The local player.

#### Returns

`void`

#### Remarks

Partial: raised when the waypoint is gone and the player is within 50 m of it (asked once a second while a script listens). Not yet confirmed in the game.

#### Example

```ts
mp.events.add('playerReachWaypoint', () => mp.console.logInfo('arrived'));
```

***

### playerReady

> **playerReady**: () => `void`

The local player is ready to play: the server has welcomed the client, and the save's load-in scene has finished.
Raised once per session.

#### Returns

`void`

#### Remarks

The moment is after the server's Welcome and after the end of the save's load-in scene, so the player's
position can be set from the handler (a teleport is safe here). Scripts are loaded before it, so handlers
registered at load time are in place. It takes no arguments, as in RAGE MP.
Same name on the server: `playerReady(player)`, raised when the client's PlayerReady packet arrives, which is
also after the load-in scene.

#### Example

```ts
mp.events.add('playerReady', () => mp.console.logInfo('ready'));
```

***

### playerSpawn

> **playerSpawn**: (`player`) => `void`

The local player is alive again after a death.

#### Parameters

##### player

[`PlayerMp`](../../player/interfaces/PlayerMp.md)

The local player.

#### Returns

`void`

#### Remarks

Partial: not raised for the first spawn of the session, nor for other players.
Same name on the server: `playerSpawn(player)`, raised for every player when its client is ready and after every
respawn the server makes.

#### Example

```ts
mp.events.add('playerSpawn', (player) => mp.console.logInfo('respawned'));
```

***

### playerWeaponShot

> **playerWeaponShot**: (`targetPosition`, `targetEntity?`) => `void`

The local player fired a weapon. One event per shot.

#### Parameters

##### targetPosition

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

The point the weapon was aimed at, in world coordinates (metres), from the frame the shot
was counted in.

##### targetEntity?

[`EntityMp`](../../entity/interfaces/EntityMp.md)

The entity aimed at: always `undefined` here, the client does not know it.

#### Returns

`void`

#### Remarks

Partial: `targetEntity` is never given; the aim point is the aim of the frame in which the shot was
counted. A jump of more than 64 in the shot counter within one frame is taken as a reset, and those shots raise
nothing.

#### Example

```ts
mp.events.add('playerWeaponShot', (targetPosition) => mp.console.logInfo(targetPosition.x + ' ' + targetPosition.y));
```

***

### render

> **render**: () => `void`

Every frame of the game. The handler runs once per frame, after the frame's snapshot (the local player's
position and camera, the streamed players) is applied.

#### Returns

`void`

#### Remarks

Partial: RAGE MP passes the list of nametags (`[player, x, y, z]` per player) to the handler. SixL passes
no argument: that list is not computed. Keep the work per call small: the handler runs on every frame.

#### Example

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

***

### uncaughtException

> **uncaughtException**: (`error`) => `void`

A script threw an error that was not caught. The error is logged; the runtime keeps running.

#### Parameters

##### error

`any`

The thrown value. Usually an `Error`; any other thrown value is passed as it is.

#### Returns

`void`

#### Example

```ts
mp.events.add('uncaughtException', (error) => mp.console.logError(String(error)));
```

***

### unhandledRejection

> **unhandledRejection**: (`promise`, `error`) => `void`

A promise was rejected and nothing handled the rejection. The reason is logged; the runtime keeps running.

#### Parameters

##### promise

`Promise`\<`any`\>

The rejected promise.

##### error

`any`

The rejection reason. Usually an `Error`; any other value is passed as it is.

#### Returns

`void`

#### Example

```ts
mp.events.add('unhandledRejection', (promise, error) => mp.console.logError(String(error)));
```
