> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-duel-arena-system/tournaments.md).

# Tournaments

Run single elimination duel tournaments on your RedM server. Entry fees, prize pools, automatic brackets, byes, walkovers and payouts.

Tournaments are single elimination brackets with an entry fee and a prize pool. Once a bracket starts, the server dispatches every match on its own. Admins only step in if they want to.

## How a tournament runs

1. **Registration opens.** Every tournament template in `config.lua` always has one bracket open for entries. Players join from the **Tournaments** tab and pay the entry fee, which goes into the pool.
2. **The bracket starts** when the last slot is filled, or when an admin runs `/duel_admin tstart <id>` (at least 2 entrants).
3. **Seeding.** Entrants are shuffled. If the number of entrants is not a power of two, the remaining slots become **byes** and those players go straight through to the next round.
4. **Matches are dispatched.** Whenever both players of a match are online and free, the duel opens for them automatically. They get the pre-match screen and ready up as usual.
5. **Winners advance** until the final is played.
6. **Prizes are paid** from the pool and a new registration opens for the same template.

A player can leave a tournament and get their entry fee back while registration is still open. Once the bracket has started, entries are final.

## No-shows and walkovers

If one player of a match is offline or busy, the server waits `noShowSeconds` (120 by default).

* If one side turns up and the other does not, the side that turned up wins by **walkover**.
* If neither turns up, the higher rated player advances.
* Leaving the pre-match screen of a tournament match counts as a forfeit.
* A drawn tournament match is played again.

## Prizes

`payouts` is the share of the pool for 1st place, 2nd place, and each of the two losing semifinalists.

```lua
payouts = { 0.6, 0.25, 0.075, 0.075 }
```

With 8 entrants at $50 each, the pool is $400: the champion takes $240, the runner up $100 and each losing semifinalist $30. Whatever the shares leave over stays with the house.

Prize money is added to the player's duel earnings. Money for a player who is offline when the final ends is kept and paid the next time they open the menu. See [Wagers, Side Bets and Payouts](/script-documentation/cas-duel-arena-system/wagers-and-betting.md#money-owed-to-offline-players).

Winning a tournament counts towards the **Tournament Champion** achievement and the server record for most tournament wins.

## Watching tournament matches

Live tournament matches show a **Watch** button on the bracket, and they also appear in the **Active Duels** tab. Spectators can bet on them like any other duel. See [Spectating Live Duels](/script-documentation/cas-duel-arena-system/spectating.md).

## Surviving a restart

Brackets are saved. If the server or the resource restarts, every tournament comes back exactly where it was, and any match that was in progress is dispatched again.

## Templates

```lua
Config.Tournament = {
    ranked        = true,   -- tournament matches affect rating
    noShowSeconds = 120,    -- wait for an offline or busy opponent, then award a walkover
    templates = {
        { id = 'valentine', mode = 'bo3',                   weapon = 'cattleman',    arena = 'blackwater_main', entry = 50,  slots = 8,  payouts = { 0.6, 0.25, 0.075, 0.075 } },
        { id = 'quickdraw', mode = 'quickdraw', format = 5,     weapon = 'doubleaction', arena = 'lagras',          entry = 25,  slots = 16, payouts = { 0.6, 0.25, 0.075, 0.075 } },
        { id = 'deadshot',  mode = 'headshot',              weapon = 'schofield',    arena = 'heartlands',      entry = 100, slots = 8,  payouts = { 0.65, 0.25, 0.05, 0.05 } },
    },
}
```

| Field     | Meaning                                                                                                                                                                                                                                   |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`      | Unique template id. Do not change it once players have entered.                                                                                                                                                                           |
| `name`    | Optional. A fixed name for every language. Without it the name is `tournament_<id>` in the [language file](/script-documentation/cas-duel-arena-system/languages.md), for example `tournament_valentine = 'The Valentine Invitational',`. |
| `mode`    | Duel mode id from `Config.Modes`.                                                                                                                                                                                                         |
| `format`  | Optional. Number of rounds for modes with a format choice. Leave it out to use the mode's default.                                                                                                                                        |
| `weapon`  | Weapon id from `Config.Weapons`. Every match of the tournament uses it.                                                                                                                                                                   |
| `arena`   | Arena id from `Config.Arenas`.                                                                                                                                                                                                            |
| `entry`   | Entry fee in dollars.                                                                                                                                                                                                                     |
| `slots`   | Most entrants. A power of two (4, 8, 16, 32) fills the bracket exactly; other sizes work with byes.                                                                                                                                       |
| `starts`  | Optional. Text shown while registration is open. Without it: "When the bracket fills" in the server's language.                                                                                                                           |
| `payouts` | Shares of the pool for 1st, 2nd and the two losing semifinalists.                                                                                                                                                                         |

Tournament matches never carry a wager of their own. The entry fee is the stake.

{% hint style="info" %}
Rename the included templates to match your server. Their names came from the original arenas, so for example "The Valentine Invitational" is played on Blackwater Main Street.
{% endhint %}

## Admin commands

| Command                    | Does                                                                                                           |
| -------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `/duel_admin`              | Lists every tournament with its id and status (`open`, `live` or `done`).                                      |
| `/duel_admin tstart <id>`  | Starts the bracket before it is full.                                                                          |
| `/duel_admin tcancel <id>` | Cancels the tournament, refunds every entry fee, calls off its running matches and opens a fresh registration. |

Only the most recent finished bracket of each template is kept, so the menu shows the last champion without growing forever.
