> For the complete documentation index, see [llms.txt](https://5scripts-1.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://5scripts-1.gitbook.io/docs/assets/5s_dialogs/usage.md).

# Usage

### Basic Dialog Structure

```lua
    local dialogData = {
        id = "example_dialog", -- Unique dialog identifier
        title = "NPC Name", -- NPC's name
        role = "NPC Role", -- NPC's role/occupation
        roleColor = "#ff000077", -- Role badge color
        roleBorderColor = "#ff0000", -- Role badge border color
        text = "Welcome message", -- Initial greeting text
        ped = ped, -- NPC entity object
        options = {
            {
                title = "Option 1", -- Dialog option title
                description = "Option 1 description", -- Brief description
                text = "NPC response text", -- Text shown when option is selected
                onSelect = function()
                    -- Code executed when option is selected
                end,
                next = { -- Sub-menu options
                    {
                        title = "Sub-option 1",
                        description = "Sub-option 1 description",
                        text = "Response for sub-option 1",
                        onSelect = function()
                            -- Code executed when sub-option is selected
                        end,
                        close = true -- Closes dialog when selected and typing text will be end
                    }
                }
            }
        }
    }
```

### Properties

* `id`: Unique identifier for the dialog
* `title`: NPC's name displayed in dialog
* `role`: NPC's role or occupation
* `roleColor (optional)`: Displayed badge color
* `roleBorderColor (optional)`: Displayed badge border color
* `text`: Initial greeting message
* `ped`: Reference to the NPC entity
* `options`: Array of dialog options

#### Option Properties

* `title`: Option text shown in menu
* `description (optional)`: Additional description text
* `text`: NPC's response when selected
* `onSelect(close?, response?) (optional)`: Function triggered on selection
  * `close() (optional)` : Close dialog immediately
  * `response(text) (optional)` : Update dialog text
* `next (optional)`: Sub-menu options array
* `close (optional)`: Boolean to close dialog after selection

### Example Usage

```lua
    local dialogId = exports["5s_dialogs"]:CreateDialog(dialogData)
    exports["5s_dialogs"]:ShowDialog(dialogId)
```

### Exports

#### CreateDialog

```lua
    exports["5s_dialogs"]:CreateDialog(dialogData)
```

This function creates a new dialog and returns the dialog id

#### ShowDialog

```lua
    exports["5s_dialogs"]:ShowDialog(dialogId)
```

This function shows the dialog with the given id

#### RemoveDialog

```lua
    exports["5s_dialogs"]:RemoveDialog(dialogId, removePed)
```

This function removes the dialog with the given id, if you send second true, ped will be removed


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://5scripts-1.gitbook.io/docs/assets/5s_dialogs/usage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
