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

# Exports and events

What other resources can ask Quicks, and the events it sends them.

Other resources can ask Quicks about its tables and players, read a player's record and the leaderboard, make a player stand up, put up or take away tables, and let a player put up a table as the table item does. Two server events say when a game starts and ends.

The exports are in two files that are left open, not encrypted: `server/exports.lua` and `client/exports.lua`. You can read them, change them and add exports of your own. Keep your version of them when you update the resource.

## Server exports

| Export                      | Returns                     | What it does                                                                                                                                                                                                                                                                                                                  |
| --------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `getTables()`               | a list of tables            | Every table, see below                                                                                                                                                                                                                                                                                                        |
| `getTable(id)`              | a table, or `nil`           | One table by its id                                                                                                                                                                                                                                                                                                           |
| `getPlayerSeat(source)`     | `{ table, seat }`, or `nil` | Where a player sits                                                                                                                                                                                                                                                                                                           |
| `isSeated(source)`          | `true` or `false`           | Whether a player sits at a table, in the lobby or in a game                                                                                                                                                                                                                                                                   |
| `standUp(source)`           | `true` or `false`           | Makes a player stand up, without the confirmation they would be asked for. In a running game that counts as leaving it. Returns whether they sat                                                                                                                                                                              |
| `addTable(coords, heading)` | the new id, or `nil`        | Puts up a table and keeps it over restarts, like `/quicks_place`. `coords` is the centre of the table on the ground                                                                                                                                                                                                           |
| `removeTable(id)`           | `true` or `false`           | Takes away a table that was put up in game or with `addTable`. Players sitting there stand up. Tables from `Config.Tables` stay                                                                                                                                                                                               |
| `getStats(source, cb)`      | nothing                     | Hands a player's record to your function, see below                                                                                                                                                                                                                                                                           |
| `getLeaderboard()`          | a list of records           | The leaderboard as the board shows it, best first. Empty without `oxmysql`                                                                                                                                                                                                                                                    |
| `placeTable(source, item)`  | `true` or `false`           | Lets the player choose a spot and put up a table, as the table item does. `item` is the item's name: it is taken from the inventory (with `Config.Item.Remove`) and given back on picking the table up. Without `item` the table cannot be picked up. `false` when the player cannot right now, for example at `MaxPerPlayer` |
| `useItem`                   |                             | For ox\_inventory: an item with `server = { export = 'quicks.useItem' }` lets the player put up a table. See [Table item](/organized-chaos-docs/quicks/table-item.md)                                                                                                                                                         |

A table looks like this:

```lua
{
    id = 'c1',                -- 'c1', 'c2' ... from Config.Tables; 'p1', 'p2' ... put up in game
    coords = vector3(201.65, -938.47, 30.69),
    heading = 144.0,
    placed = false,           -- true for a table put up in game
    item = false,             -- the item's name for a table put up with the table item
    owner = false,            -- for such a table: a token of who put it up (a hash of their licence)
    state = 'playing',        -- 'playing' while a game runs, 'lobby' before the first one
    players = {
        { seat = 1, name = 'PlayerA', source = 12, computer = false },
        { seat = 2, name = 'Computer', source = false, computer = true },
    },
}
```

`source` is the player's server id. It is `false` for a computer player, and for a player whose connection is lost and whose seat is being kept.

The record comes from the database, so it is handed to a function of yours:

```lua
exports.quicks:getStats(source, function(stats)
    if not stats then return end      -- no record yet, or oxmysql is not running
    print(stats.name, stats.games, stats.wins, stats.best, stats.points, stats.locks)
end)
```

| Field    | Meaning                           |
| -------- | --------------------------------- |
| `name`   | The name the record is kept under |
| `games`  | Games played to the end           |
| `wins`   | Games won against other people    |
| `best`   | The best game                     |
| `points` | All points together               |
| `locks`  | Rows locked                       |

## Client exports

| Export          | Returns                     | What it does                                                                                                                                                |
| --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isSeated()`    | `true` or `false`           | Whether this player sits at a table                                                                                                                         |
| `getSeat()`     | `{ table, seat }`, or `nil` | Where this player sits                                                                                                                                      |
| `isWatching()`  | `true` or `false`           | Whether this player is watching a game from beside a table                                                                                                  |
| `isBoardOpen()` | `true` or `false`           | Whether the board is on the screen, for a player or a watcher                                                                                               |
| `standUp()`     | `true` or `false`           | Stands up without the confirmation. Returns whether the player sat                                                                                          |
| `isPlacing()`   | `true` or `false`           | Whether this player is choosing a spot for a table right now                                                                                                |
| `canPickUp(id)` | `true` or `false`           | Whether this player can pick up that table right now: put up with the item, by them if `OwnOnly`, nobody sitting there. For a target script's `canInteract` |
| `pickUp(id)`    | `true` or `false`           | Picks up that table, for a target script other than ox\_target. `false` when it cannot be picked up                                                         |

`id` is a table's id as in `getTables`.

```lua
-- In a client script of another resource: no inventory while the board is open
if exports.quicks:isBoardOpen() then return end
```

## Events

Both are sent on the server, to other server scripts. Listen with `AddEventHandler`, not `RegisterNetEvent`, so that no client can send them.

```lua
AddEventHandler('quicks:gameStarted', function(tableId, players, pot)
    -- players: as in getTables. pot: what is played for, 0 without a stake.
end)

AddEventHandler('quicks:gameEnded', function(tableId, result)
    -- result.winners   the seats that won; several after a tie, none when nobody did
    -- result.reason    how the game ended, as a short word
    -- result.pot       what was played for, 0 without a stake
    -- result.players   as in getTables
end)
```
