> For the complete documentation index, see [llms.txt](https://docs.cuxial.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cuxial.com/scripts/leisure/cuxial-domino/developers.md).

# Exports & events

Public API of Cuxial Domino: server exports to manage tables and events to follow matches.

Create and delete tables, find out where a player is seated and react to rounds, matches and bets from your own resources. The whole API is server side.

## Server exports

### GetTables

Returns every table.

```lua
local tables = exports.cuxial_domino:GetTables()
```

**Returns:** `table[]`, sorted by `id`. Each entry is a table summary:

| Field              | Type          | Description                                            |
| ------------------ | ------------- | ------------------------------------------------------ |
| `id`               | number        | Table id.                                              |
| `name`             | string \| nil | Name given to the table.                               |
| `pos`              | table         | `{ x, y, z }`.                                         |
| `heading`          | number        | Heading of the table.                                  |
| `maxPlayers`       | number        | `1` to `4`.                                            |
| `teamMode`         | boolean       | `true` on 4 player team tables.                        |
| `tableModel`       | string        | Model of the table.                                    |
| `scoreMode`        | string        | `'classic'` or `'fives'`.                              |
| `betMin`, `betMax` | number \| nil | Bet limits of the table. `nil` uses the global limits. |
| `seated`           | number        | Players seated right now.                              |
| `inGame`           | boolean       | `true` while a round is being played.                  |

```lua
for _, t in ipairs(exports.cuxial_domino:GetTables()) do
    print(t.id, t.name, t.seated, t.inGame)
end
```

### GetTable

Returns the summary of one table.

```lua
local tbl = exports.cuxial_domino:GetTable(id)
```

| Parameter | Type   | Description |
| --------- | ------ | ----------- |
| `id`      | number | Table id.   |

**Returns:** a table summary, or `nil` when the table does not exist.

```lua
local tbl = exports.cuxial_domino:GetTable(3)
if tbl and not tbl.inGame then print('Table 3 is free') end
```

### CreateTable

Creates a table and saves it in the database.

```lua
local id, err = exports.cuxial_domino:CreateTable(data)
```

| Parameter                    | Type    | Description                                                                                                             |
| ---------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `data.pos`                   | table   | `{ x, y, z }`. Required. Use the coordinates of a player standing on the spot: the table is placed one metre below `z`. |
| `data.heading`               | number  | Heading. `0.0` by default.                                                                                              |
| `data.maxPlayers`            | number  | `1` to `4`. `4` by default.                                                                                             |
| `data.teamMode`              | boolean | Teams. Only applies with `maxPlayers = 4`.                                                                              |
| `data.style`                 | string  | `'luxury'`, `'wood'` or `'classic'`. `'luxury'` by default.                                                             |
| `data.tableModel`            | string  | A model name. When given, it replaces `style`.                                                                          |
| `data.scoreMode`             | string  | `'classic'` or `'fives'`. `'classic'` by default.                                                                       |
| `data.name`                  | string  | Name of the table. Cut at 60 characters.                                                                                |
| `data.betMin`, `data.betMax` | number  | Bet limits. Both are needed; with only one, the table uses the global limits.                                           |

**Returns:** the `id` of the new table, or `nil` and a reason. The reason is `'err_too_close'` when another table is closer than `table.minDistanceBetween`, and `'err_table_not_found'` when `data` or `data.pos` is missing.

```lua
local id, err = exports.cuxial_domino:CreateTable({
    pos = { x = 195.0, y = -934.0, z = 30.7 },
    heading = 90.0,
    maxPlayers = 4,
    teamMode = true,
    style = 'wood',
    scoreMode = 'classic',
    name = 'Main square',
    betMin = 100,
    betMax = 5000,
})
if not id then print('Could not create the table: ' .. tostring(err)) end
```

### DeleteTable

Deletes a table. Seated players are stood up and any bet already charged is returned.

```lua
local ok = exports.cuxial_domino:DeleteTable(id)
```

| Parameter | Type   | Description |
| --------- | ------ | ----------- |
| `id`      | number | Table id.   |

**Returns:** `boolean`. `false` when the table does not exist.

```lua
exports.cuxial_domino:DeleteTable(3)
```

### GetPlayerTable

Returns where a player is seated.

```lua
local tableId, seat = exports.cuxial_domino:GetPlayerTable(source)
```

| Parameter | Type   | Description              |
| --------- | ------ | ------------------------ |
| `source`  | number | Server id of the player. |

**Returns:** the table id and the seat number (`1` to `4`), or `nil` when the player is not seated.

```lua
local tableId, seat = exports.cuxial_domino:GetPlayerTable(source)
if tableId then print(('Seated at table %d, seat %d'):format(tableId, seat)) end
```

### IsSeated

Tells whether a player is seated at a table.

```lua
local seated = exports.cuxial_domino:IsSeated(source)
```

**Returns:** `boolean`.

```lua
if exports.cuxial_domino:IsSeated(source) then return end
```

### on

Registers a function for one of the events listed below.

```lua
local handle = exports.cuxial_domino:on(event, fn)
```

| Parameter | Type     | Description                                               |
| --------- | -------- | --------------------------------------------------------- |
| `event`   | string   | Event name without prefix, for example `'matchFinished'`. |
| `fn`      | function | Receives the payload of the event.                        |

**Returns:** a numeric handle, or `nil` when the arguments are not valid.

```lua
local handle = exports.cuxial_domino:on('matchFinished', function(payload)
    print(('Table %d: seat %s won'):format(payload.tableId, tostring(payload.winnerSeat)))
end)
```

### off

Removes a function registered with `on`.

```lua
local removed = exports.cuxial_domino:off(handle)
```

**Returns:** `boolean`.

```lua
exports.cuxial_domino:off(handle)
```

## Server events

Every event is also triggered as a local server event named `cuxial_domino:<event>`. This is the simplest way to listen:

```lua
AddEventHandler('cuxial_domino:betPaid', function(payload)
    print(('Table %d paid a pot of $%d'):format(payload.tableId, payload.total))
end)
```

| Event           | Payload                             | When                                                                                                                    |
| --------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `tableCreated`  | `{ id, table, by }`                 | A table is created. `table` is its summary. `by` is the server id of the staff member, or `nil` when created by export. |
| `tableRemoved`  | `{ id, by }`                        | A table is deleted.                                                                                                     |
| `playerSeated`  | `{ tableId, seat, source }`         | A player sits down.                                                                                                     |
| `playerLeft`    | `{ tableId, seat, source, reason }` | A player leaves the table.                                                                                              |
| `roundStarted`  | `{ tableId, seats, scoreMode }`     | A round starts. `seats` is the list of seats playing, AI included.                                                      |
| `tilePlayed`    | `{ tableId, seat, tile, side }`     | A tile is placed, by a player or by the AI. `tile` is `{ a, b }`.                                                       |
| `bonus`         | `{ tableId, seat, points, kind }`   | A classic match bonus is scored.                                                                                        |
| `roundEnded`    | `{ tableId, winnerSeat, reason }`   | A round ends. `winnerSeat` can be `nil`.                                                                                |
| `matchFinished` | `{ tableId, winnerSeat, scores }`   | A match ends. `scores` maps each seat to its points.                                                                    |
| `betPaid`       | `{ tableId, winnerSeat, total }`    | The pot is paid to the winner. `total` is the whole pot.                                                                |

### Values

| Field               | Values                                                                                                                                                                                                    |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `playerLeft.reason` | `'left'` (by choice), `'disconnected'`, `'inactive'` (turns ran out)                                                                                                                                      |
| `tilePlayed.side`   | `'start'`, `'left'`, `'right'`; in All Fives also `'top'` and `'bottom'`                                                                                                                                  |
| `bonus.kind`        | `'round_pass'`, `'opening_pass'`, `'capicua'`                                                                                                                                                             |
| `roundEnded.reason` | `'domino'` (a player went out), `'blocked'`, `'fives_target'` and `'bonus_target'` (target reached during the round), `'player_left'` (round cancelled), `'last_standing'`, `'solo_left'`, `'no_players'` |

{% hint style="info" %}
Seats are numbered `1` to `4`. 2 player tables use seats `1` and `3`. On 1 player tables the player is seat `1` and the AI is seat `2`. In team tables, seats `1` and `3` play against `2` and `4`.
{% endhint %}

## Client

Cuxial Domino has no client exports or public client events.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cuxial.com/scripts/leisure/cuxial-domino/developers.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
