CodeWorks
YoutubeDiscordTebex
  • Welcome!
  • Main
    • How can i download my script
    • How can i transfer my script
    • Whats escrow system?
  • Errors
    • You lack the required entitlement to use cdw-*
  • Scripts
    • Boss Menu
      • Installation
      • Configuration
      • Language Files
      • Events / Export List
      • Editable Files
        • sv_utils.lua
        • cl_utils.lua
        • cl_mugshot.lua
    • Hud System
      • Installation
      • Configuration
      • Language Files
      • Events / Export List
      • Editable Files
        • sv_utils.lua
        • cl_utils.lua
      • Integrations
        • QB Core
          • Notification
          • Progressbar
        • ESX
          • Notification
          • Progressbar
        • ox_lib
          • Notification
          • Progressbar
  • GPS & Bodycam
    • GPS System
      • Installation
      • Configuration
      • Language Files
      • Editable Files
        • sv_utils.lua
        • cl_utils.lua
    • Bodycam System
      • Installation
      • Configuration
      • Language Files
      • Editable Files
        • sv_utils.lua
        • cl_utils.lua
Powered by GitBook
On this page
  1. Scripts
  2. Boss Menu
  3. Editable Files

cl_utils.lua

Framework = "qb"
local Core
local loadEvent = "QBCore:Client:OnPlayerLoaded"
local unloadEvent = "QBCore:Client:OnPlayerUnload"
local jobEvent = "QBCore:Client:OnJobUpdate"

if GetResourceState("qbx_core") == "started" or Config.framework == "qbx" then
    Framework = "qbx"
    Core = exports.qbx_core
    lib.print.info("Detected Framework: QBOX")
    unloadEvent = 'qbx_core:client:playerLoggedOut'

elseif GetResourceState("es_extended") == "started" or Config.framework == "esx" then
    Framework = "esx"
    Core = ESX
    loadEvent = 'esx:playerLoaded'
    unloadEvent = "esx:onPlayerLogout"
    jobEvent = "esx:setJob"
    lib.print.info("Detected Framework: ESX")
elseif GetResourceState("qb-core") == "started" or Config.framework == "qb" then 
    Framework = "qb"
    Core = exports['qb-core']:GetCoreObject()
    lib.print.info("Detected Framework: QB")
else
    Framework = Config.framework
end 

RegisterNetEvent(loadEvent, function()
    LoadFunc()
end)

RegisterNetEvent(jobEvent, function()
    UpdatePlayerData()
end)

function GetPlayerCharName()
    if Framework == "qb" then 
        local Player = Core.Functions.GetPlayerData()
        local firstName = Player.charinfo.firstname
        local lastName = Player.charinfo.lastname
        return firstName .. " " .. lastName
    elseif Framework == "esx" then 
        local firstName = Core.PlayerData.firstName
        local lastName = Core.PlayerData.lastName
        return firstName .. " " .. lastName
    elseif Framework == "qbx" then 
        local Player = Core:GetPlayerData()
        local firstName = Player.charinfo.firstname
        local lastName = Player.charinfo.lastname
        return firstName .. " " .. lastName
    else 
        --Custom Framework here
        return "Unknown"
    end
end

function GetPlayerJob()
    if Framework == "qb" then 
        local Player = Core.Functions.GetPlayerData()
        local job = Player.job.name
        return job
    elseif Framework == "esx" then 
        local job = Core.PlayerData.job.name
        return job
    elseif Framework == "qbx" then 
        local Player = Core:GetPlayerData()
        local job = Player.job.name
        return job
    else 
        --Custom Framework here
        return "Unknown"
    end
end

function IsPlayerBoss()
    local jobName = ""
    if Framework == "qb" then 
        local Player = Core.Functions.GetPlayerData()
        return Player.job.isboss
    elseif Framework == "esx" then 
        local playerData = ESX.GetPlayerData()
        if playerData and playerData.job and playerData.job.grade_name then
            return playerData.job.grade_name == "boss"
        else
            return false
        end
    elseif Framework == "qbx" then 
        local Player = Core:GetPlayerData()
        return Player.job.isboss
    else 
        --Custom Framework here
        return "Unknown"
    end
end

function Notify(text, type)
    local jobName = ""
    if Framework == "qb" then 
        Core.Functions.Notify(text, type)
    elseif Framework == "esx" then 
        Core.ShowNotification(text)
    elseif Framework == "qbx" then 
        Core:Notify(text, type)
    else 
        --Custom Framework here
    end
end

function checkItem(itemName)
    if Framework == "qb" then 
        local hasItem = Core.Functions.HasItem(itemName)
        return hasItem
    elseif Framework == "esx" then 
        local hasItem = Core.SearchInventory(itemName, 1)
        return hasItem >= 1
    elseif Framework == "qbx" then 
        local count = exports.ox_inventory:Search('count', itemName)
        return count >= 1
    else 
        --Custom Framework here
    end
end

RegisterNUICallback("GetGrades", function(data, cb)
    if Framework == "qb" then
        local jobName = GetPlayerJob()
        local job = Core.Shared.Jobs[jobName]

        if not job then
            cb({})
            return
        end

        local grades = {}

        for grade, info in pairs(job.grades) do
            grades[grade] = {
                name = info.name .. (info.isboss and " (boss)" or ""),
                salary = info.payment,
                isBoss = info.isboss
            }
        end

        cb(grades)
    elseif Framework == "qbx" then
        local job = exports.qbx_core:GetJob(Core.GetPlayerData().job.name)
        local grades = {}
        for k,v in pairs(job.grades) do
            grades[k] = {
                salary = v.payment,
                name = v.isboss and v.name .. " (boss)" or v.name,
            }
        end
        cb(grades)
    elseif Framework == "esx" then
        local jobName = GetPlayerJob()

        lib.callback("cdw-bossmenu:GetJobGrades", false, function(grades)
            cb(grades or {})
        end, jobName)
    else
        --your code
    end
end)

