> For the complete documentation index, see [llms.txt](https://cactus-code.gitbook.io/cactus-code-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cactus-code.gitbook.io/cactus-code-docs/documentation/scripts/advanced-crafting-v2/export.md).

# Export

## <mark style="color:$danger;">Client-Side Exports</mark>

### Station Management

#### `OpenCraftStation(stationId)`

```lua
exports['cactus_craft']:OpenCraftStation('stationId')
```

Opens the craft station UI for the given `stationId`.

#### `OpenCraftStation(stationId, coords)`

```lua
exports['cactus_craft']:OpenCraftStation('stationId', vector3(x, y, z))
```

Opens the craft station UI at the specified coordinates.

#### `CloseCraftMenu()`

```lua
exports['cactus_craft']:CloseCraftMenu()
```

Closes the craft menu/UI.

***

### XP & Level System (Asynchronous - recommended)

> Use these asynchronous exports (with callbacks) when you need up-to-date data from the database.

#### `GetPlayerCraftXP(stationId, callback)`

```lua
exports['cactus_craft']:GetPlayerCraftXP('stationId', function(xp)
    print("XP: " .. xp)
end)
```

Fetches the player's XP for `stationId` from the database and returns it via the callback.

#### `GetPlayerCraftLevel(stationId, callback)`

```lua
exports['cactus_craft']:GetPlayerCraftLevel('stationId', function(level)
    print("Level: " .. level)
end)
```

Fetches the player's level for `stationId` from the database and returns it via the callback.

#### `GetPlayerCraftData(stationId, callback)`

```lua
exports['cactus_craft']:GetPlayerCraftData('stationId', function(data)
    print("XP: " .. data.xp .. ", Level: " .. data.level)
end)
```

Fetches full station data (e.g. `{ xp = ..., level = ..., stationId = ... }`) from the database.

***

### XP & Level System (Synchronous - Legacy)

> These are synchronous/local-cache exports. They may be faster but can return outdated values.

#### `GetPlayerCraftXP(stationId)`

```lua
local xp = exports['cactus_craft']:GetPlayerCraftXP('stationId')
```

Returns cached XP for `stationId`. May be stale.

#### `GetPlayerCraftLevel(stationId)`

```lua
local level = exports['cactus_craft']:GetPlayerCraftLevel('stationId')
```

Returns cached level for `stationId`. May be stale.

#### `GetPlayerCraftData(stationId)`

```lua
local data = exports['cactus_craft']:GetPlayerCraftData('stationId')
```

Returns cached data for the specified station.

#### `GetPlayerCraftData()`

```lua
local allData = exports['cactus_craft']:GetPlayerCraftData()
```

Returns cached data for all stations (table of stations).

***

### UI State

#### `IsCraftUIOpen()`

```lua
local isOpen = exports['cactus_craft']:IsCraftUIOpen()
```

Returns `true` if the craft UI is currently open for the player.

#### `IsCrafting()`

```lua
local isCrafting = exports['cactus_craft']:IsCrafting()
```

Returns `true` if the player is currently performing a craft action.

#### `GetCurrentStation()`

```lua
local currentStation = exports['cactus_craft']:GetCurrentStation()
```

Returns the `stationId` of the currently active/opened station (or `nil` if none).

***

### Recipe Validation

#### `CanCraftRecipe(recipeId, stationId)`

```lua
local canCraft = exports['cactus_craft']:CanCraftRecipe('recipeId', 'stationId')
```

Returns `true` if the player has the required ingredients, level, and meets conditions to craft the recipe at the given station.

***

## <mark style="color:$danger;">Server-Side Exports</mark>

### XP Management

#### `AddCraftXP(playerId, stationId, amount)`

```lua
exports['cactus_craft']:AddCraftXP(playerId, 'stationId', amount)
```

Adds the specified `amount` of XP to `playerId` for `stationId`. This updates server-side data and (usually) the database.

#### `SetCraftXP(playerId, stationId, amount)`

```lua
exports['cactus_craft']:SetCraftXP(playerId, 'stationId', amount)
```

Sets the player's XP for `stationId` to the exact `amount`.

#### `GetPlayerCraftData(playerId, stationId, callback)`

```lua
exports['cactus_craft']:GetPlayerCraftData(playerId, 'stationId', function(data)
    -- data.xp, data.level, data.stationId
end)
```

Returns `playerId`'s data for a specific station via the callback.

#### `GetPlayerCraftData(playerId, callback)`

```lua
exports['cactus_craft']:GetPlayerCraftData(playerId, function(data)
    -- data.stations = { stationId = { xp = 100, level = 5 } }
end)
```

Returns all craft station data for a player via the callback.

***

### Admin Commands

#### `ForceCraft(playerId, recipeId, quantity)`

```lua
exports['cactus_craft']:ForceCraft(playerId, 'recipeId', quantity)
```

Forces the server to craft the specified `recipeId` for `playerId` in the given `quantity`. Useful for admin commands, rewards, or debugging.

#### `OpenCraftStationServer(playerId, stationId)`

```lua
exports['cactus_craft']:OpenCraftStationServer(playerId, 'stationId')
```

Opens a craft station UI for a specific player from the server-side (useful for admin-triggered interactions).

***

## Examples

### Server-Side Example

```lua
-- Give XP
exports['cactus_craft']:AddCraftXP(playerId, 'leatherworker', 50)

-- Set XP (e.g. to set level progress)
exports['cactus_craft']:SetCraftXP(playerId, 'blacksmith_forge', 500)

-- Get a player's station data
exports['cactus_craft']:GetPlayerCraftData(playerId, 'leatherworker', function(data)
    print("Level: " .. data.level .. ", XP: " .. data.xp)
end)

-- Force a craft for a player
exports['cactus_craft']:ForceCraft(playerId, 'iron_sword', 1)
```

***

### Client-Side Example (Asynchronous - recommended)

```lua
-- Get fresh level from database
exports['cactus_craft']:GetPlayerCraftLevel('leatherworker', function(level)
    if level >= 20 then
        -- give player a special UI, unlock, badge, etc.
        print("Player is a master leatherworker!")
    end
end)

-- Get fresh XP from database
exports['cactus_craft']:GetPlayerCraftXP('leatherworker', function(xp)
    print("Current XP: " .. xp)
end)

-- Open a station UI
exports['cactus_craft']:OpenCraftStation('leatherworker')
```

***

## Important Notes

* **Prefer asynchronous exports** (with callbacks) when you need reliable and up-to-date information from the database.
* **Server-side exports** are authoritative and should be used for data mutations (Add/Set XP, ForceCraft).
* **Client synchronous exports** return local cache and **may be out-of-date** — use them only when eventual consistency is acceptable.
* **stationId** values must match the identifiers defined in your `config.lua`.
* Handle network errors/timeouts on the client if your callback-based calls may be delayed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://cactus-code.gitbook.io/cactus-code-docs/documentation/scripts/advanced-crafting-v2/export.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
