> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nmentities.net/llms.txt
> Use this file to discover all available pages before exploring further.

# What are Triggers

A trigger decides **when** an effect line runs. It's the part prefixed with `#`:

yaml

```yaml theme={null}
- narrate "Ow!"  #onHurt  @target
```

If a line has no trigger, it defaults to `#onSpawn`.

> `~` also works as a trigger prefix (`~onHurt`) if you prefer it over `#`.

## Available triggers

| Trigger       | Aliases                     | Fires when...                       | `@target` resolves to |
| :------------ | :-------------------------- | :---------------------------------- | :-------------------- |
| `#onSpawn`    | *(default)*                 | the mob is spawned via `/nme spawn` | nothing               |
| `#onHurt`     | `#onDamage`, `#onDamaged`   | the mob takes damage                | the damager, if any   |
| `#onAttack`   |                             | the mob deals damage                | the victim            |
| `#onDeath`    | `#onDie`                    | the mob dies                        | the killer, if any    |
| `#onInteract` | `#onClick`, `#onRightClick` | a player right-clicks the mob       | the player            |

## Triggers set the target

Each trigger defines who `@target` points to. That's what makes lines like these work:

```yaml theme={null}
- damage{amount=4}        #onAttack   @target   # extra damage to the victim
- narrate "&cYou did it!" #onDeath    @target   # message to the killer
- message{m=&7Hello!}     #onInteract @target   # reply to the clicking player
```

Two things to keep in mind:

* `#onSpawn` has no target. A spawn isn't caused by any entity, so `@target` resolves to nothing there. Use `@self`, `@playersRadius[N]` or `@world` instead.
* The target can be empty even on other triggers. A mob that dies to fall damage has no killer, so an `#onDeath @target` line simply does nothing. Environmental damage on `#onHurt` behaves the same way.

## One trigger, many lines

Multiple lines can share a trigger. They run in order:

```yaml theme={null}
boss:
  model: toast
  base: zombie
  effects:
  - sound{sound=entity.wither.spawn;volume=2} #onSpawn @playersRadius[30]
  - narrate "&4The boss has awakened."        #onSpawn @world
  - lightning                                 #onDeath @self
  - narrate "&aThe boss has fallen!"          #onDeath @world
```

## Where triggers apply

Triggers only exist on a mob's `effects:` list. Lines inside [named effects](#) never carry a trigger of their own: they inherit the moment they were called from. The `run` line has the trigger, the named effect just executes.

```yaml theme={null}
  effects:
  - run smash  #onHurt @target   # ← trigger lives here
  smash:
  - lunge{velocity=1.6}          # ← no triggers in here
  - delay 0.5s
  - damage{amount=10} @playersRadius[4]
```
