# Tool

## Tool System

#### Understanding Special Slots

The <mark style="color:$success;">lvs\_inventory</mark> system supports **special slots** for specific item types. The tool system uses the special slot named `'tool'`.

#### How Tools Work

When a recipe requires a tool (e.g., `tool = { name = 'lvs_wrench', degrade = 0.05 }`), the system:

1. Checks if the player has an item in their **tool special slot**
2. Verifies the item name matches the required tool name
3. Checks tool durability (if `degrade` is set)
4. Reduces durability by `degrade * 100` per craft
5. Destroys the tool when durability reaches 0

#### Creating Tool Items

**1. Define the item in your lvs\_shops `config/shops.lua` file:**

```lua
shops = {
    {
        type = 'youtool', 
        ...
        items = {
            {
        				type = 'tool', -- category name
        				name = 'lvs_wrench',
        				price = 1000,
        				metadata = {
                    type = 'tool',
                    durability = 100
        				}
    		    },
            {
                type = 'tool',
                name = 'lvs_screwdriver',
                price = 250, 
                metadata = {
                    type = 'tool',
                    durability = 100
                }
            }
        }	
        ...
    },
    ...
}
```

**2. The item must have `metadata.type = 'tool'` to fit in the tool slot.**

When giving the item via command or script, include the `tool` type:

```lua
-- Using giveitem command (if your inventory supports it)
/giveitem [playerID] lvs_wrench 1 tool

-- Using export
exports.ox_inventory:AddItem(playerId, 'lvs_wrench', 1, { type = 'tool' })
```

#### Tool Durability Mechanics

* **Starting durability:** 100 (or custom value in metadata)
* **Durability loss:** `recipe.tool.degrade * 100` per craft
* **Example:** `degrade = 0.05` → loses 5 durability per craft → 20 crafts until destroyed
* **When durability reaches 0:** Tool is automatically removed from inventory
* **If `degrade = 0`:** Tool has infinite durability (no loss)
