NPC Interaction

The NPC Interaction module provides a highly immersive, cinematic dialogue system for your server. When a player interacts with an NPC, the script automatically aligns the player, creates a cinematic camera angle focusing on the NPC, and displays a sleek UI for dialogues and options. It fully supports nested submenus, conditional options, and event triggering.


📚 Available Exports

RegisterNpcInteract

Registers an interaction menu to a specific NPC entity. This must be called before attempting to show the menu.

Syntax:

Parameters:

Parameter

Type

Description

entity

integer

The network ID or handle of the ped/entity.

data

table

The configuration object containing dialogues, styling, and options.

ShowNpcInteract

Opens a previously registered NPC interaction menu.

Syntax:

Parameters:

Parameter

Type

Description

id

string

The unique ID defined in your RegisterNpcInteract data table.

focusIndex

integer (Optional)

The index of the option you want to be pre-selected/focused.

HideNpcInteract

Forcefully closes the currently open NPC interaction menu.

Syntax:

Parameters:

Parameter

Type

Description

runOnExit

boolean

If true, triggers the onExit callback defined in the NPC's data table.


⚙️ Configuration Objects

The data Table

This table configures the overarching menu for the NPC.

Property

Type

Description

id

string

Required. A unique identifier for this interaction menu.

colors

table

Optional. Override default UI colors (colorPrimary, colorSecondary, colorText).

dialogues

table

An array of strings. The menu will pick one at random to display as a greeting.

menu

string

Optional. The id of a parent menu. Enables native "Back" button functionality.

onExit

function

Optional. A callback triggered when the menu is closed.

options

table

Required. An array of Option objects.

The Option Object

Each item inside the options array represents a clickable button.

Property

Type

Description

label

string

Required. The text displayed on the button.

icon

string

FontAwesome icon name (e.g., car, comments, person-walking-arrow-right).

iconColor

string

Hex code to color the icon (e.g., #3498db).

isVisible

function

Returns a boolean. If false, the option is completely hidden.

disabled

boolean

If true, the option is shown but grayed out/unclickable.

canInteract

function

Returns a boolean. Overrides disabled dynamically based on logic.

onSelect

function

Callback triggered when the player clicks this option.

event

string

A Client event to trigger when clicked.

serverEvent

string

A Server event to trigger when clicked.

menu

string

Automatically opens another registered NPC menu id (acts as a submenu).

Note on Navigation: You can navigate to a submenu using the menu = 'target_id' property inside an option, or manually inside the onSelect function by calling exports['ak47_lib']:ShowNpcInteract('target_id').


💡 Examples

Example 1: Basic Shop Ped

A simple interaction with a single ped offering basic choices.

Example 2: Dialogue Trees (Submenus & Back Buttons)

This example demonstrates how to create a conversation tree where the player can ask questions, go into a submenu, and hit a "Back" button to return to the main choices.

Example 3: Conditional & Restricted Options

Sometimes you only want specific players (like police) to see an option, or you want to show an option but disable it if they don't have enough money.

Last updated