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

# Exports

> **Note:** These exported functions can be called from other resources to integrate with the racing system - for example to open the tablet from a ped, gate another menu while a player is racing, or read a driver's ELO.

***

## Client Side Exports

### Race state

#### 1. `isInRace`

* **isInRace()** → `boolean`
  * True from the moment the player joins a race lobby until they leave / finish / are kicked. Mirrors the server-side `inRace` state, so it's correct during the lobby **and** the run.
  * **Example:**

    ```lua
    if exports['5s_racing']:isInRace() then return end
    ```

#### 2. `isRaceActive`

* **isRaceActive()** → `boolean`
  * True only once a joined race is actually live for this player (checkpoints registered and the countdown elapsed) - i.e. driving, not just sitting in the lobby.

#### 3. `getCurrentRaceId`

* **getCurrentRaceId()** → `number | nil`
  * Id of the race the player is running, or `nil`.

#### 4. `getRacePosition`

* **getRacePosition()** → `number | nil`
  * Current placing in the live race (`1` = leading), or `nil` when not racing / before the first leaderboard tick.

#### 5. `isCreatingTrack`

* **isCreatingTrack()** → `boolean`
  * True while the track creator/editor is open. Treat this like a "busy" flag (don't open menus, start cutscenes, teleport, etc.).

#### 6. `getRaceState`

* **getRaceState()** → `table`
  * One snapshot of where the player stands, for callers that want everything in one call instead of polling each export. Fields that don't apply are `nil`.
  * **Returns:** `{ inRace, racing, editing, raceId, position, currentLap, totalLaps, nextCheckpoint, totalCheckpoints }`

#### 7. `leaveCurrentRace`

* **leaveCurrentRace()**
  * Leave whatever race the player is in: tears down a live race locally (and tells the server), or just leaves a not-yet-started lobby (refunds the buy-in, updates the roster). No-op when not in a race. Also backs the tablet's "leave race" button.

***

### Tablet control

#### 8. `openRacingTablet` / `closeRacingTablet` / `toggleRacingTablet`

* **openRacingTablet()** / **closeRacingTablet()** / **toggleRacingTablet()**
  * Open, close, or flip the racing tablet on this client. Handy for a single keybind or a usable item.
  * **Example:**

    ```lua
    -- Bind a usable item to the tablet
    exports['5s_racing']:toggleRacingTablet()
    ```

#### 9. `isRacingTabletOpen`

* **isRacingTabletOpen()** → `boolean`
  * True while the tablet UI is on screen. Lets other resources avoid opening their own menu on top of it.

#### 10. `getDriverProfile` (client)

* **getDriverProfile()** → `table | nil`
  * The local player's loaded driver profile (`id, nickname, elo, firstLogin, isAdmin, stats`).

***

## Server Side Exports

#### 1. `getActiveRaces`

* **getActiveRaces()** → `table[]`
  * All joinable races right now (open lobbies that haven't started), as the same DTOs the tablet's race browser uses: `id, trackName, host, entryPrice, prizePool, participants`, etc.

#### 2. `isPlayerInRace`

* **isPlayerInRace(source)** → `boolean`
  * True if the player is in any race (lobby or running).
  * **Arguments:** `source` *(number)* - player's server ID.

#### 3. `getPlayerRaceId`

* **getPlayerRaceId(source)** → `number | nil`
  * Id of the race the player belongs to, or `nil`.

#### 4. `getDriverProfile` (server)

* **getDriverProfile(source)** → `table | nil`
  * The player's racing profile (`id, nickname, elo, firstLogin, isAdmin, stats`) - the same payload the tablet loads on open. Creates a fresh profile on the fly for a first-time racer.

#### 5. `getPlayerStats`

* **getPlayerStats(source)** → `table | nil`
  * Just the aggregated stats block: `totalRaces, completionRate, favoriteClass, mostUsedVehicle, totalEarnings`.

#### 6. `getPlayerElo`

* **getPlayerElo(source)** → `number | false | nil`
  * The player's ELO rating. Returns `false` when ranked/ELO is disabled server-wide (so the caller can tell "0 / disabled" apart), or `nil` when the player has no profile.

#### 7. `isRacingAdmin`

* **isRacingAdmin(source)** → `boolean`
  * Whether this player passes the racing admin check (verify/delete any track, force start/end any race). Resolves through the editable `isAdmin()` in `server/editable/functions.lua`.

#### 8. `openTabletForPlayer` / `closeTabletForPlayer`

* **openTabletForPlayer(source)** / **closeTabletForPlayer(source)**
  * Open/close the racing tablet for a specific player from the server (e.g. an interaction handled by another resource - a ped, a target zone, an item). Mirrors the client-side tablet exports.
  * **Example:**

    ```lua
    -- Open the tablet when a player interacts with a race-organiser ped
    exports['5s_racing']:openTabletForPlayer(source)
    ```

***

> Use these exports to integrate the 5s\_racing system with your own resources.
