# Server

## Track Exports

### createTrack

Creates a new track in the database.

```lua
exports['rcore_formula']:createTrack(client, trackData)
```

| Parameter   | Type   | Description            |
| ----------- | ------ | ---------------------- |
| `client`    | number | The player's server ID |
| `trackData` | table  | Track configuration    |

**trackData structure:**

```lua
{
    name = "Track Name",  -- string: Track display name
    icon = "icon_name"    -- string (optional): Track icon identifier
}
```

***

### editTrack

Edits an existing track's properties.

```lua
exports['rcore_formula']:editTrack(client, trackId, editData)
```

| Parameter  | Type          | Description                 |
| ---------- | ------------- | --------------------------- |
| `client`   | number        | The player's server ID      |
| `trackId`  | number/string | The ID of the track to edit |
| `editData` | table         | Fields to update            |

**editData structure:**

```lua
{
    name = "New Name",           -- string (optional): New track name
    startingPositions = {...},   -- table (optional): Starting grid positions
    registrationFee = 1000,      -- number (optional): Race entry fee
    zone = {...},                -- table (optional): Track zone boundaries
    zoneData = {...}             -- table (optional): Additional zone data
}
```

***

### deleteTrack

Deletes a track from the database.

```lua
exports['rcore_formula']:deleteTrack(client, trackId)
```

| Parameter | Type          | Description                   |
| --------- | ------------- | ----------------------------- |
| `client`  | number        | The player's server ID        |
| `trackId` | number/string | The ID of the track to delete |

***

### getTracks

Returns all loaded tracks.

```lua
local tracks = exports['rcore_formula']:getTracks()
```

**Returns:** `table` - Dictionary of all loaded tracks indexed by track ID.

***

## Team Exports

### createTeam

Creates a new racing team.

```lua
exports['rcore_formula']:createTeam(owner, teamData, base)
```

| Parameter  | Type    | Description                                     |
| ---------- | ------- | ----------------------------------------------- |
| `owner`    | number  | Player server ID who will own the team          |
| `teamData` | table   | Team configuration                              |
| `base`     | boolean | (optional) Whether this is a base/template team |

**teamData structure:**

```lua
{
    name = "Team Name",    -- string: Team display name
    icon = "icon_name",    -- string: Team icon identifier
    colors = {             -- table: Team colors
        primary = {...},
        secondary = {...}
    }
}
```

***

### editTeam

Edits an existing team's properties.

```lua
exports['rcore_formula']:editTeam(client, teamId, editData)
```

| Parameter  | Type          | Description                |
| ---------- | ------------- | -------------------------- |
| `client`   | number        | The player's server ID     |
| `teamId`   | number/string | The ID of the team to edit |
| `editData` | table         | Fields to update           |

**editData structure:**

```lua
{
    name = "New Team Name",  -- string (optional): New team name
    icon = "new_icon"        -- string (optional): New icon identifier
}
```

***

### deleteTeam

Deletes a team and removes all members.

```lua
exports['rcore_formula']:deleteTeam(client, teamId)
```

| Parameter | Type          | Description                  |
| --------- | ------------- | ---------------------------- |
| `client`  | number        | The player's server ID       |
| `teamId`  | number/string | The ID of the team to delete |

***

### setTeamMoney

Sets a team's balance to a specific amount.

```lua
local success = exports['rcore_formula']:setTeamMoney(teamId, amount)
```

| Parameter | Type          | Description            |
| --------- | ------------- | ---------------------- |
| `teamId`  | number/string | The team ID            |
| `amount`  | number        | The new balance amount |

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

### handleTeamTransaction

Processes a financial transaction for a team.

```lua
local success = exports['rcore_formula']:handleTeamTransaction(client, teamId, transactionType, amount, data)
```

| Parameter         | Type          | Description                   |
| ----------------- | ------------- | ----------------------------- |
| `client`          | number        | The player's server ID        |
| `teamId`          | number/string | The team ID                   |
| `transactionType` | string        | Transaction type (see below)  |
| `amount`          | number        | Transaction amount            |
| `data`            | table         | (optional) Additional options |

**Transaction Types:**

* `DEPOSIT` - Add money to team balance
* `WITHDRAW` - Remove money from team balance
* `PAY_FEE` - Pay race registration fee
* `RETURN_FEE` - Refund registration fee
* `RECEIVE_PRIZE` - Receive race winnings
* `BUY_UPGRADE` - Purchase team upgrade
* `PENALTY` - Pay penalty fee

**data structure:**

```lua
{
    ignorePermissions = false  -- boolean: Skip permission checks
}
```

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

### kickTeamMember

Removes a member from a team.

```lua
exports['rcore_formula']:kickTeamMember(client, teamId, racerId, data)
```

| Parameter | Type          | Description                             |
| --------- | ------------- | --------------------------------------- |
| `client`  | number        | The player's server ID (who is kicking) |
| `teamId`  | number/string | The team ID                             |
| `racerId` | number/string | The racer ID to kick                    |
| `data`    | table         | (optional) Additional options           |

**data structure:**

```lua
{
    fromMenu = false  -- boolean: Whether action is from UI menu
}
```