RegisterNUICallback("OpenStash", function(data, cb)
    if GetResourceState("ox_inventory") == "started" then 
        local sa = lib.callback.await('cdw-bossmenu:OpenStash', false, data)
        if sa then
            exports.ox_inventory:openInventory('stash', GetPlayerJob() .. "stash")
            cb(true)
        else
            cb(false)
        end
    elseif GetResourceState("qb-inventory") == "started" then
        TriggerServerEvent('cbw-bossmenu:OpenQBInventory', GetPlayerJob() .. "stash")
        cb(true)
    end
end)

local sleep = 1000
CreateThread(function()
    if Config.Interaction == "target" then
        for k,v in pairs(Config.AccesCoords) do
            if GetResourceState('ox_target') == 'started' then
                exports.ox_target:addBoxZone({
                    coords = v.coord,
                    size = vec3(0.45, 0.35, 0.45),
                    debug = Config.debug,
                    options = {
                        {
                            name = "cdw-bossmenu",
                            icon = "fas fa-sign-in-alt",
                            label = "Open Boss Menu",
                            event = "cdw-bossmenu:openMenu",
                            groups = {[v.job] = 0},
                            canInteract = function()
                                if v.BossOnly then
                                    return IsPlayerBoss()
                                else
                                    return true
                                end
                            end,
                        },
                    }
                })
            else
                exports['qb-target']:AddBoxZone("cdw-bossmenu"..k, v.coord, 0.45, 0.35, {
                    name = "cdw-bossmenu"..k,
                    heading = 0,
                    debugPoly = Config.debug,
                    minZ = v.coord.z - 0.8,
                    maxZ = v.coord.z + 0.8,
                }, {
                    options = {
                        {
                            type = "client",
                            event = "cdw-bossmenu:openMenu",
                            icon = "fas fa-sign-in-alt",
                            label = "Open Boss Menu",
                            job = v.job,
                            canInteract = function()
                                if v.BossOnly then
                                    return IsPlayerBoss()
                                else
                                    return true
                                end
                            end,
                        },
                    },
                    distance = 2.5
                })
            end
        end
    elseif Config.Interaction == "drawtext" then
        while true do
            Wait(sleep)
            local ped = PlayerPedId()
            local coords = GetEntityCoords(ped)
            local closezone = false
            for k,v in pairs(Config.AccesCoords) do
                local dist = #(coords - v.coord)
                if dist < 5.0 then
                    sleep = 0
                    closezone = true
                end
                if closezone then sleep = 0 else sleep = 1000 end
                if closezone then
                    if dist < 2.0 then
                        DrawText3D({
                            text = "Press ~g~[E]~w~ to open the boss menu",
                            coords = v.coord,
                            textMaxLenght = 99,
                        })
                        if IsControlJustPressed(0, 38) then
                            if GetPlayerJob() ~= v.job then
                                Notify(Config.locales[Config.Locale].ui.not_same_job, "error")
                            else
                                if v.BossOnly then
                                    if IsPlayerBoss() then
                                        TriggerEvent("cdw-bossmenu:openMenu")
                                    else
                                        Notify(Config.locales[Config.Locale].ui.not_boss, "error")
                                    end
                                else
                                    TriggerEvent("cdw-bossmenu:openMenu")
                                end
                            end
                        end
                    end
                end
            end
        end
    elseif Config.Interaction == "custom" then
        --your custom code (like interaction etc.)
    end
end)

local function GetLineCountAndMaxLenght(text)
    local count = 0
    local maxLenght = 0
    for line in text:gmatch("([^\n]*)\n?") do
        count = count + 1
        local lenght = string.len(line)
        if lenght > maxLenght then maxLenght = lenght end
    end
    return count, maxLenght
end

function DrawText3D(data)
    SetTextScale(0.30, 0.30)
    SetTextFont(0)
    SetTextProportional(1)
    SetTextColour(255, 255, 255, 215)
    SetTextEntry("STRING")
    SetTextCentre(true)
    local totalLenght = string.len(data.text)
    local textMaxLenght = data.textMaxLenght or 99 -- max 99
    local text = totalLenght > textMaxLenght and data.text:sub(1, totalLenght - (totalLenght - textMaxLenght)) or data.text
    AddTextComponentString(text)
    SetDrawOrigin(data.coords.x, data.coords.y, data.coords.z, 0)
    DrawText(0.0, 0.0)
    local count, lenght = GetLineCountAndMaxLenght(text)

    local padding = 0.005
    local heightFactor = (count / 43) + padding
    local weightFactor = (lenght / 100) + padding

    local height = (heightFactor / 2) - padding / 2
    local width = (weightFactor / 2) - padding / 2

    DrawRect(0.0, height, width, heightFactor, 0, 0, 0, 150.0)
    ClearDrawOrigin()
end

RegisterNUICallback("GetInventoryData", function(data, cb)
    local sa = lib.callback.await('cdw-bossmenu:GetInventoryData', false)
    if sa then
        cb(sa)
    else
        cb(nil)
    end
end)
Previoussv_utils.luaNextcl_mugshot.lua

Last updated 9 days ago