Wert Npc Dialog System

You can access the setup information you need about this product

INSTALLATION

1 - Upload the script folder to the location of your resources

2 - You can check the config file and customize it according to yourself

3 - Installation successful, have a good funs

TARGET OPTION

If you want use target system for interaction check this snippets

Config.UseTarget = true -- This option need true

And finally, edit the exports that are appropriate for your own target system in editable_client

OX LIB OPTION

If you want to add notifications, text ui or a different ox_lib plugin to the script, please remember this step.

Find this location and change this code like this

wert-dialog/fxmanifest.lua

shared_scripts {
    '@ox_lib/init.lua',
    'config.lua',
}

TEMPLATE

exports['wert-dialog']:CreateNewDialog({
    name = string,
    model = string, -- https://docs.fivem.net/docs/game-references/ped-models/
    coord = vector4 coord,
    job = string,
    dialog_label = string,
    label = string,
    icon = string, -- https://fontawesome.com/icons
    enable_escape_close = false, -- If you want disable escape key for close dialog menu set false (Default true)
    canInteract = function(entity) -- If you want check open state dialog menu use this function. This function help you for much new feature
        return true
    end,
    question = string,
    distance = int,
    answers = {
        {
            text = string,
            event = string,
            color = string, -- If you want special color for the button text
            args = table,
            forceclose = boolean, -- When you select this answer close automaticly dialog ui
            action = function(entity)
            end,
        },
    },
})

EXPORTS

-- Create Dialog Ped
exports['wert-dialog']:CreateNewDialog(table)

-- This export close dialog menu
exports['wert-dialog']:CloseDialogMenu()

-- Get Dialogs Data
exports['wert-dialog']:GetDialogsData()

-- This export open new dialog page (For example, after selecting an option, you can use it to reveal new options again. Opens without closing the menu)
exports['wert-dialog']:OpenNewDialogPage({ 
    question = string,
    answers = {
        {
            text = string,
            event = string,
            color = string, -- If you want special color for the button text
            args = table,
            forceclose = boolean, -- When you select this answer close automaticly dialog ui
            action = function(entity)
            end,
        },
    }
})

EXAMPLES

exports['wert-dialog']:CreateNewDialog({
    name = "example_dialog_1",
    model = "s_m_m_fiboffice_01",
    coord = vector4(-551.57, 285.48, 82.98, 90.05),
    job = "tequila",
    dialog_label = "Tequila Artist",
    label = "Tequila Artist",
    icon = "fa-regular fa-comment-dots",
    question = "Hello, I'm a live music artist how can I help you ?",
    enable_escape_close = false, -- If you want disable escape key for close dialog menu set false (Default true)
    distance = 1.5,
    answers = {
        {
            text = "Can you play something ?",
            action = function()
                exports['wert-dialog']:OpenNewDialogPage({
                    question = "Do you want whick kind music ?",
                    answers = {
                        {
                            text = "Pop Music",
                            forceclose = true,
                            action = function(entity)
                                QBCore.Functions.Notify('Pop Music Selected!')
                            end,
                        },
                        {
                            text = "Rap Music",
                            forceclose = true,
                            action = function(entity)
                                QBCore.Functions.Notify('Rap Music Selected!')
                            end,
                        },
                        {
                            text = "Slow Music",
                            forceclose = true,
                            action = function(entity)
                                QBCore.Functions.Notify('Slow Music Selected!')
                            end,
                        },
                        {
                            text = "I'm Busy. [EXIT]",
                            event = "wert-dialog:client:close-dialog-menu",
                        },
                    }
                })
            end,
        },
        {
            text = "I'm Busy. [EXIT]",
            event = "wert-dialog:client:close-dialog-menu",
            args = {
                music = "url"
            }
        },
    },
})

exports['wert-dialog']:CreateNewDialog({
    name = "example_dialog_2",
    model = "s_m_m_autoshop_02",
    coord = vector4(-511.84, -1737.83, 19.27, 326.59),
    job = "mechanic",
    dialog_label = "Junkyard Attendant",
    label = "Junkyard Attendant",
    icon = "fa-regular fa-comment-dots",
    enable_escape_close = false, -- If you want disable escape key for close dialog menu set false (Default true)
    canInteract = function(entity)
        return true
    end,
    question = "Hello, do you want to get the car shredding task available ?",
    distance = 1.5,
    answers = {
        {
            text = "Take the task",
            event = "wert-chopshop:start-job",
            forceclose = true, -- When you select this answer close automaticly dialog ui
        },
        {
            text = "I'm Busy. [EXIT]",
            color = "red",
            event = "wert-dialog:client:close-dialog-menu",
        },
    },
})

OPEN FILES

Config file

Config = {}

Config.Framework = "qb" -- "qb" | "esx" | "standalone"

Config.UseTarget = true -- Target options and options in editable_client.lua

Config.DefaultDistance = 2.0 -- If you dont set a distance value in create template this number active

Config.DebugPoly = false -- Draw Zones

Config.NoTargetInteraction = "textui" -- Options : "textui" | "drawtext" | "helpnotification"

Config.DrawTextPedZOffSett = 1.1 -- Drawtext coord z offset (+)

Config.StartCameraCalculateOffsets = {-0.15, 2.0, 0.7}

Config.CreateNpcZOffset = 1.0 -- Npc spawn coord offset (-)

Config.CamRotHeadingOffset = 180

Config.NoTargetInteractionKey = 38 -- https://docs.fivem.net/docs/game-references/controls/

Config.NoTargetInteractionKeyLabelPreset = "[E] %s" -- Script Format this automaticly

Defaults file