***

### changeMemberRole

Changes a team member's role.

```lua
exports['rcore_formula']:changeMemberRole(client, teamId, racerId, role, data)
```

| Parameter | Type          | Description                                   |
| --------- | ------------- | --------------------------------------------- |
| `client`  | number        | The player's server ID (who is changing role) |
| `teamId`  | number/string | The team ID                                   |
| `racerId` | number/string | The racer ID                                  |
| `role`    | string        | The new role name                             |
| `data`    | table         | (optional) Additional options                 |

**data structure:**

```lua
{
    fromMenu = false  -- boolean: Whether action is from UI menu
}
```

***

### buyTeamUpgrade

Purchases an upgrade for a team.

```lua
exports['rcore_formula']:buyTeamUpgrade(client, teamId, upgradeName, tier)
```

| Parameter     | Type          | Description                                          |
| ------------- | ------------- | ---------------------------------------------------- |
| `client`      | number        | The player's server ID                               |
| `teamId`      | number/string | The team ID                                          |
| `upgradeName` | string        | Upgrade name (e.g., 'vehicles', 'pitstop', 'repair') |
| `tier`        | number        | The tier level to upgrade to                         |

***

### getActiveTeamVehicle

Gets the active vehicle configuration for a team.

```lua
local vehicle = exports['rcore_formula']:getActiveTeamVehicle(teamId)
```

| Parameter | Type          | Description |
| --------- | ------------- | ----------- |
| `teamId`  | number/string | The team ID |

**Returns:** `table` or `nil`

```lua
{
    model = "vehicle_model",  -- string: Vehicle model name
    primary = {...},          -- table: Primary color
    secondary = {...}         -- table: Secondary color
}
```

***

### spawnTeamVehicle

Spawns a team vehicle at specified coordinates.

```lua
local vehicleEntity = exports['rcore_formula']:spawnTeamVehicle(client, teamId, coords)
```

| Parameter | Type          | Description                 |
| --------- | ------------- | --------------------------- |
| `client`  | number        | The player's server ID      |
| `teamId`  | number/string | The team ID                 |
| `coords`  | table/vector4 | Spawn position with heading |

**coords structure:**

```lua
{
    x = 0.0,
    y = 0.0,
    z = 0.0,
    w = 0.0  -- heading
}
```

**Returns:** `number` or `nil` - Vehicle entity handle if successful.

***

### getTeams

Returns all loaded teams.

```lua
local teams = exports['rcore_formula']:getTeams()
```

**Returns:** `table` - Dictionary of all loaded teams indexed by team ID.

***

## Team Racer Exports

### addPlayerToTeam

Adds a player to a team with a specific role.

```lua
exports['rcore_formula']:addPlayerToTeam(client, teamId, role)
```

| Parameter | Type          | Description            |
| --------- | ------------- | ---------------------- |
| `client`  | number        | The player's server ID |
| `teamId`  | number/string | The team ID            |
| `role`    | string        | The role to assign     |

***

### setPlayerTeamRoleByRacerId

Changes a racer's role by their racer ID.

```lua
local success = exports['rcore_formula']:setPlayerTeamRoleByRacerId(racerId, teamId, role)
```

| Parameter | Type          | Description  |
| --------- | ------------- | ------------ |
| `racerId` | number/string | The racer ID |
| `teamId`  | number/string | The team ID  |
| `role`    | string        | The new role |

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

### removePlayerFromTeam

Removes a player from a team.

```lua
exports['rcore_formula']:removePlayerFromTeam(client, teamId)
```

| Parameter | Type          | Description            |
| --------- | ------------- | ---------------------- |
| `client`  | number        | The player's server ID |
| `teamId`  | number/string | The team ID            |

***

### removePlayerFromTeamByRacerId

Removes a player from a team by their racer ID.

```lua
local success = exports['rcore_formula']:removePlayerFromTeamByRacerId(racerId, teamId)
```

| Parameter | Type          | Description  |
| --------- | ------------- | ------------ |
| `racerId` | number/string | The racer ID |
| `teamId`  | number/string | The team ID  |

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

### removeAllPlayersFromTeam

Removes all members from a team.

```lua
local success = exports['rcore_formula']:removeAllPlayersFromTeam(teamId)
```

| Parameter | Type          | Description |
| --------- | ------------- | ----------- |
| `teamId`  | number/string | The team ID |

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

## Race Exports

### setRaceState

Updates the state of a race.

```lua
exports['rcore_formula']:setRaceState(trackId, state)
```

| Parameter | Type          | Description        |
| --------- | ------------- | ------------------ |
| `trackId` | number/string | The track ID       |
| `state`   | string        | The new race state |

**Race States:**

* `JOINING` - Waiting for racers to join
* `STARTING` - Race countdown
* `RACING` - Race in progress
* `FINISHED` - Race completed

***

### canCreateRace

Checks if a player can create a race.

```lua
local canCreate = exports['rcore_formula']:canCreateRace(client)
```

| Parameter | Type   | Description            |
| --------- | ------ | ---------------------- |
| `client`  | number | The player's server ID |

