Skip to content

How to Create a Trainer NPC That Battles You

This guide explains how to build a Trainer NPC using .uri, capable of engaging players in a Pokémon battle. We’ll go over the interaction logic, Pokémon team setup, and the trainer configuration step by step.

Before continuing, make sure you are familiar with the basics of .uri and understand how interactions, behaviors, and action trees work.


NPC Definition

First, define your NPC with a name, model, and position, and configure their interaction and behavior. To learn more about diferent actions see Core/Monsters > Extensions > Actions.

Idea 1: Aggresive Trainer

NPC

name "example_trainer"
model "a_m_m_hillbilly_02"
position 2404.86 3106.31 48.21 39.68

interaction
    hasLostPokemonBattle
        tell "Damn it... it's all the Pokémon's fault."
        startPokemonBattle

behaviour
    forcePokemonBattle
        nothing
        wander 2404.86 3106.31 48.21 10 5 5

What this does:

  • The NPC automatically starts a battle with any nearby player who hasn’t defeated them yet.

  • The forcePokemonBattle action is part of the behavior tree, meaning the trainer is actively checking for players at all times.

  • If the player already lost a battle, the interaction block provides fallback dialogue and allows them to interact again (e.g., to talk).

  • If no players are nearby or eligible, the trainer will wander around within a defined radius.

  • No player interaction is required, the NPC will challenge you on sight.

Idea 2: Quest Trainer

NPC

name "example_trainer"
model "a_m_m_hillbilly_02"
position 2404.86 3106.31 48.21 39.68

interaction
    hasLostPokemonBattle
        tell "Damn it... it's all the Pokémon's fault."
        hasQuestStarted example_quest
            tell "You shouldn’t have come. We’re going to crush you."
                startPokemonBattle
            tell "Get lost."

behaviour
    wander 2404.86 3106.31 48.21 10 5 5

What this does:

  • This NPC only engages in battle if a specific quest (example_quest) is currently active for the player.

  • If the player has already lost a battle against this trainer, they will see a defeat-related message.

  • If the quest is active, the trainer warns the player and initiates a Pokémon battle.

  • If the quest is not active, the NPC dismisses the player with a message like “Get lost.”

  • The wander behavior makes the NPC move freely within a defined radius to appear more alive in the world.

  • This is a great pattern for story-driven trainers who should only challenge players at specific points in the game.


Defining the Pokémon Team

Then you define each Pokémon used in the battle. These are referenced later in the trainer definition. See more at Monsters > Extensions > Constructors > POKEMON.

POKEMON

id example_trainer_pokemon_1
name koffing
level 16
moves "smog" "tackle" "poison-gas" "haze"

POKEMON

id example_trainer_pokemon_2
name misdreavus
level 16
moves "spite" "astonish" "confuse-ray" "pain-split"

POKEMON

id example_trainer_pokemon_3
name murkrow
level 16
moves "peck" "astonish" "haze" "pursuit"

POKEMON

id example_trainer_pokemon_4
name houndour
level 20
moves "ember" "bite" "roar" "smog"

POKEMON

id example_trainer_pokemon_5
name haunter
level 20
moves "shadow-ball" "hypnosis" "confuse-ray" "night-shade"

Each Pokémon block defines:

  • A unique id

  • Its name (as defined in this wiki or in the files)

  • The level

  • Up to 4 moves (using then names defined in this wiki or in the files)


Trainer Configuration

Finally you define the TRAINER block that ties the NPC and their Pokémon together for the battle logic. See more at Monsters > Extensions > Constructors > TRAINER.

TRAINER

npc example_trainer
pokemon example_trainer_pokemon_1 example_trainer_pokemon_2 example_trainer_pokemon_3 example_trainer_pokemon_4 example_trainer_pokemon_5

started "I am going to crush you."
wins "You are nothing!"
loses "Damn it... it’s all the Pokémon’s fault."
draws "Damn it... it’s all the Pokémon’s fault."
stopped "There was a strange storm..."

What each field means:

  • npc: References the NPC that will use this trainer profile.

  • pokemon: The list of Pokémon (previously defined by ID) that will be used in battle.

  • started: Message shown when the battle begins.

  • wins / loses / draws: Post-battle outcomes shown depending on the result.

  • stopped: Message shown if the battle is aborted or interrupted.


Summary

With .uri, you can easily create a wide variety of Trainer NPCs, each with unique behavior patterns:

  • Use startPokemonBattle inside interaction to make trainers respond to player dialogue or quest conditions.

  • Use forcePokemonBattle in the behaviour tree for aggressive trainers that initiate battles automatically when players approach.

  • Combine logic like hasQuestStarted or hasLostPokemonBattle to fully control when and how a trainer engages in battle.

  • Use TRAINER and POKEMON definitions to customize teams, battle dialogue, and outcomes.

  • Add wander for immersion and to make your NPCs feel more dynamic in the world.

This system is modular, readable, and powerful, giving you full control over how trainers behave and how players interact with them. With just a few lines, you can create complex and engaging combat encounters that respond to the player’s progress and choices.