Skip to content

How to Create a Trading NPC with options

In this guide, you'll learn how to build an NPC that allows players to exchange a specific item (coupon) for one of several options, in this case, an evolution stone of their choice.

This setup uses a behavior tree to offer the selection, confirm the trade, and handle both valid and invalid conditions.

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


Behavior Tree: Select and Confirm the Item

BEHAVIOURTREE

name example_trade_coupon_tree

interaction
    ask "Which stone would you like?" "Sun Stone" "Moon Stone" "Fire Stone" "Thunder Stone" "Water Stone" "Leaf Stone"
        set "stoneName" "Sun Stone"
            set "stoneId" "sun_stone"
                do example_trade_coupon_tree_1
        set "stoneName" "Moon Stone"
            set "stoneId" "moon_stone"
                do example_trade_coupon_tree_1
        set "stoneName" "Fire Stone"
            set "stoneId" "fire_stone"
                do example_trade_coupon_tree_1
        set "stoneName" "Thunder Stone"
            set "stoneId" "thunder_stone"
                do example_trade_coupon_tree_1
        set "stoneName" "Water Stone"
            set "stoneId" "water_stone"
                do example_trade_coupon_tree_1
        set "stoneName" "Leaf Stone"
            set "stoneId" "leaf_stone"
                do example_trade_coupon_tree_1

What this does:

  • Shows a menu to the player asking which stone they want.

  • Stores the stone name and corresponding item ID in temporary variables ($stoneName, $stoneId).

  • Proceeds to the next tree to confirm and process the trade.


Behavior Tree: Process the Trade

BEHAVIOURTREE

name example_trade_coupon_tree_1

interaction
    ask "Are you sure you want $stoneName?" "Yes" "No"
        remove coupon_evolution_stone 1
            give $stoneId 1
                tell "That was one of my favorites… take good care of it!"
                give coupon_evolution_stone 1
            tell "You don’t have a coupon..."

What this does:

  • Asks the player to confirm their choice.

  • If they confirm, the script:

    • Tries to remove 1 coupon_evolution_stone.

    • If successful, gives the selected item ($stoneId).

    • If not, displays a message that the player doesn’t have the coupon and returns the stone (just in case it was already granted).

  • This ensures safe trade logic, preventing duplication or loss.


NPC Definition

NPC

name "example_trader"
model "a_m_m_rurmeth_01"
position 1954.14 3746.38 32.16 300.47

interaction
    knows
        tell "Oh! Hey again. Want more stones?"
            do example_trade_coupon_tree
        tell "Hey friend, want some shiny rocks? I'm Soru. I like picking up stones from the ground."
            do example_trade_coupon_tree

behaviour
    nothing

What this does:

  • When a player talks to example_trader for the first time, he introduces himself and offers a trade.

  • On future interactions, he skips the intro and goes straight to the menu.

  • He doesn’t move or act on his own (behaviour nothing).


Summary

This setup allows you to create item trading NPCs with:

  • Dynamic choice menus

  • Safe item removal and reward

  • Simple structure with reusable logic

It's perfect for:

  • Trading tokens or coupons for rewards

  • Letting players pick what to get at exchange

  • Expanding side quests with optional gear or loot