> For the complete documentation index, see [llms.txt](https://k0ssek-scripts.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://k0ssek-scripts.gitbook.io/docs/scripts/dart-game/exports.md).

# Exports

Server and client exports for other resources.

| Export                        | Side   | Returns          | Description                           |
| ----------------------------- | ------ | ---------------- | ------------------------------------- |
| `GetPlayerStats(source)`      | Server | `table` or `nil` | Stats of a connected player           |
| `AddPlayerXP(source, amount)` | Server | `boolean`        | Award darts XP to a player            |
| `IsPlayerInLobby(source)`     | Server | `boolean`        | Player is in a lobby or a match       |
| `IsPlayerInMatch(source)`     | Server | `boolean`        | Player is in a running match          |
| `IsInLobby()`                 | Client | `boolean`        | Local player is in a lobby or a match |
| `IsInMatch()`                 | Client | `boolean`        | Local player is in a running match    |

## Server exports

### GetPlayerStats

```lua
local stats = exports.kossek_darts:GetPlayerStats(source)
```

| Parameter | Type     | Description             |
| --------- | -------- | ----------------------- |
| `source`  | `number` | Server id of the player |

Returns a table:

```lua
{
    level         = 12,
    xp            = 4821,
    games_played  = 34,
    games_won     = 18,
    highest_score = 60,
    elo           = 1148,
}
```

`highest_score` is the most points the player has scored in a single turn.

If the player has no row in `darts_stats` yet, one is created and the starting values are returned (level 1, 0 XP, Elo from `Config.Elo.Default`). Returns `nil` only when `source` is not a number.

```lua
local stats = exports.kossek_darts:GetPlayerStats(source)
if stats then
    print(('Level %d, Elo %d'):format(stats.level, stats.elo))
end
```

### AddPlayerXP

```lua
local success = exports.kossek_darts:AddPlayerXP(source, amount)
```

| Parameter | Type     | Description               |
| --------- | -------- | ------------------------- |
| `source`  | `number` | Server id of the player   |
| `amount`  | `number` | XP to add, greater than 0 |

Adds XP, levels the player up when they have enough, saves the result and shows the player a `+XP` notification (and a level-up one when it applies).

Returns `true` on success. Returns `false` when an argument is invalid or the player has no identifier yet.

```lua
-- Reward darts XP from another script
RegisterNetEvent('myEvent:finished', function()
    exports.kossek_darts:AddPlayerXP(source, 150)
end)
```

### IsPlayerInLobby

```lua
local inLobby = exports.kossek_darts:IsPlayerInLobby(source)
```

Returns `true` when the player is in the lobby of any board, whether the match has started or not.

```lua
-- Do not teleport a player who is playing darts
if exports.kossek_darts:IsPlayerInLobby(source) then return end
```

### IsPlayerInMatch

```lua
local inMatch = exports.kossek_darts:IsPlayerInMatch(source)
```

Returns `true` only while the player is in a match that is running. A player who is waiting in a lobby gets `false`.

## Client exports

### IsInLobby

```lua
local inLobby = exports.kossek_darts:IsInLobby()
```

Returns `true` when the local player has joined a board, whether the match has started or not.

```lua
-- Block a menu while the player is at a dartboard
RegisterCommand('openMenu', function()
    if exports.kossek_darts:IsInLobby() then return end
    -- open the menu
end, false)
```

### IsInMatch

```lua
local inMatch = exports.kossek_darts:IsInMatch()
```

Returns `true` only while the local player is in a match that is running. A player who is waiting in a lobby gets `false`.
