> For the complete documentation index, see [llms.txt](https://atiysus-organization.gitbook.io/aty-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atiysus-organization.gitbook.io/aty-scripts/inventory/features/durability-and-decay.md).

# Durability & Decay

## Durability & Decay

#### Durability

An item defined with `durability = true` is created at 100 and wears down as it is used. The value rides on that unit's metadata, so two pistols in the same bag can be in different condition and the difference survives trading, storing and server restarts.

Only items that ask for it have a condition. Weapons ship with one; a phone, a lockpick or anything adopted from the framework does not, because an item that wears out is a rule about your server rather than a property of the object. Add one where you want it — `durability = true` here, the **Condition** switch on the admin panel's item screen, or `SetDurability` from your own resource.

```lua
weapon_pistol = {
    label      = 'Pistol',
    weight     = 1100,
    stack      = false,
    durability = true,
}
```

Set it directly when a resource needs to:

```lua
exports.aty_inventory:SetDurability(inv, slot, 62)
```

#### Spoilage

Food and medical items can carry an expiry. With `Config.Decay.spoil` on (the default), items with an `expiry` field (hours) age in real time. A spoiled item can still be used, but it applies its `spoiled` effect instead of its `effect` — the shipped food and drink then restore little and cost health.

```lua
Config.Decay = {
    spoil = true,
}
```

Decay is computed from timestamps, not ticked — an item in a stash nobody has opened for two days is exactly as old as one that was watched the whole time.

#### Water damage

A separate, small system: swimming wears items that carry a `water` value. Every `tick` milliseconds in the water, each one loses `water × rate` points of condition, times `underwaterMultiplier` when fully submerged. Only items with `durability` can lose any (the shipped firearms carry `water = 2`), and nothing is destroyed — a soaked item stays in the bag at 0.

```lua
Config.Decay.water = {
    enabled              = true,
    tick                 = 4000,
    rate                 = 1.0,
    underwaterMultiplier = 2.0,
}
```

#### Inspecting

```
invdecay <playerId|invId> [age <hours>] [soak <n>] [repair]
```

Prints each perishable's freshness and each water-sensitive item's condition, flags what has spoiled, and lists the ages inside a stack whose units were made at different times. `age` winds the clock forward, `soak` applies submerged water ticks and `repair` puts condition back to 100 — test tools, on real items.
