NPC DIalog

Overview

This documentation covers the setup, configuration, and usage of the CS-Dialog script.


Database Setup

Before using the script, ensure your database has the necessary table (This is automaticly setup inside the script but incase you encounter any issues you can manually import this):

CREATE TABLE dialog_reputation (
    id INT AUTO_INCREMENT PRIMARY KEY,
    identifier VARCHAR(255) NOT NULL,
    dialog_id VARCHAR(255) NOT NULL,
    reputation INT DEFAULT 0
);

This table stores player reputations for specific dialog IDs.


Installation and Configuration

Server Setup

  1. Place the cs-dialog resource in your resources folder.

  2. Ensure the resource name is exactly cs-dialog.

  3. Add ensure cs-dialog to your server.cfg.


Exported Functions

The script provides several exports for managing reputation:

Add Reputation

Adds a specified amount of reputation to a player for a dialog.

exports["cs-dialog"]:addReputation(identifier, dialogId, amount)
  • identifier: Player's identifier.

  • dialogId: The ID of the dialog.

  • amount: Amount to add.

Set Reputation

Sets a player's reputation for a dialog to a specific value.

exports["cs-dialog"]:setReputation(identifier, dialogId, amount)
  • identifier: Player's identifier.

  • dialogId: The ID of the dialog.

  • amount: New reputation value.

Remove Reputation

Removes a specified amount of reputation from a player for a dialog.

exports["cs-dialog"]:removeReputation(identifier, dialogId, amount)
  • identifier: Player's identifier.

  • dialogId: The ID of the dialog.

  • amount: Amount to remove.


Example Usage

Ped and Dialog Example

Below is an example of how to create an interactive ped with a dialog.

CreateThread(function()
    local pedCoords = vector3(252.6678, -1671.2336, 29.6632)
    local pedHeading = 188.1727
    local pedModel = `g_m_y_salvagoon_01`

    RequestModel(pedModel)
    while not HasModelLoaded(pedModel) do
        Wait(0)
    end

    local ped = CreatePed(4, pedModel, pedCoords.x, pedCoords.y, pedCoords.z - 1.0, pedHeading, false, true)
    SetEntityInvincible(ped, true)
    SetBlockingOfNonTemporaryEvents(ped, true)
    FreezeEntityPosition(ped, true)

    exports.ox_target:addLocalEntity(ped, {{
        name = "ped_dialog_MS13",
        label = "Talk to MS-13 Leader",
        icon = "fa-solid fa-skull-crossbones",
        onSelect = function()
            exports["cs-dialog"]:openDialog({
                id = "ms13_job_dialog",
                ped = ped,
                name = "Big Joe (MS-13 Leader)",
                text = "Yo, I'm Big Joe. Ready to prove yourself?",
                theme = "blue",
                options = {{
                    text = "Sign me up!",
                    response = "Welcome to the crew! Let's get started.",
                    autoClose = true,
                    closeDelay = 3000,
                    onSelect = function()
                        print("Player joined MS-13")
                    end
                }, {
                    text = "What's the latest mission?",
                    repNeeded = 20,
                    lowRepResponse = "You need more reputation to take on these missions.",
                    nextOptions = {{
                        text = "Earn reputation",
                        response = "Here are some ways to gain rep:",
                        nextOptions = {{
                            text = "Help the local vendors",
                            response = "Assist the shopkeepers nearby.",
                            autoClose = true,
                            closeDelay = 3000,
                            onSelect = function()
                                TriggerEvent("ms13:helpVendors")
                            end
                        }}
                    }}
                }, {
                    text = "I'm outta here.",
                    response = "Catch you later. Stay out of trouble.",
                    autoClose = true,
                    closeDelay = 2000
                }}
            })
        end
    }})
    SetModelAsNoLongerNeeded(pedModel)
end)

Customization

Themes

Available dialog themes:

  • blue

  • orange

  • red

  • purple

  • green

  • black

  • yellow

  • pink

Specify the theme in the openDialog function using:

theme = "blue"

Notifications

Modify Config.Notify in the client script to customize notifications.

Camera Settings

Adjust Config.CamOffset and Config.CamTransitionTime in the client script for camera positioning and transitions.


Important Notes

  • The resource must be named cs-dialog.

  • Players can only interact with the script via provided examples and exports.

  • Ensure ox_lib is installed and working.


Configuration

Example configuration:

Config = {}

-- Camera offsets for your NPC camera
Config.CamOffset = { x = 0.0, y = 0.6, z = 0.6 }
Config.CamTransitionTime = 500

-- Notification system type:
-- "ox", "qb", "esx", or "custom"
Config.NotificationType = "ox"

function Config.Notify(msg)
    if Config.NotificationType == "ox" then
        exports.ox_lib:notify({ description = msg, type = 'inform' })
    elseif Config.NotificationType == "qb" then
        QBCore.Functions.Notify(msg)
    elseif Config.NotificationType == "esx" then
        ESX.ShowNotification(msg)
    elseif Config.NotificationType == "custom" then
        exports.my_notify:CustomNotify(msg)
    end
end

For any additional help or support, feel free to reach out in our discord server.

Last updated