> 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/chess/table-item.md).

# Table item

Players carry a chess table as an inventory item and put it up themselves, with a see-through preview. Picked up again with ox\_target or a command.

With the table item, players put up chess tables themselves. The item is `chess_table`. Used from the inventory, a see-through table and its two chairs follow where the player looks; they turn it, put it up where it fits, and from then on it is a table like any other: everyone can play at it, and it stays over restarts. When they are done, they pick it up again and have the item back.

The script registers the item as usable with whichever framework runs (`Config.Item.Framework`, `'auto'` by default: Qbox, then QBCore, then ESX, else ox\_inventory on its own). The item itself has to be in the inventory's item list.

## Adding the item

{% tabs %}
{% tab title="ESX" %}
Run `install/esx_items.sql` on your database. It adds the `chess_table` row (weight 8).
{% endtab %}

{% tab title="QBCore" %}
Add to `qb-core/shared/items.lua`:

```lua
chess_table = { name = 'chess_table', label = 'Chess Table', weight = 8000, type = 'item',
    image = 'chess_table.png', unique = true, useable = true, shouldClose = true,
    description = 'Put it up and play' },
```

{% endtab %}

{% tab title="ox\_inventory / Qbox" %}
Add to `ox_inventory/data/items.lua`:

```lua
['chess_table'] = { label = 'Chess Table', weight = 8000, stack = false, close = true,
    server = { export = 'chess.useItem' } },
```

On Qbox, ESX or QBCore the `server` line can be left out: the framework hands the use on to the item the script registered. With ox\_inventory on its own it is needed.
{% endtab %}

{% tab title="Another inventory" %}
Set `Config.Item.Framework = false` and have your inventory call this on the server when the item is used:

```lua
exports.chess:placeTable(source, 'chess_table')
```

Taking the item out of the inventory and giving it back is then left to your own code; see [Exports and events](/organized-chaos-docs/chess/exports-and-events.md).
{% endtab %}
{% endtabs %}

## Putting a table up

| Key                                           | What it does      |
| --------------------------------------------- | ----------------- |
| Mouse wheel, or the left and right arrow keys | Turn the table    |
| **E**                                         | Put it up         |
| Backspace, Esc or the right mouse button      | Put it away again |

The table follows where the player looks, up to `Config.Item.Place.Distance` (4 m) away. A ring on the ground shows whether it fits: green where it can stand, red where it cannot. It cannot stand

* on ground that is not level enough under the table and the chairs (`Radius`, `Slope`),
* in water, or with a car in the way,
* closer than `Spacing` (3.5 m) to the middle of any other table.

The table starts out facing the way the player does, so they stand on White's side. On **E** the player works on it for a moment (`Animation`, `Time`) while it becomes solid, and then it stands. A fall, a car or death stops it, and the item stays where it was.

The table is kept in `tables.json` like those of `/chess_place`, together with the item it came from and a token of the player who put it up (a hash of their licence; the licence itself is not sent to anyone).

## Picking it up

With ox\_target, aiming at such a table offers **Pick up the table**. Without ox\_target, `/chess_pickup` takes down the nearest such table in reach. The player works on it for a moment, the table is gone, and the item is back in their inventory.

* With `OwnOnly = true` (the default) only the player who put it up can pick it up.
* Nobody may be sitting at it.
* Not into a full inventory.
* Tables of `Config.Tables` and of `/chess_place` are no item and cannot be picked up.

`/chess_remove` takes these tables away too, for admins; the item is then not given back.

## One table, or a licence

`MaxPerPlayer` (1 by default) is how many tables a player may have up at once; `0` is any number. With `Remove = false` the item stays in the inventory when the table is put up, as a licence to put up tables, and picking one up only takes it down.

## Settings

All in `Config.Item`, see also [Configuration](/organized-chaos-docs/chess/configuration.md#table-item).

| Option                            | Default               | Meaning                                                                                                     |
| --------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------- |
| `Enabled`                         | `true`                | `false`: no item                                                                                            |
| `Name`                            | `'chess_table'`       | The item's name                                                                                             |
| `Framework`                       | `'auto'`              | `'auto'`, `'esx'`, `'qb'`, `'qbx'`, `'ox'`, or `false` for an inventory of your own that calls `placeTable` |
| `Remove`                          | `true`                | The item leaves the inventory while the table stands. `false`: it stays, as a licence                       |
| `MaxPerPlayer`                    | `1`                   | Tables a player may have up at once. `0` for any number                                                     |
| `Place.Distance`                  | `4.0`                 | Metres from the player the table may stand                                                                  |
| `Place.Spacing`                   | `3.5`                 | Metres it has to keep from the middle of any other table                                                    |
| `Place.Radius`                    | `1.1`                 | The ground this far around has to be free and level enough                                                  |
| `Place.Slope`                     | `0.3`                 | Metres the ground may rise or fall over that radius                                                         |
| `Place.Turn`                      | `7.5`                 | Degrees one click of the mouse wheel turns it                                                               |
| `Place.Animation`                 | `mini@repair`         | What the player does while putting it up, `{ Dict, Clip }`, or `false` for at once                          |
| `Place.Time`                      | `2500`                | Milliseconds that takes                                                                                     |
| `PickUp.Enabled`                  | `true`                | `false`: tables cannot be picked up                                                                         |
| `PickUp.Target`                   | `'ox_target'`         | `false`: only the command                                                                                   |
| `PickUp.Command`                  | `'chess_pickup'`      | The command, or `false` for none                                                                            |
| `PickUp.Icon`                     | `'fa-solid fa-hand'`  | The option's icon in ox\_target                                                                             |
| `PickUp.Distance`                 | `2.5`                 | Metres from the table the option shows                                                                      |
| `PickUp.OwnOnly`                  | `true`                | Only the player who put a table up can pick it up                                                           |
| `PickUp.Animation`, `PickUp.Time` | `mini@repair`, `1500` | What the player does while taking it down, and for how long                                                 |

The texts are in `locales.lua`: `help_place`, `target_pick_up`, `table_picked_up` and the `item_...` messages.
