> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/global-components/stats/stat-modifiers.md).

# Stat Modifier

Last updated AC v1.5.3

## Overview

**Stat Modifier** is a serializable struct that describes **one change to one Stat**. Almost everything in the framework that touches a Stat uses it: Damagers, Projectiles, Explosions, Stat Reactions, AI Tasks, Super Item Processors, and the Modify Stat component.

A Stat Modifier answers two questions:

* **What changes** — the **Target** Stat and the **Stat Option** applied to it.
* **Which number is used** — either a plain **Value**, or a **Source** expression built from other Stats.

```
Stat Modifier
├── Target ─────────── the Stat that changes, on the Stats being modified
├── Stat Option ────── how it changes  (Subtract, Add, Set, Regenerate…)
└── Value From
    ├── Use Value ──── a random roll between Min and Max
    └── Use Sources ── an expression built from Stats and numbers
        ├── Source Stats ── the Stats component the terms are read from
        └── Terms ───────── Attack + [20-30] x Charge - Durability
```

{% hint style="info" %}
**Coming from an older version?** The modifier used to expose a single **Source** Stat plus a **Source Part**. That pair is now the **first term** of the Sources list. Existing assets are migrated automatically the first time the modifier is drawn in the Inspector — there is nothing to re-author.
{% endhint %}

## Parameters

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F7qZcuhqvY2EfY23uvS59%2Fimage.png?alt=media&amp;token=0c5b7259-a83c-4ac3-bfb7-101a572ef932" alt=""><figcaption></figcaption></figure>

#### Target

The **Stat ID** that will be modified on the Stats component receiving the modifier. E.g. **Health** on the character being damaged.

#### Stat Option

What to do to the Target Stat. See **Stat Options** below.

#### Value From

Where the number applied by the Stat Option comes from.

<table><thead><tr><th width="160">Option</th><th>Description</th></tr></thead><tbody><tr><td><strong>Use Value</strong></td><td>A random value between <strong>Min</strong> and <strong>Max</strong>. Set both to the same number for a fixed amount.</td></tr><tr><td><strong>Use Sources</strong></td><td>The value is calculated from the <strong>Source</strong> expression — one or more Stats and static numbers combined with operators.</td></tr></tbody></table>

#### Min / Max

Shown when **Value From** is set to **Use Value**. The modifier rolls a random number in that range every time it is applied.

#### Enable

Replaces Min/Max when the Stat Option is **Enable** or **Immune**, since those options take a true/false instead of a number.

## Source Expression

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FcJI7DGabqONhn1Qmtdxq%2Fimage.png?alt=media&amp;token=fffcbab0-3a9c-41b4-893e-99048774e164" alt=""><figcaption></figcaption></figure>

When **Value From** is set to **Use Sources**, the value is built from a list of **terms**. This is how a weapon deals damage based on its own **Attack** Stat instead of a hard-coded number.

\[Insert Image - the Source list: header with the Stats slot and the formula, and three term rows]

{% hint style="warning" %}
The list is evaluated **top to bottom, with no operator precedence**. The row order *is* the math order — `x` does **not** bind tighter than `+`. The header prints the resulting formula with parentheses so the real grouping is always visible.
{% endhint %}

Three rows reading `Attack`, `+ 30`, `x Charge` are evaluated as:

```
(Attack + 30) x Charge
```

Not as `Attack + (30 x Charge)`. To get that grouping, reorder the rows.

### Term

Each row of the list is one term.

<table><thead><tr><th width="180">Field</th><th>Description</th></tr></thead><tbody><tr><td><strong>Operator</strong></td><td>How the term combines with the result of the rows <strong>above</strong> it.</td></tr><tr><td><strong>Use Value / Use Stat</strong></td><td>Whether the term is a static number or a value read from a Stat.</td></tr><tr><td><strong>Stat</strong></td><td>The Stat the term reads, when set to <strong>Use Stat</strong>. E.g. the weapon's <strong>Attack</strong>.</td></tr><tr><td><strong>Source Part</strong></td><td>Which number of that Stat is used.</td></tr><tr><td><strong>Min / Max</strong></td><td>The static range rolled by the term, when set to <strong>Use Value</strong>.</td></tr></tbody></table>

The **first** term has nothing above it to combine with: it seeds the expression. Its operator only offers `+` and `-`, where `-` starts the expression at a negative value.

