> For the complete documentation index, see [llms.txt](https://rtx-dev.gitbook.io/rtxdev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rtx-dev.gitbook.io/rtxdev/billiard.md). Agents can also search and read this documentation through its [MCP server](https://rtx-dev.gitbook.io/rtxdev/~gitbook/mcp).

# Billiard

Documentation for RTX Billiard, the FiveM Billiard & Pool Script for ESX, QBCore and QBox: installation, configuration, commands, exports and FAQ.

{% embed url="<https://www.youtube.com/watch?v=jfeD6AuhZ0w>" %}

## Purchase

[Purchase this resource](https://rtx.tebex.io/package/6158989)

**RTX Billiard** is real pool for FiveM. Balls roll, spin and bounce off the cushions like on a real table, every player around the table sees the same game, and matches can be played for money. Play on any pool table that already stands in your map, on tables placed with the in-game table creator, or on tables written in the config.

## Requirements

| Resource                              | Required                                                               |
| ------------------------------------- | ---------------------------------------------------------------------- |
| `rtx_billiard`                        | Yes - the script, the table models and the animation are all inside it |
| `ox_target` / `qb-target` / `qtarget` | No - only if you want target instead of the key prompt                 |

No database, no items and no other resource is needed.

## Installation

{% stepper %}
{% step %}

## Add the resource

Place `rtx_billiard` into your resources folder and add it to your `server.cfg`:

```
ensure rtx_billiard
```

{% hint style="warning" %}
Keep the `stream` folder and the `data` folder. The `stream` folder holds the RTX tables and the cue animation, the `data` folder is where the tables placed in game are saved.
{% endhint %}
{% endstep %}

{% step %}

## Framework

Open `config.lua`, section 1, and set your framework:

```lua
Config.Framework = "esx" -- "esx", "qbcore" or "standalone"

Config.MoneyAccount = "money" -- "money" (cash) or "bank"
```

| Framework          | Value          |
| ------------------ | -------------- |
| ESX                | `"esx"`        |
| QBCore / QBox      | `"qbcore"`     |
| Standalone / other | `"standalone"` |

{% hint style="info" %}
In standalone mode every table is free and there is no money on a match, unless you fill in the money functions in `server/other.lua`. The ESX and QBCore parts in the same file show how.
{% endhint %}
{% endstep %}

{% step %}

## Admins

The table creator and the reset command belong to whoever your `server.cfg` gives `billiard.admin` to:

```
add_ace group.admin billiard.admin allow
```

ESX groups, QBCore permissions and single players by identifier can be allowed too, see [Permissions](#permissions).
{% endstep %}

{% step %}

## Database

None. There is nothing to import. Tables placed in game are saved in `data/tables.json`.
{% endstep %}
{% endstepper %}

## Tables

A table gets into the game in one of three ways, and they all play exactly the same.

### Tables already in your map

Every GTA pool table that stands in the map - GTA bars, MLOs, houses - is found automatically and can be played. Nothing to place.

```lua
Config.WorldTables = true -- false turns it off
```

### The table creator

Place tables in game with `/billiardcreator`. See [Table Creator](#table-creator).

### Config.Tables

For those who like to write tables by hand, in `config.lua`, section 5:

```lua
Config.Tables = {
	{
		label = "Beach Bar", -- Name shown in the table menu
		type = 1, -- 1 to 6, see the table types
		coords = vector3(-1575.67, -1017.76, 12.01), -- Where the table stands, on the floor
		heading = 0.0, -- Which way the table points
		price = 0, -- What each player pays to start a match here. 0 = free
		manage = {
			enabled = false, -- true = the players below can lock the table and set its price
			job = "", -- Job that can manage the table, "" = no job
			grade = 0, -- Lowest grade of that job that can manage it
			groups = {}, -- ESX groups / QBCore permissions that can manage it too
			ace = "", -- Players with this ACE can manage it too
			identifiers = {}, -- Single players that can manage it too
			locked = false, -- true = the table starts locked
			setprice = true, -- true = they can change the entry price
			maxprice = 5000, -- Highest entry price they can set
			society = true -- true = the entry price goes to the job's society account
		}
	}
}
```

### Table types

| Type | Table                    |
| ---- | ------------------------ |
| `1`  | GTA table, red cloth     |
| `2`  | GTA table, green cloth   |
| `3`  | RTX table 1, blue cloth  |
| `4`  | RTX table 1, green cloth |
| `5`  | RTX table 2, green cloth |
| `6`  | RTX table 2, blue cloth  |

## Table Creator

```
/billiardcreator
```

Opens the list of every table placed with the creator, nearest first. From there you can place a new table, edit, move, teleport to or delete any of them.

### Placing a table

The table follows where you look.

| Key                          | Action                               |
| ---------------------------- | ------------------------------------ |
| `MOUSE`                      | Where the table goes                 |
| `SCROLL` / `Q` / `E`         | Rotate - hold `SHIFT` for fine steps |
| `ARROW UP` / `ARROW DOWN`    | Raise or lower the table             |
| `ARROW LEFT` / `ARROW RIGHT` | Switch the table type                |
| `LMB` / `ENTER`              | Put the table down                   |
| `BACKSPACE`                  | Cancel                               |

The table stays where you put it while you fill in its name, table type, entry price and management. Save it and it appears for every player straight away, no restart.

### Where it is saved

`data/tables.json` - no database. Back the file up with your server and keep it when you update the resource.

{% hint style="warning" %}
Updating the resource without the `data` folder removes every table placed with the creator.
{% endhint %}

## Managed Tables

Turn on `manage` for a table, in the creator or in `Config.Tables`, and the players you allow can manage it right at the table. They press `E` or `G` there and the table menu has a **Management** part:

* **Lock and unlock the table** - nobody starts a match on a locked table
* **Set the entry price** - up to the highest price you allow

### Who can manage a table

Any mix of:

| Option                          | Example                                                  |
| ------------------------------- | -------------------------------------------------------- |
| A job, from a grade             | `job = "bahama", grade = 2`                              |
| ESX groups / QBCore permissions | `groups = {"admin", "superadmin"}`                       |
| An ACE                          | `ace = "billiard.bahama"`                                |
| Single players                  | `identifiers = {"license:abc123", "discord:1234567890"}` |

Identifiers can be the ESX identifier, the QBCore citizenid, `license:`, `steam:`, `discord:` - or just the part after the colon.

### Society money

With a job set and `society = true`, the entry price goes straight to that job's society account:

* **ESX** - `esx_addonaccount`
* **QBCore** - `qb-banking` or `qb-management`

This lives in `AddSocietyMoneyRTX` in `server/other.lua`, open source.

### After a restart

The locked state and the price set on a managed table are remembered after a restart.

```lua
Config.JobTables = {
	savestate = true
}
```

## Game Modes & Rules

```lua
Config.Modes = {
	["8ball"] = true, -- Two players, solids and stripes, the 8 last
	["9ball"] = true, -- Two players, always hit the lowest ball first, the 9 wins
	["practice"] = true -- One player alone, no rules, re-rack whenever you like
}
```

### Fouls

* The cue ball goes into a pocket
* The wrong ball is hit first
* No ball is hit
* No ball reaches a cushion after the hit
* Illegal break
* The shot clock runs out

A foul gives the other player **ball in hand**. A scratch on the break gives ball in hand behind the head string.

### Rules

```lua
Config.Rules = {
	["8ball"] = {
		breakrails = 4, -- On the break at least this many balls have to reach a cushion, or a ball has to drop
		eightonbreak = "spot", -- The 8 on the break: "spot" puts it back, "win" wins the match
		scratchbreak = "kitchen" -- Cue ball in on the break: "kitchen" = ball in hand behind the head string, "table" = anywhere
	},
	["9ball"] = {
		breakrails = 4,
		ninebreakwins = true -- The 9 on a legal break wins the match
	}
}
```

### Matches

```lua
Config.Match = {
	breaker = "random", -- Who breaks: "host" or "random"
	shotclock = 60, -- Seconds for a shot, running out is a foul. 0 = no limit
	lobbytime = 180, -- Seconds a match waits for a second player
	finishdelay = 8, -- Seconds the result stays up before the table is free again
	leaveondeath = true, -- A player who dies or goes down gives up his match
	walkaround = true -- The player can walk around the table between his shots
}
```

A player who walks away from the table, leaves the city or goes down gives the match up.

## Money & Stakes

```lua
Config.Price = {
	default = 0 -- Price on tables without their own price (GTA tables in the map, creator tables left empty)
}

Config.Stakes = {
	enabled = true, -- The player who opens a match can put money on it, the second player pays the same to join
	min = 0,
	max = 50000,
	default = 0,
	fee = 0 -- Percent the house keeps from the pot. 0 = the winner takes everything
}
```

The winner takes the pot. Stakes are paid back automatically when a match is cancelled.

## Playing

Walk up to a table and press `E`. Pick a game, put money on it if you like and rack them up. A second player walks up to the same table and presses `E` to join. When it is your turn, walk to the table and press `E` to take your shot.

| Key          | Action                                                                 |
| ------------ | ---------------------------------------------------------------------- |
| `MOUSE`      | Aim - hold `SHIFT` for fine aim                                        |
| `LMB`        | Hold, pull the mouse back for power and push to shoot                  |
| `SPACE`      | Hold to charge the power with the keyboard, let go to shoot            |
| `ARROW KEYS` | Where the cue hits the cue ball: follow, draw and side spin            |
| `R`          | Centre the tip                                                         |
| `C`          | Cue view / view from above                                             |
| `SCROLL`     | Zoom - in free style, scroll in for the view right behind the cue ball |
| `BACKSPACE`  | Back                                                                   |
| `G`          | Match menu: rules, re-rack in practice, leave the table                |

**Ball in hand** - move the cue ball with the mouse or the arrow keys and press `LMB` to put it down.

{% hint style="info" %}
`E` and `G` are key mappings. Every player can rebind them in **Settings > Key Bindings > FiveM**.
{% endhint %}

## Aiming & Camera

### Aiming style

```lua
Config.Aim = {
	style = "both",
	guide = "full",
	animation = true
}
```

| `style`    | What it does                                                                                         |
| ---------- | ---------------------------------------------------------------------------------------------------- |
| `"free"`   | Walk around the table and take the shot right where you stand, with the normal game camera           |
| `"camera"` | Press `E` anywhere at the table, the player is put behind the cue ball and the cue camera takes over |
| `"both"`   | Free style next to the cue ball, the cue camera from further away                                    |

| `guide`   | What it shows                                                                |
| --------- | ---------------------------------------------------------------------------- |
| `"full"`  | Line to the first ball, the ghost ball and where both balls go after the hit |
| `"ghost"` | Line to the first ball and the ghost ball only                               |
| `"none"`  | Nothing at all, like on a real table                                         |

`animation = false` keeps the player standing with the cue at his hip instead of leaning over the table.

### Camera

```lua
Config.Camera = {
	aftershot = "top" -- "top" from above, "follow" behind the cue ball, "none" the normal game camera
}
```

Field of view, distance, zoom range and height of both views are in the same block.

## Interface & Interaction

```lua
Config.InterfaceColor = "#ff66ff" -- Accent colour of the whole interface
Config.Currency = "$"
Config.InteractionSystem = 1
Config.PromptPosition = "right" -- "right", "center" or "left"
Config.Notifications = "rtx"
```

| `InteractionSystem` | Prompt                                         |
| ------------------- | ---------------------------------------------- |
| `1`                 | RTX prompt, matching the rest of the interface |
| `2`                 | 3D text                                        |
| `3`                 | GTA Online style help                          |
| `4`                 | Floating help text above the table             |

`Config.Notifications = "rtx"` uses the built-in notifications. Anything else calls `Notify()` in `client/other.lua`, where your own notification system goes.

### Target

```lua
Config.Target = true
Config.Targettype = "oxtarget" -- "oxtarget", "qbtarget" or "qtarget"
```

The registering is in `client/other.lua`, open source, so any other target system is one function to add.

### Scoreboard

```lua
Config.Scoreboard = {
	enabled = true,
	spectators = true, -- Players standing next to a playing table see the scoreboard too
	spectatordistance = 6.0
}
```

## Sounds

```lua
Config.Sounds = {
	enabled = true,
	volume = 0.85,
	distance = 18.0, -- Nobody further away hears the table
	interface = true -- Your turn, fouls, wins
}
```

Every sound plays from where it happened on the table. The files are in `html/sounds` - replace them freely.

## Physics

The physics is tuned to a real table and ball, and every value is open in `config.lua`, section 10: cloth friction, rolling, spin, ball on ball, cushions, the speed range of the cue and more.

{% hint style="danger" %}
Every player and the server use the same values. Change them only while the server is stopped, never with a live edit in the middle of matches.
{% endhint %}

## Commands

| Command            | Who       | What it does                                      |
| ------------------ | --------- | ------------------------------------------------- |
| `/billiardleave`   | Everybody | Leave the match you are in - counts as giving up  |
| `/billiardreset`   | Admins    | Reset the table next to you, stakes are paid back |
| `/billiardcreator` | Admins    | The table creator                                 |

```lua
Config.Commands = {
	leave = "billiardleave",
	reset = "billiardreset",
	creator = "billiardcreator"
}
```

Rename any of them, or set it to `""` and it is never registered.

## Permissions

```lua
Config.AdminAce = "billiard.admin"

Config.Creator = {
	groups = {"admin", "superadmin", "god"}, -- ESX groups / QBCore permissions
	identifiers = {} -- Single players, by any identifier
}
```

A player can use the table creator and `/billiardreset` if **any** of these is true:

* he has the ACE `billiard.admin`
* his ESX group / QBCore permission is in `groups`
* one of his identifiers is in `identifiers`

## Language

Every line of text - notifications and the whole interface - is in `language/en.lua`, open source.

To add a language, copy `en.lua` (for example to `cs.lua`), rename the block inside to `Language["Czech"]`, add the file to `fxmanifest.lua` and set:

```lua
Config.Language = "Czech"
```

## Open-Source Files

| File               | What is in it                                                                        |
| ------------------ | ------------------------------------------------------------------------------------ |
| `config.lua`       | Everything configurable, fully commented                                             |
| `language/en.lua`  | Every text                                                                           |
| `client/other.lua` | Notifications, prompts, target, death check, hooks when a match starts or ends       |
| `server/other.lua` | Money, jobs, society accounts, admin checks, player names, Discord logs, match hooks |
| `html`             | The interface and the sounds                                                         |

### Death check

`IsPlayerDeadRTX()` in `client/other.lua` decides whether the player is down. It already reads the common death and last-stand states and listens to `esx:onPlayerDeath`, the QBCore ambulance events and `baseevents`. For any other ambulance script, add one line there, or trigger this from it:

```lua
TriggerEvent("rtx_billiard:client:playerDied")
```

### Discord logs

Switched on in `server/other.lua`, in `LogsRTX`. The webhook lives there too - never put it in `config.lua`, that file is sent to every player.

## Exports & Events

### Client exports

```lua
exports.rtx_billiard:IsPlayingBilliard() -- true while the player is in a match
exports.rtx_billiard:IsAimingBilliard() -- true while the player is lining up a shot
```

### Server exports

```lua
exports.rtx_billiard:IsPlayerPlayingBilliard(source) -- true / false
exports.rtx_billiard:GetPlayerBilliardTable(source) -- id of the table, or nil
```

### Server events

```lua
AddEventHandler("rtx_billiard:server:paid", function(source, amount, tableid) end)
AddEventHandler("rtx_billiard:server:matchStarted", function(tableid, mode, players, stake) end)
AddEventHandler("rtx_billiard:server:matchEnded", function(tableid, result) end)
```

### Client events

```lua
AddEventHandler("rtx_billiard:client:matchStarted", function(tableid, mode) end)
AddEventHandler("rtx_billiard:client:matchEnded", function(tableid, result) end)
```

## Troubleshooting

<details>

<summary>The table creator says I am not allowed</summary>

Check the ACE in `server.cfg`, `Config.Creator.groups` and `Config.Creator.identifiers`. Any one of them is enough.

</details>

<details>

<summary>The placed tables are gone after an update</summary>

The update replaced the `data` folder. Put your old `data/tables.json` back and restart the resource.

</details>

<details>

<summary>The RTX tables (types 3 to 6) do not show up</summary>

The `stream` folder is missing or was renamed. Put it back and restart the server - streamed models are only picked up by players who connect after the restart.

</details>

<details>

<summary>Nobody pays anything</summary>

Check `Config.Framework` and `Config.MoneyAccount`. In standalone mode everything is free until the money functions in `server/other.lua` are filled in.

</details>

<details>

<summary>Target does not work</summary>

`Config.Target = true` needs the target resource running. If it is not, the console says so at startup.

</details>

<details>

<summary>A player who died is still in the match</summary>

Your ambulance script uses a death state the script does not know yet. Add it to `IsPlayerDeadRTX()` in `client/other.lua`, or trigger `rtx_billiard:client:playerDied` from your ambulance script.

</details>

## Support

If you need help with installation, configuration or have any questions regarding this resource, feel free to contact us on our Discord server:

[Join our Discord](https://discord.gg/rtxdev)
