> ## 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.

# NPCs & Dialogs

> Identify and edit NPCs from code, and start branching conversations for any player.

## NPCs

`NMEntitiesAPI.npcs()` identifies [NPC](npcs) entities in the world and looks up their definitions.

```java theme={null}
String npcId  = NMEntitiesAPI.npcs().npcId(clickedEntity);  // null if not an NPC instance
boolean isNpc = NMEntitiesAPI.npcs().isNpc(clickedEntity);
NpcDefinition def = NMEntitiesAPI.npcs().get("bob");
Set<String> ids = NMEntitiesAPI.npcs().ids();               // also all()
```

### Editing NPCs

`ops()` is the same surface the [`/npc` commands](npc-commands) use, so an addon and an admin produce identical results:

```java theme={null}
NpcOps ops = NMEntitiesAPI.npcs().ops();
ops.setDisplay("bob", "&6Quest Giver");
ops.addEffect("bob", "quest_dialogue");
```

<Note>
  `ops()` is null only while the platform is still enabling. Check it if you call during startup.
</Note>

To replace what a right-click does rather than edit the NPC, cancel [`NpcInteractEvent`](addon-events#npcinteractevent).

## Dialogs

Branching conversations from `Dialogs/` can be driven from code: start one from an item use, a region enter, a quest step.

```java theme={null}
NMEntitiesAPI.dialogs().start(player, "bob_talk", npcEntity, "&6Bob"); // npc and name optional
boolean talking = NMEntitiesAPI.dialogs().isInDialog(player);
NMEntitiesAPI.dialogs().end(player);
```

`ids()` and `get(id)` are there too. The NPC argument is optional, so a dialog doesn't have to belong to an NPC at all.

### Dialogs speak the same effect DSL

Custom [conditions](extending-effects#custom-conditions) you register are immediately usable in dialog `conditions:` blocks, and custom [mechanics](extending-effects#custom-mechanics) in dialog node `effects:`. Nothing extra to wire up.

See [NPC Dialogs](dialogs) and [Dialog Conditions](dialog-conditions) for the config side.