### Operators

<table><thead><tr><th width="100">Symbol</th><th width="200">Operator</th><th>Result</th></tr></thead><tbody><tr><td><code>+</code></td><td>Add</td><td><code>result + value</code></td></tr><tr><td><code>-</code></td><td>Substract</td><td><code>result - value</code></td></tr><tr><td><code>x</code></td><td>Multiply</td><td><code>result x value</code></td></tr><tr><td><code>/</code></td><td>Divide</td><td><code>result / value</code> — skipped when the value is 0, so it can never divide by zero.</td></tr><tr><td><code>+%</code></td><td>Add Percent</td><td><code>result + (result x value%)</code>. A value of <code>15</code> means +15%.</td></tr><tr><td><code>-%</code></td><td>Substract Percent</td><td><code>result - (result x value%)</code>. A value of <code>15</code> means -15%.</td></tr><tr><td><code>^</code></td><td>Clamp Min</td><td>Floor: the result can never go <strong>below</strong> the value.</td></tr><tr><td><code>v</code></td><td>Clamp Max</td><td>Ceiling: the result can never go <strong>above</strong> the value.</td></tr></tbody></table>

### Source Part

Which number of a Stat the term reads.

<table><thead><tr><th width="220">Part</th><th>Description</th></tr></thead><tbody><tr><td><strong>Value</strong></td><td>The current runtime value of the Stat.</td></tr><tr><td><strong>Min Value</strong></td><td>The Stat's minimum value.</td></tr><tr><td><strong>Max Value</strong></td><td>The Stat's maximum value.</td></tr><tr><td><strong>Random [Min-Max]</strong></td><td>A random value inside the Stat's own range.</td></tr><tr><td><strong>Normalized</strong></td><td>The Stat's value divided by its Max Value, so a 0-1 number. Ideal as a multiplier — e.g. a <strong>Charge</strong> Stat scaling the damage.</td></tr></tbody></table>

### Source Stats

The **Stats** component slot in the **Source** header. It is the component every **Use Stat** term reads from.

Leave it **empty** to use the Stats the caller provides:

<table><thead><tr><th width="320">Used by</th><th>Stats provided</th></tr></thead><tbody><tr><td>MDamager, MAttackTrigger, MExplosion</td><td>The <strong>Owner</strong> of the damager — the character swinging the weapon.</td></tr><tr><td>Super Item Processors (Damager, Projectile)</td><td>The <strong>Item's own</strong> Stats component, sitting next to the Super Item.</td></tr><tr><td>Modify Stat component</td><td>None. Assign <strong>Source Stats</strong> explicitly if the modifier uses Stat terms.</td></tr></tbody></table>

Assign it to read the terms from a specific character or item instead. An assigned component always wins over the one the caller provides.

{% hint style="info" %}
A component reference cannot cross a prefab/scene boundary. On a prefab, **Source Stats** must point at a Stats component on that same prefab — otherwise leave it empty and let the caller supply it.
{% endhint %}

### Example

A charged bow whose damage grows with the draw, plus a flat bonus, reduced by the bow's wear:

<table><thead><tr><th width="80">Row</th><th width="110">Operator</th><th width="220">Term</th><th>Running result</th></tr></thead><tbody><tr><td>1</td><td><code>+</code></td><td>Attack <em>(Value)</em></td><td><code>20</code></td></tr><tr><td>2</td><td><code>+</code></td><td>[20-30]</td><td><code>20 + 25 = 45</code></td></tr><tr><td>3</td><td><code>x</code></td><td>Charge <em>(Normalized)</em></td><td><code>45 x 0.8 = 36</code></td></tr><tr><td>4</td><td><code>-</code></td><td>Durability <em>(Value)</em></td><td><code>36 - 5 = 31</code></td></tr></tbody></table>

The header prints it as `(Attack + [20-30]) x Charge.Normalized - Durability`, and 31 is subtracted from the target's **Health**.

## Stat Options

Actions to do to the Stat. The menu is grouped by the part of the Stat it touches.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FbVYeBrlWbKUYxkR9auEv%2Fimage.png?alt=media&#x26;token=6d2b76d7-efb3-458f-ab85-f76c19fc9a0d" alt=""><figcaption></figcaption></figure>

### Value

