# Durability Repair Items

# Durability Repair Items

Internal repair consumables and the public durability API.

**Applies to:** `Nord Inventory v2.0.0`
# Durability repair items

Nord Inventory can create internal usable items that restore durability on a specific target item without relying on another script.

## Admin Studio

In **Behavior → Use behavior**, keep the handler on **Internal (Nord)** and set:

- **Item effect:** `Restore durability`
- **Target item:** choose an item that has durability enabled
- **Restore amount:** percentage points restored per successful use
- **Remove on use:** enable it if the repair item should be consumed

Nord only consumes the repair item when durability was actually restored.

## Lua definition

```lua
['weapon_cleaning_kit'] = {
    label = 'Weapon Cleaning Kit',
    weight = 250,
    stack = true,
    close = true,
    use = {
        duration = 3500,
        actionText = 'Repairing with {item}',
        remove = 1,
        repair = {
            item = 'weapon_pistol',
            amount = 25
        }
    }
}
```

## Server-authoritative behavior

When the repair item is used successfully, Nord Inventory:

1. validates that the configured target definition exists and uses durability;
2. searches the player's inventory for matching target instances;
3. selects the most damaged matching instance;
4. restores the configured amount without exceeding the target maximum;
5. consumes the repair item only after a real repair is applied;
6. updates inventory watchers immediately.

The same effect works with weapons and normal items because both use the standard `metadata.durability` state.

## Safe failure cases

The use is rejected without consuming the repair item when:

- the player does not have the configured target item;
- the target definition does not use durability;
- every matching target is already at maximum durability;
- the repair configuration is invalid.

If several copies of the target exist, the most damaged copy is repaired first.

## Runtime registration example

External resources can register repair items through the normal runtime API:

```lua
exports.nord_inventory:RegisterItem('pistol_cleaning_kit', {
    label = 'Pistol Cleaning Kit',
    weight = 200,
    stack = true,
    close = true,
    use = {
        duration = 3000,
        remove = 1,
        repair = {
            item = 'weapon_pistol',
            amount = 30
        }
    }
})
```

The repair itself remains server-authoritative inside Nord Inventory.