**Returns:** `boolean` - `true` if player has permission, `false` otherwise.

***

### createRace

Creates a new race on a track.

```lua
exports['rcore_formula']:createRace(client, trackId, racersCount, laps, joinData)
```

| Parameter     | Type          | Description                              |
| ------------- | ------------- | ---------------------------------------- |
| `client`      | number        | The player's server ID                   |
| `trackId`     | number/string | The track ID                             |
| `racersCount` | number        | Required number of racers                |
| `laps`        | number        | Number of laps                           |
| `joinData`    | table         | (optional) Additional join configuration |

***

### canRaceStart

Checks if a race has enough participants to start.

```lua
local canStart = exports['rcore_formula']:canRaceStart(trackId)
```

| Parameter | Type          | Description  |
| --------- | ------------- | ------------ |
| `trackId` | number/string | The track ID |

**Returns:** `boolean` - `true` if all required racers have joined, `false` otherwise.

***

### joinRace

Adds a player to a race.

```lua
exports['rcore_formula']:joinRace(client, trackId, teamId, joinData)
```

| Parameter  | Type          | Description                 |
| ---------- | ------------- | --------------------------- |
| `client`   | number        | The player's server ID      |
| `trackId`  | number/string | The track ID                |
| `teamId`   | number/string | The team ID                 |
| `joinData` | table         | (optional) Join preferences |

**joinData structure:**

```lua
{
    tires = "soft"  -- string: Tire compound preference
}
```

***

### leaveRace

Removes a player from a race.

```lua
exports['rcore_formula']:leaveRace(client, trackId, kick)
```

| Parameter | Type          | Description                                 |
| --------- | ------------- | ------------------------------------------- |
| `client`  | number        | The player's server ID                      |
| `trackId` | number/string | The track ID                                |
| `kick`    | boolean       | (optional) Whether this is a forced removal |

***

### deleteRace

Deletes a race from a track.

```lua
exports['rcore_formula']:deleteRace(trackId)
```

| Parameter | Type          | Description  |
| --------- | ------------- | ------------ |
| `trackId` | number/string | The track ID |

***

### getRaceCheckpointsCount

Gets the number of checkpoints on a track.

```lua
local count = exports['rcore_formula']:getRaceCheckpointsCount(trackId)
```

| Parameter | Type          | Description  |
| --------- | ------------- | ------------ |
| `trackId` | number/string | The track ID |

**Returns:** `number` - Checkpoint count, or 0 if track not found.

***

### getHistoricalRaceData

Retrieves data from a completed race.

```lua
local raceData = exports['rcore_formula']:getHistoricalRaceData(raceId)
```

| Parameter | Type          | Description               |
| --------- | ------------- | ------------------------- |
| `raceId`  | number/string | The race ID from database |

**Returns:** `table` or `nil`

```lua
{
    standings = {...},  -- table: Final race standings
    timeData = {...}    -- table: Timing information
}
```

***

### addRacerPoints

Adds points to a racer.

```lua
local success = exports['rcore_formula']:addRacerPoints(client, points, clientIdentifier)
```

| Parameter          | Type   | Description                             |
| ------------------ | ------ | --------------------------------------- |
| `client`           | number | The player's server ID                  |
| `points`           | number | Points to add                           |
| `clientIdentifier` | string | Player identifier (for offline players) |

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

### addTeamPoints

Adds points to a team.

```lua
local success = exports['rcore_formula']:addTeamPoints(teamId, points)
```

| Parameter | Type          | Description   |
| --------- | ------------- | ------------- |
| `teamId`  | number/string | The team ID   |
| `points`  | number        | Points to add |

**Returns:** `boolean` - `true` if successful, `false` otherwise.

***

### getCachedRacerPoints

Gets cached points for a racer.

```lua
local points = exports['rcore_formula']:getCachedRacerPoints(client)
```

| Parameter | Type   | Description            |
| --------- | ------ | ---------------------- |
| `client`  | number | The player's server ID |

**Returns:** `number` - Racer's current points.

***

### getCachedTeamPoints

Gets cached points for a team.

```lua
local points = exports['rcore_formula']:getCachedTeamPoints(teamId)
```

| Parameter | Type          | Description |
| --------- | ------------- | ----------- |
| `teamId`  | number/string | The team ID |

**Returns:** `number` - Team's current points, or 0 if not found.

***

### getWatchers

Gets all players watching a race on a track.

```lua
local watchers = exports['rcore_formula']:getWatchers(trackId)
```

| Parameter | Type          | Description  |
| --------- | ------------- | ------------ |
| `trackId` | number/string | The track ID |

**Returns:** `table` - Dictionary of watchers `{clientId = true, ...}`

***

### getRaces

Returns all active races.

```lua
local races = exports['rcore_formula']:getRaces()
```

**Returns:** `table` - Dictionary of active races indexed by track ID.

***

### getPractices

Returns all active practice sessions.

```lua
local practices = exports['rcore_formula']:getPractices()
```

**Returns:** `table` - Dictionary of active practice sessions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.rcore.cz/paid-resources/rcore_formula/api/server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
