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

# Server

### Server Exports

The following exports are **server-side only**:

```
GetPlayerProfile
AddPlayerXP
AddPlayerReputation
AddPlayerHeat
```

> Do not let a client choose export amounts. Call reward exports from a validated server-side action.

In the examples below, `source` means the numeric player source available inside your own server event, callback, or command.

#### `GetPlayerProfile`

**Side:** Server\
**Parameters:** `sourceOrIdentifier`

Accepts either:

* A numeric online player source
* A complete identifier string such as `license:...`

Returns:

```lua
success, profileOrError
```

Example:

```lua
local success, result = exports['tg-cornerselling']:GetPlayerProfile(source)

if not success then
    print(('Corner Selling profile could not be loaded: %s'):format(result))
    return
end

print(('Level: %s | Reputation: %s | Heat: %s'):format(
    result.level,
    result.reputation,
    result.heat
))
```

Important profile fields include:

```lua
profile.identifier
profile.playerName
profile.level
profile.maxLevel
profile.xp
profile.xpRequired
profile.reputation
profile.reputationRank
profile.heat
profile.skillPoints
profile.skills
profile.stats
profile.challenges
profile.milestones
profile.progression
```

If the player has never successfully opened `/cs`, the export returns:

```
false, "profile_not_found"
```

#### `AddPlayerXP`

**Side:** Server\
**Parameters:** `sourceOrIdentifier, amount, reason`

Adds non-negative XP, applies level-ups, grants level Connection Points, saves the profile, and returns the updated profile.

```lua
local success, result = exports['tg-cornerselling']:AddPlayerXP(
    source,
    75,
    'delivery_mission'
)

if not success then
    print(('XP reward failed: %s'):format(result))
    return
end

print(('New level: %s | Current XP: %s'):format(result.level, result.xp))
```

At maximum level, additional XP does not increase the player beyond `Config.Progression.MaxLevel`.

#### `AddPlayerReputation`

**Side:** Server\
**Parameters:** `sourceOrIdentifier, amount, reason`

Positive values add reputation. Negative values remove reputation. The result is clamped to the script's valid reputation range.

```lua
local success, result = exports['tg-cornerselling']:AddPlayerReputation(
    source,
    10,
    'territory_delivery'
)

if success then
    print(('New reputation: %s'):format(result.reputation))
end
```

Reputation penalty example:

```lua
local success, result = exports['tg-cornerselling']:AddPlayerReputation(
    source,
    -5,
    'failed_delivery'
)
```

#### `AddPlayerHeat`

**Side:** Server\
**Parameters:** `sourceOrIdentifier, amount, reason`

Positive values add Heat. Negative values remove Heat. The result is clamped between the configured internal minimum and maximum.

```lua
local success, result = exports['tg-cornerselling']:AddPlayerHeat(
    source,
    8,
    'witness_report'
)

if success then
    print(('New Heat: %s'):format(result.heat))
end
```

Heat reduction example:

```lua
local success, result = exports['tg-cornerselling']:AddPlayerHeat(
    source,
    -10,
    'police_bribe'
)
```

#### Using an identifier

All four exports also accept a full player identifier:

```lua
local identifier = 'license:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

local success, result = exports['tg-cornerselling']:AddPlayerXP(
    identifier,
    50,
    'offline_reward'
)
```

The identifier must already have a Corner Selling profile.