```lua
-- If you want create here default dialogs quickly (Or If you want use exports in another resources you can access more detail in documents)
local DefaultDialogs = {
    -- Template same like export
    --[[ {
        name = string,
        model = string, -- https://docs.fivem.net/docs/game-references/ped-models/
        coord = vector4 coord,
        job = string,
        dialog_label = string,
        label = string,
        icon = string, -- https://fontawesome.com/icons
        enable_escape_close = false, -- If you want disable escape key for close dialog menu set false (Default true)
        canInteract = function(entity) -- If you want check open state dialog menu use this function. This function help you for much new feature
            return true
        end,
        question = string,
        distance = int,
        answers = {
            {
                text = string,
                event = string,
                color = string, -- If you want special color for the button text
                args = table,
                forceclose = boolean, -- When you select this answer close automaticly dialog ui
                action = function(entity)
                end,
            },
        },
    }, ]]
}




-- # Thread
CreateThread(function()
    for i=1, #DefaultDialogs do
        local row = DefaultDialogs[i]
        exports['wert-dialog']:CreateNewDialog(row)
        Wait(100)
    end
end)
```

Editable client file

local Framework = nil
-- If you want add more framework here. If you use another framework like ox or another ...
if Config.Framework == "qb" then
    Framework = exports['qb-core']:GetCoreObject()
elseif Config.Framework == "esx" then
    Framework = exports["es_extended"]:getSharedObject()
end

function ShowTextUi(text)
    -- If you use another system for text ui, you can change here like ox_lib or etc.
    -- If you want ox_lib you can check wert documentions and look ox_lib install steps
    exports['qb-core']:DrawText(text, 'left')
end
function HideTextUI()
    -- If you use another system for text ui, you can change here like ox_lib or etc.
    -- If you want ox_lib you can check wert documentions and look ox_lib install steps
    exports['qb-core']:HideText()
end

function NoTargetJobCheck(job)
    if not job then return true end
    if Config.Framework == "standalone" then
        return true
    elseif Config.Framework == "qb" then
        local ply_job = Framework.Functions.GetPlayerData().job.name
        if ply_job == job then
            return true
        else
            return false
        end
    elseif Config.Framework == "esx" then
        local ply_job = Framework.GetPlayerData().job.name
        if ply_job == job then
            return true
        else
            return false
        end
    end
end

function NoTargetCanInteract(data)
    if data.canInteract and not data.canInteract(data.entity) then return false end
    return true
end

function DrawText3D(x, y, z, text)
    -- Use local function instead
    SetTextScale(0.35, 0.35)
    SetTextFont(4)
    SetTextProportional(1)
    SetTextColour(255, 255, 255, 215)
    SetTextEntry('STRING')
    SetTextCentre(true)
    AddTextComponentString(text)
    SetDrawOrigin(x, y, z, 0)
    DrawText(0.0, 0.0)
    local factor = (string.len(text)) / 370
    DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
    ClearDrawOrigin()
end

function CustomTargetEntity(data)
    exports["qb-target"]:AddTargetEntity(data.entity, {
        options = {
            {
                event = data.event,
                dialogname = data.dialogname,
                icon = data.icon,
                label = data.label,
                job = data.job,
                canInteract = data.canInteract,
                debugPoly = Config.DebugPoly,
            },
        },
        distance = data.distance
    })
end

function RemoveTargetEntity(entities, labels)
    exports["qb-target"]:RemoveTargetEntity(entities, labels)
end

-- When dialog menu open disable this actions
function CustomDisableThisActions()
    DisablePlayerFiring(PlayerPedId(), true)
    DisableControlAction(0, 24, true) -- Attack
    DisableControlAction(0, 257, true) -- Attack 2
    DisableControlAction(0, 25, true) -- Aim
    DisableControlAction(0, 263, true) -- Melee Attack 1
    DisableControlAction(0, 56, true) -- F9
    DisableControlAction(0, 45, true) -- Reload
    DisableControlAction(0, 22, true) -- Jump
    DisableControlAction(0, 44, true) -- Cover
    DisableControlAction(0, 37, true) -- Select Weapon
    DisableControlAction(0, 288,  true) --F1
    DisableControlAction(0, 289, true) -- F2
    DisableControlAction(0, 170, true) -- F3
    DisableControlAction(0, 167, true) -- F6
    DisableControlAction(0, 31, true) -- S
    DisableControlAction(0, 32, true) -- W
    DisableControlAction(0, 34, true) -- A
    DisableControlAction(0, 30, true) -- D
    DisableControlAction(0, 0, true) -- Disable changing view
    DisableControlAction(0, 26, true) -- Disable looking behind
    DisableControlAction(0, 73, true) -- Disable clearing animation
    DisableControlAction(2, 199, true) -- Disable pause screen
    DisableControlAction(0, 59, true) -- Disable steering in vehicle
    DisableControlAction(0, 71, true) -- Disable driving forward in vehicle
    DisableControlAction(0, 72, true) -- Disable reversing in vehicle
    DisableControlAction(0, 47, true)  -- Disable weapon
    DisableControlAction(0, 264, true) -- Disable melee
    DisableControlAction(0, 257, true) -- Disable melee
    DisableControlAction(0, 140, true) -- Disable melee
    DisableControlAction(0, 141, true) -- Disable melee
    DisableControlAction(0, 142, true) -- Disable melee
    DisableControlAction(0, 143, true) -- Disable melee
    DisableControlAction(0, 75, true)  -- Disable exit vehicle
    DisableControlAction(0, 301, true)  -- Disable exit vehicle
    DisableControlAction(27, 75, true) -- Disable exit vehicle
end

FINISH

Last updated