# API Reference

## 📚 API Reference

### Server Functions

#### AddXP

```lua
AddXP(src, amount)
```

Add XP to a player. Automatically handles level ups.

| Parameter | Type   | Description      |
| --------- | ------ | ---------------- |
| src       | number | Player server ID |
| amount    | number | XP amount to add |

#### GetBonus

```
local value = GetBonus(src, bonusType)
```

Get a specific bonus value for a player.

| Parameter | Type   | Values                                                                |
| --------- | ------ | --------------------------------------------------------------------- |
| src       | number | Player server ID                                                      |
| bonusType | string | `'speedReduction'`, `'successBoost'`, `'bonusItem'`, `'materialSave'` |

#### GetAllBonuses

```
local bonuses = GetAllBonuses(src)
-- bonuses.speedReduction, bonuses.successBoost, bonuses.bonusItem, bonuses.materialSave
```

#### GetRequiredXP

```
local xp = GetRequiredXP(level)
```

Get XP required for a specific level.

#### LoadCraftData / SaveCraftData

```
LoadCraftData(src)
SaveCraftData(src)
```

Load or save player craft data to database.Server Callbacks

| Callback                      | Parameters                | Returns |
| ----------------------------- | ------------------------- | ------- |
| `craft:hasItem`               | itemName                  | boolean |
| `craft:getInventory`          | -                         | table   |
| `craft:getData`               | tableType                 | table   |
| `craft:start`                 | recipeId, tableId, amount | table   |
| `craft:getStats`              | -                         | table   |
| `craft:learnBlueprint`        | blueprintItem             | table   |
| `craft:admin:getPlayers`      | -                         | table   |
| `craft:admin:getPlayerDetail` | targetId                  | table   |
| `craft:admin:getActiveCrafts` | -                         | table   |
| `craft:admin:giveXP`          | targetId, amount          | table   |
| `craft:admin:setLevel`        | targetId, level           | table   |
| `craft:admin:giveBlueprint`   | targetId, blueprintItem   | table   |
| `craft:admin:resetPlayer`     | targetId                  | table   |

***

### Client Events

| Event                  | Data         | Description       |
| ---------------------- | ------------ | ----------------- |
| `craft:result`         | result table | Craft completed   |
| `craft:levelUp`        | level data   | Player leveled up |
| `craft:refreshUI`      | UI data      | Refresh NUI       |
| `craft:notify`         | msg, type    | Show notification |
| `craft:openAdminPanel` | -            | Open admin panel  |

***

### Server Events

| Event            | Parameters        | Description               |
| ---------------- | ----------------- | ------------------------- |
| `craft:complete` | recipeId, tableId | Client reports craft done |
| `craft:cancel`   | -                 | Client cancels craft      |

***

### NUI Callbacks

| Callback               | Data                    | Description            |
| ---------------------- | ----------------------- | ---------------------- |
| `startCraft`           | recipeId, amount        | Start crafting         |
| `cancelCraft`          | -                       | Cancel current craft   |
| `closeCraft`           | -                       | Close craft UI         |
| `refreshInventory`     | -                       | Refresh inventory data |
| `learnBlueprint`       | blueprintItem           | Learn a blueprint      |
| `getStats`             | -                       | Get player statistics  |
| `closeAdminPanel`      | -                       | Close admin panel      |
| `adminGetPlayerDetail` | targetId                | Get player details     |
| `adminGetActiveCrafts` | -                       | Get active crafts      |
| `adminGiveXP`          | targetId, amount        | Give XP                |
| `adminSetLevel`        | targetId, level         | Set level              |
| `adminGiveBlueprint`   | targetId, blueprintItem | Give blueprint         |
| `adminResetPlayer`     | targetId                | Reset player           |
| `adminRefreshPlayers`  | -                       | Refresh player list    |

### Locale Function

#### Server-side

```
local text = L('key', arg1, arg2)
```

#### Client-side (NUI)

```
const text = T('key', arg1, arg2);
```


---

# 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://elena-scripts.gitbook.io/elenascripts/gameplay/craft-system/api-reference.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.
