> For the complete documentation index, see [llms.txt](https://devmosaic.gitbook.io/devmosaic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devmosaic.gitbook.io/devmosaic/resources/devmosaic-ox-inventory-rework-v2/blueprint-system.md).

# Blueprint System

Blueprints are items that unlock advanced crafting recipes. A recipe marked with a blueprint key is locked until the crafting player possesses the matching blueprint item in their inventory.

***

### How Blueprints Work

1. A `blueprint` item sits in the player's inventory with metadata identifying which recipe it unlocks.
2. When the player crafts a blueprint-locked recipe, `consume` percentage of the blueprint's durability is subtracted.
3. When the blueprint reaches 0 durability it is automatically removed from the inventory.

A single blueprint can be used multiple times before it is consumed. At `consume = 0.05` (5% per craft) each blueprint allows 20 crafts.

***

### Blueprint Configuration

In `data/crafting.lua`:

```lua
blueprints = {
    weapon_pistol = {
        item          = 'blueprint',
        metadataKey   = 'blueprint',
        metadataValue = 'weapon_pistol',
        consume       = 0.05,
    },
}
```

The matching recipe on a bench:

```lua
{
    name      = 'weapon_pistol',
    blueprint = 'weapon_pistol',
    xp        = { required = 36, reward = 22 },
    ingredients = { scrapmetal = 20, WEAPON_HAMMER = 0.05 },
    duration  = 7600,
    count     = 1,
}
```

***

### Giving a Blueprint to a Player

#### Export

Use this from any other resource to give a blueprint programmatically:

```lua
exports['inventory']:giveBlueprintToPlayer(playerId, blueprintKey)
```

| Parameter      | Type   | Description                                            |
| -------------- | ------ | ------------------------------------------------------ |
| `playerId`     | number | Server-side player source ID                           |
| `blueprintKey` | string | Key from the `blueprints` table in `data/crafting.lua` |

**Example:**

```lua
exports['inventory']:giveBlueprintToPlayer(source, 'weapon_pistol')
```

#### Admin Command

```
/giveBlueprintToPlayer [playerId] [blueprintKey]
```

**Example:**

```
/giveBlueprintToPlayer 5 weapon_smg
```

This gives the player with server ID `5` a blueprint for the SMG recipe.

#### ACE Permission

The admin command requires the following ACE in `server.cfg`:

```
add_ace group.admin command.giveBlueprintToPlayer allow
```

Replace `group.admin` with the admin group configured on your server.

***

### Default Blueprints

| Blueprint Key    | Unlocks Recipe | Crafts Per Blueprint |
| ---------------- | -------------- | -------------------- |
| `lockpick`       | Lockpick       | 20                   |
| `weapon_bat`     | Baseball Bat   | 20                   |
| `weapon_crowbar` | Crowbar        | 20                   |
| `weapon_wrench`  | Wrench         | 20                   |
| `weapon_hatchet` | Hatchet        | 20                   |
| `weapon_hammer`  | Hammer         | 20                   |
| `weapon_pistol`  | Pistol         | 20                   |
| `weapon_smg`     | SMG            | 20                   |

***

### Adding a New Blueprint

1. Add an entry to `blueprints` in `data/crafting.lua`.
2. Add `blueprint = 'your_key'` to the matching recipe.
3. Ensure the `blueprint` item exists in `data/items.lua`.
4. Use the export or admin command to give blueprints to players.

```lua
blueprints = {
    my_recipe = {
        item          = 'blueprint',
        metadataKey   = 'blueprint',
        metadataValue = 'my_recipe',
        consume       = 0.10,   -- 10% per craft = 10 crafts per blueprint
    }
}
```
