> For the complete documentation index, see [llms.txt](https://k0ssek-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://k0ssek-scripts.gitbook.io/docs/scripts/squash/events.md).

# Events

The server event fired when a match or a practice session ends.

## kossek\_squash:matchFinished

A server event, fired when a match or a practice session ends. Use it to log results, pay rewards or feed your own ranking.

```lua
AddEventHandler('kossek_squash:matchFinished', function(summary)
    if summary.mode ~= 'match' or not summary.winner then return end

    print(('%s: %s won (%s)'):format(summary.court, GetPlayerName(summary.winner), summary.reason))
end)
```

### summary

| Field         | Type          | Description                                                                                                    |
| ------------- | ------------- | -------------------------------------------------------------------------------------------------------------- |
| `court`       | string        | The `id` of the court.                                                                                         |
| `mode`        | string        | `'match'` or `'solo'` (practice).                                                                              |
| `players`     | number\[]     | Server ids, the lobby owner first. Practice has one entry.                                                     |
| `names`       | string\[]     | Names in the same order.                                                                                       |
| `identifiers` | string\[]     | The identifiers the stats use, in the same order. For a player who had none it is their server id as a string. |
| `winner`      | number or nil | Server id of the winner. `nil` for practice.                                                                   |
| `scores`      | number\[]     | Points in the last game, in the same order.                                                                    |
| `games`       | number\[]     | Games won, in the same order.                                                                                  |
| `reason`      | string        | How it ended, see below.                                                                                       |
| `best`        | number        | Longest rally of a practice session.                                                                           |
| `stake`       | number        | What each player paid. `0` is none.                                                                            |

`players`, `names` and `identifiers` are as they were when each player joined, so they are still there for a player who has disconnected. The pot has been paid out by the time the event fires.

### reason

How the last rally ended:

| Value           | Meaning                                             |
| --------------- | --------------------------------------------------- |
| `double`        | The ball bounced twice.                             |
| `down`          | Into the tin.                                       |
| `out`           | Out.                                                |
| `not_up`        | The ball did not reach the front wall.              |
| `fault`         | Service fault.                                      |
| `serve_timeout` | The server ran out of time to serve.                |
| `stroke`        | Stroke awarded by the referee.                      |
| `no_let`        | Appeal refused.                                     |
| `self_created`  | Appeal refused: the player caused the interference. |
| `turning`       | The ball hit the opponent after the striker turned. |
| `body`          | The ball hit a player.                              |

Or why the match stopped:

| Value        | Meaning                                                       |
| ------------ | ------------------------------------------------------------- |
| `left`       | A player left with the leave key or `/squashleave`.           |
| `left_court` | A player stayed off the court for too long.                   |
| `dropped`    | A player disconnected or switched character.                  |
| `idle`       | Practice ended after no serve for `Config.Match.idleTimeout`. |

{% hint style="info" %}
The script has no exports. Need something for your own resource? Ask on our [Discord](https://discord.gg/eZN5ycvPVs).
{% endhint %}
