> 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/matchmaking.md).

# Ranked Matchmaking

Ranked PvP duels in RedM with ELO ratings, matchmaking queues, rating tiers and an open challenge board in the RedM Duel & Arena System.

Players can find a duel three ways: challenge someone nearby, join a matchmaking queue, or take up a challenge posted on the open board.

## Challenging a nearby player

The **Challenge** tab lists every player within 250 metres who has a character loaded, with their tier, record, fastest draw and distance. Players who are already in a duel or busy are shown but cannot be picked.

The challenger chooses the mode, format, weapon, rules, wager and arena, and ticks **Ranked** if the result should change ratings. The other player has 30 seconds to answer.

```lua
Config.Challenge = {
    radius   = 250.0,   -- metres: "nearby players" list and challenge range
    window   = 30,      -- seconds the challenged player has to answer
    cooldown = 8,       -- seconds between two challenges from the same player
}
```

## Matchmaking queues

The **Matchmaking** tab has one button per queue. A player joins a queue and the server pairs them with the closest rated player in the same queue.

| Queue                | Mode          | Ranked | Weapon                 |
| -------------------- | ------------- | ------ | ---------------------- |
| Ranked Classic       | Classic Duel  | Yes    | Cattleman Revolver     |
| Ranked Best of 3     | Best of 3     | Yes    | Schofield Revolver     |
| Casual Quick Draw    | Quick Draw    | No     | Double-Action Revolver |
| Casual Headshot Only | Headshot Only | No     | Cattleman Revolver     |

### How pairing works

* Every two seconds the server looks for pairs, starting with whoever has waited longest.
* Two players can be paired when their ratings are within range. The range starts at **100** and widens by **2.5 points for every second** spent waiting, so nobody waits forever.
* A player with a challenge waiting for an answer is skipped until they answer it.
* The arena is picked at random from `Config.Queue.arenas`.
* Once paired, both players have **15 seconds** to ready up. If only one of them does, that player goes straight back into the queue.
* Queue matches never have a wager.

The menu shows how many players are in each queue and an estimated wait, based on the last ten matches found.

```lua
Config.Queue = {
    baseRange   = 100,
    widenPerSec = 2.5,
    acceptTime  = 15,
    arenas      = { 'blackwater_main', 'scarlett_meadows', 'lagras', 'armadillo', 'heartlands' },
    queues = {
        { id = 'ranked-classic',  mode = 'classic',   ranked = true,  weapon = 'cattleman' },
        { id = 'ranked-bo3',      mode = 'bo3',       ranked = true,  weapon = 'schofield' },
        { id = 'casual-quick',    mode = 'quickdraw', ranked = false, weapon = 'doubleaction' },
        { id = 'casual-headshot', mode = 'headshot',  ranked = false, weapon = 'cattleman' },
    },
}
```

Add, remove or change queues freely. `mode` must be one of the mode ids in `Config.Modes` and `weapon` one of the ids in `Config.Weapons`.

The queue name is built from the ranked or casual tag and the mode name in the server's language, for example `Ranked · Classic Duel`. Add `name = '...'` to a queue to use a fixed name instead. See [Languages and Translation](/script-documentation/cas-duel-arena-system/languages.md).

## The open challenge board

Below the queues is a public board. A player posts an open challenge and anyone on the server can take it up, wherever they are. The duel starts as soon as someone accepts.

* One post per player at a time.
* A post comes down on its own after 30 minutes, or when its owner leaves.
* The settings of a posted challenge come from `config.lua`, including the wager. Both players must be able to cover it.

```lua
Config.Board = {
    expireMinutes = 30,
    post = { mode = 'classic', weapon = 'cattleman', wager = 25, arena = 'blackwater_main', ranked = true },
}
```

## ELO rating

Ranked duels change both players' ratings with the ELO system.

```lua
Config.Rating = {
    start = 1200,   -- rating of a new player
    k     = 32,     -- ELO K-factor
    floor = 100,    -- rating never drops below this
}
```

* Two players at the same rating win or lose **16 points**. Beating a stronger player earns more; losing to a weaker one costs more.
* Only ranked duels between two players change ratings. NPC duels are never ranked.
* Tournament matches are ranked when `Config.Tournament.ranked` is on.
* A drawn match changes nothing.

## Rating tiers

The menu shows a tier badge next to every rating.

| Tier      | Rating         |
| --------- | -------------- |
| Greenhorn | Below 1000     |
| Drifter   | 1000           |
| Gunhand   | 1200           |
| Pistolero | 1400           |
| Deadshot  | 1600           |
| Legend    | 1800 and above |

New players start at 1200, which is Gunhand.

## Leaderboard

The **Leaderboard** tab ranks every player with at least one ranked or casual duel against another player, by rating, then by wins. The top 20 are listed, and a player outside the top 20 always sees their own row. See [Profiles, Leaderboard and Achievements](/script-documentation/cas-duel-arena-system/profiles-and-achievements.md).
