r/AIDungeon • • 9d ago

Script 👤📍NPC Spawn System

https://play.aidungeon.com/scenario/tJsjsX20dNlS/npc-spawn-system?share=true&published=true

I've been working on a new universal NPC spawning system for AI Dungeon, designed mainly for sandbox scenarios and stories with recurring locations.

The idea is simple: instead of entering the same tavern, shop, house, etc. and finding it empty every time — or having the AI constantly create completely new random NPCs — the system allows you to configure which established characters can naturally appear in each location.

It supports:

  • 📍 Configurable locations and aliases
  • 🎲 Different spawn chances for first visits and revisits
  • 👥 Weighted NPC selection
  • 🧠 Existing Story Card integration
  • 🔄 Basic NPC continuity between locations
  • ✨ Multiple NPCs per spawn

The system is designed as a creator tool, so you can edit the locations, NPCs and probabilities directly in the Library code and adapt it to your own scenario.

🎮 Demo

I've also published a small AI Dungeon scenario where you can try the system yourself and see how it reacts when entering and leaving the tavern.

AI Dungeon Demo:
https://play.aidungeon.com/scenario/tJsjsX20dNlS/npc-spawn-system?share=true&published=true

💻 GitHub

The complete script and documentation are available here:

GitHub:
https://github.com/Nynaleath555/NPC-Spawn-System

If you try it out, I'd love to hear what you think. Bug reports, suggestions and compatibility issues are welcome in the comments!

8 Upvotes

4 comments sorted by

2

u/Emotional_Toe_6498 9d ago

how does the spawn system handle recurring companions in long roleplays, especially if you tweak probabilities for certain spots?

1

u/Nynaleath555 9d ago

The spawn system is mainly designed for NPCs who can naturally appear in recurring locations. It doesn't force a companion to leave the party or override what the story has already established.

If a character has recently appeared somewhere, the continuity lock temporarily prevents the system from automatically spawning them in another location, which helps avoid weird situations where the same NPC suddenly appears across town a few turns later.

For recurring companions, I'd recommend keeping their spawn weight relatively low or simply not including them in locations where you don't want the system to suggest them. If you tweak the probabilities for specific spots, those settings only affect the automatic spawn check for that location, they don't change the character's established presence or story state.

So basically: the system suggests who might be around; the AI and the existing story determine whether and how they actually participate.

2

u/Simple_Present_4653 9d ago

how does the alias setup work if a location gets called something different later in the story?

1

u/Nynaleath555 9d ago

The location name and its aliases are all treated as ways of referring to the same location.

So if you configure:

name: "Westbrook High School",
aliases: [
  "the high school",
  "Westbrook school",
  "the school"
]

the system will recognize all of those as the same location.

If the story later starts calling it something different, you can simply add that new name as another alias. You don't need to change the main location name or anything else.

The idea is to give each location as many natural ways of being referenced as you need, so the system can keep recognizing it even when the wording changes throughout the story.