> 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-advanced-hunting/exports-and-api.md).

# Exports & API

All exports are called as `exports["cas-hunting"]:Fn(...)`.

## Server-side exports

| Export                            | Parameters        | Description                                                 |
| --------------------------------- | ----------------- | ----------------------------------------------------------- |
| `addHuntingXp(source, amount)`    | player id, number | Add hunting XP                                              |
| `removeHuntingXp(source, amount)` | player id, number | Remove hunting XP (cannot go below 0)                       |
| `addTraceXp(source, amount)`      | player id, number | Add tracking XP (Trace Level = floor(TraceXP / 100), max 5) |

```lua
-- Reward hunting XP for completing another job
RegisterNetEvent("myScript:jobCompleted", function()
    exports["cas-hunting"]:addHuntingXp(source, 25)
end)
```

## Client-side exports

| Export                    | Parameters | Description                         |
| ------------------------- | ---------- | ----------------------------------- |
| `PlaceBait(baitItemName)` | string     | Place bait at the player's location |

Available bait items: `bait_corn`, `bait_apples`, `bait_salt` (herbivore), `bait_meat`, `bait_blood` (predator), `bait_grain`, `bait_seeds` (bird), `bait_legendary`, `bait_exotic` (premium). The player must be in an active hunting area and hold the item.

## State bags

```lua
-- Client: read the player's trace level
local traceLevel = LocalPlayer.state.TraceLevel or 0

-- Server: set trace level (internal)
Player(src).state:set("TraceLevel", level, true)
```

## Client globals

```lua
if isHuntingStarted then end          -- active contract?
for ped, data in pairs(SpawnedAnimals) do end  -- spawned animals
if CurrentMission then                 -- current mission data
    local coords = CurrentMission.radiusCoords
end
```

## Best practices

```lua
-- Cache the export for frequent calls
local addXP = exports["cas-hunting"].addHuntingXp
addXP(source, 10)

-- Validate inputs before calling
if type(src) == "number" and amount and amount > 0 then
    exports["cas-hunting"]:addHuntingXp(src, amount)
end
```