<table><thead><tr><th width="270">Option</th><th>Description</th></tr></thead><tbody><tr><td><strong>Value/Add [+]</strong></td><td>Adds the modifier value to the Stat's <strong>Value</strong>.</td></tr><tr><td><strong>Value/Set</strong></td><td>Sets the Stat's <strong>Value</strong> to the modifier value.</td></tr><tr><td><strong>Value/Substract [-]</strong></td><td>Substracts the modifier value from the Stat's <strong>Value</strong>. This is what damage uses.</td></tr><tr><td><strong>Value/Reset</strong></td><td>Resets the Stat to its <strong>Reset To</strong> value.</td></tr><tr><td><strong>Value/Reduce by percent</strong></td><td>Reduces the Stat's <strong>Value</strong> by the modifier value, read as a percent.</td></tr><tr><td><strong>Value/Increase by percent</strong></td><td>Increases the Stat's <strong>Value</strong> by the modifier value, read as a percent.</td></tr><tr><td><strong>Value/Reset to Max</strong></td><td>Resets the Stat to its maximum value.</td></tr><tr><td><strong>Value/Reset to Min</strong></td><td>Resets the Stat to its minimum value.</td></tr><tr><td><strong>Value/Default</strong></td><td>Restores the <strong>Value</strong> to the default it was authored with.</td></tr></tbody></table>

### Max Value / Min Value

<table><thead><tr><th width="270">Option</th><th>Description</th></tr></thead><tbody><tr><td><strong>Max Value/Modify</strong></td><td>Adds or removes the modifier value from the Stat's <strong>Max Value</strong>.</td></tr><tr><td><strong>Max Value/Set</strong></td><td>Sets the Stat's <strong>Max Value</strong> to the modifier value.</td></tr><tr><td><strong>Max Value/Default</strong></td><td>Restores the <strong>Max Value</strong> to the default it was authored with.</td></tr><tr><td><strong>Min Value/Default</strong></td><td>Restores the <strong>Min Value</strong> to the default it was authored with.</td></tr></tbody></table>

### Degenerate / Regenerate

<table><thead><tr><th width="270">Option</th><th>Description</th></tr></thead><tbody><tr><td><strong>Degenerate/Value</strong></td><td>Enables the Degeneration and sets the <strong>Degenerate Rate</strong> to the modifier value. A value of 0 leaves the rate untouched.</td></tr><tr><td><strong>Degenerate/Start</strong></td><td>Starts the Degeneration without changing the rate.</td></tr><tr><td><strong>Degenerate/Stop</strong></td><td>Stops the Degeneration.</td></tr><tr><td><strong>Degenerate/Default</strong></td><td>Restores the Degeneration to its default.</td></tr><tr><td><strong>Regenerate/Value</strong></td><td>Enables the Regeneration and sets the <strong>Regenerate Rate</strong> to the modifier value. A value of 0 leaves the rate untouched.</td></tr><tr><td><strong>Regenerate/Start</strong></td><td>Starts the Regeneration without changing the rate.</td></tr><tr><td><strong>Regenerate/Stop</strong></td><td>Stops the Regeneration.</td></tr><tr><td><strong>Regenerate/Default</strong></td><td>Restores the Regeneration to its default.</td></tr></tbody></table>

### Multiplier

<table><thead><tr><th width="270">Option</th><th>Description</th></tr></thead><tbody><tr><td><strong>Multiplier/Set</strong></td><td>Sets the Stat's multiplier to the modifier value.</td></tr><tr><td><strong>Multiplier/Modify</strong></td><td>Adds or removes the modifier value from the Stat's multiplier.</td></tr><tr><td><strong>Multiplier/Default</strong></td><td>Restores the multiplier to the default it was authored with.</td></tr></tbody></table>

### Enable / Immune

<table><thead><tr><th width="270">Option</th><th>Description</th></tr></thead><tbody><tr><td><strong>Enable</strong></td><td>Enables or disables the Stat, using the <strong>Enable</strong> toggle instead of a number.</td></tr><tr><td><strong>Immune</strong></td><td>Makes the Stat immune, so <strong>Add</strong>, <strong>Set</strong> and <strong>Substract</strong> can no longer alter it.</td></tr></tbody></table>

{% hint style="info" %}
An **Immune** Stat still accepts every other option — only **Value/Add**, **Value/Set** and **Value/Substract** are blocked.
{% endhint %}
