> For the complete documentation index, see [llms.txt](https://doc.var-fivem.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.var-fivem.com/chess/configuration/events.md).

# Events

{% hint style="info" %}
All three are server-side, server-to-server events. Integrators react with `AddEventHandler` in a server script.
{% endhint %}

### var\_chess:server:matchStarted

Fires when a match starts (status becomes `playing`).

```lua
-- payload: { id, white, black, bet = { white, black }, ai }
-- white / black: seat server id (number), or nil when that seat is the AI.  ai: boolean.
AddEventHandler('var_chess:server:matchStarted', function(data)
    print(('chess started at table %s, ai=%s'):format(data.id, tostring(data.ai)))
end)
```

### var\_chess:server:matchEnded

Fires when a match ends (checkmate, resign, draw or forced).

```lua
-- payload: { id, winner = 'white' | 'black' | nil, reason, white, black, pot }
-- reason: 'checkmate' | 'resign' | 'stalemate' | 'fifty' | 'forced'.  pot: total staked.
AddEventHandler('var_chess:server:matchEnded', function(data)
    print(('chess ended at table %s, winner=%s pot=%s'):format(data.id, tostring(data.winner), data.pot))
end)
```

### var\_chess:server:move

Fires after each validated move is applied.

```lua
-- payload: { id, color = 'white' | 'black', from, to, capture }
-- from / to: algebraic squares ('e2', 'e4').  capture: captured piece code ('bp') or nil.
AddEventHandler('var_chess:server:move', function(data)
    print(('table %s: %s %s-%s'):format(data.id, data.color, data.from, data.to))
end)
```
