πŸ“ƒCreate Dialog

Creating Dialogs

1. Dialog Structure

Each dialog is created using the following function:

exports['koja-dialogs']:CreateDialog({
    id         = "<unique_dialog_id>",
    npc        = "<npc_model>",
    coords     = vector4(<x>, <y>, <z>, <heading>),
    name       = "<npc_display_name>",
    message    = "<initial_npc_message>",
    tag        = "<display_tag_above_npc>",
    animations = {
        { type = "<animation_type>", dict = "<animation_dict>", anim = "<animation_name>" },
        { type = "<animation_type>", dict = "<animation_dict>", anim = "<animation_name>" }
    },
    actions    = {
        {
            label          = "<button_label>",
            player_message = "<message_player_says>",
            onclick        = {
                message = "<npc_response_after_selection>",
                actions = {
                    { ... }  -- nested actions for more dialogue branches
                },
                open = {
                    window = "<window_type>",   -- "shop", "market" or "crafting"
                    data   = {
                        -- depends on window type
                    }
                }
            },
            close = <boolean>  -- close dialog after clicking?
        },
        -- more actions
    }
})

Fields to highlight:

  • id (string): Unique identifier for the dialog.

  • npc (string): Model name of the NPC (e.g., "g_m_m_chicold_01").

  • coords (vector4): Position in the world: vector4(x, y, z, heading).

  • name (string): Display name for the NPC in the dialog header.

  • message (string): The NPC’s initial message when the dialog opens.

  • tag (string): A label shown above the NPC (e.g., β€œDealer”, β€œDistributor”, β€œOG”).

  • animations (table): List of animation objects:

    • type (string): Custom label for the animation (e.g., "idle", "active").

    • dict (string): The Animation Dictionary to load.

    • anim (string): The Animation Name.

  • actions (table): Array of player-action objects:

    • label (string): Text displayed on the button.

    • player_message (string): The player’s dialogue line.

    • onclick (table):

      • message (string): NPC’s response after clicking.

      • actions (table): (Optional) Array of nested actions for further dialogue.

      • open (table): (Optional) UI window to open, with:

        • window (string): "shop", "market", or "crafting".

        • data (table): Data structure depending on the window type.

    • close (boolean): Whether to close the dialog after this action.


2. Shop Window

The Shop window displays a list of items (e.g., weapons) that the player can purchase. Its data block looks like this:

Example: Dialog with Shop Window (dealer-1)

Notes:

  • Clicking Buy Drugs responds that the NPC only sells guns.

  • In that branch, Ask about guns opens the Shop window showing available weapons.

  • If Go away is chosen, the dialog closes.

3. Market Window

The Market window is used for trading resources (e.g., narcotics). Its data structure is identical to Shop, but the context is resource exchange:

Example: Dialog with Market Window (dealer-2)

Notes:

  • The dialog asks if the player sold the drugs (β€œYou sold the dope?”).

  • If Yes, Give the dope opens the Market window for finalizing the transaction.

4. Crafting Window

The Crafting window combines raw materials into finished goods. It uses data.items, built through buildRequired():

Example: Dialog with Crafting Window (dealer-3)

Notes:

  • Player initiates with Hello! asking to pack weed.

  • After confirmation, Pack weed leads to Give the dope, which opens the Crafting window.

  • buildRequired() builds the internal format for recipes.

5. Summary of Fields and Window Differences

Field / Context
Shop
Market
Crafting

window

"shop"

"market"

"crafting"

Data Structure Key

data.products

data.products

data.items (uses buildRequired)

Example Product/Recipe

{ respname = "weapon_pistol", price = 14250, label = "Pistol", desc = "weapon" }

{ respname = "packed_weed", price = 50, label = "Weed", desc = "Narcotics" }

{ respname = "packed_weed", label = "Packed Weed", category = "Narcotics", required = { { respname = "weed", amount = 5 }, { respname = "plastic_bag", amount = 1 } } }

Use Case

Buying weapons or other items from an NPC

Selling or buying raw resources (e.g., narcotics)

Last updated