DynamicEncounters Script

DynamicEncounters DynamicEncounters is a reusable AI Dungeon encounter system that brings Story Card characters, objects, locations, and events into the story dynamically. Instead of manually deciding when an encounter should appear, the script automatically selects configured Story Cards based on random ambient encounters or player-triggered encounter groups. Selected encounters are introduced naturally into the current scene, with optional randomized activities to make recurring characters and background elements feel more alive. How It Works The script automatically creates three management Story Cards: DynamicEncounters Config — Controls encounter chances, cooldowns, recent-memory, and debugging. DynamicEncounters Activities — Contains the pool of activities that can be randomly assigned to encounters. DynamicEncounters Triggers — Defines encounter groups and the words that activate them. Encounter Story Cards are configured by adding a DynamicEncounters: JSON block to their Notes. By default, an encounter card can simply use: DynamicEncounters:{} This places it in the default group with a weight of 1. Ambient Encounters When the player is exploring normally, the script periodically has a chance to select an encounter from the default group. The default chance is 8% per action, with a configurable cooldown preventing encounters from appearing too frequently. Triggered Encounters Creators can make specialized encounter groups such as merchants, knights, events, or festival. A group's trigger words determine when it becomes eligible. For example, a group could activate when the player writes words such as market, shop, or merchant. Triggered groups take priority over ambient encounters and can have their own encounter probability. Encounter Variety Each encounter can have a weight, allowing common encounters to appear more often than rare ones. The system also remembers recently selected encounters and temporarily excludes them, reducing repetitive appearances. For character Story Cards, the script tells the AI to naturally introduce the character into the current scene and optionally gives them a randomized activity such as browsing something nearby, talking with another person, or looking for a friend. The character is not forced to approach or interact with the player—the AI decides how naturally they fit into the scene. Setting It Up Add the script to your AI Dungeon scenario. Run the scenario once so the three DynamicEncounters management cards are created automatically. Add the characters, objects, locations, or events you want the system to use as Story Cards. Add a DynamicEncounters: configuration block to each card's Notes. Optionally assign the card to a group, give it a weight, or provide custom activities. Edit DynamicEncounters Config and DynamicEncounters Triggers to customize encounter frequency and trigger behavior. For example: DynamicEncounters:{ "groups":["merchants"], "weight":2 } Then configure the merchants group in DynamicEncounters Triggers with appropriate trigger words. Once configured, the system handles the encounter selection and introduction automatically. This makes it especially useful for scenarios with large casts, explorable locations, wandering NPCs, random events, or lots of optional content without requiring the creator to manually script every encounter.

Cover art for DynamicEncounters Script, an encounters script on AI Dungeon