ESX

CreateThread(function()
    if Config.framework ~= 'ESX' then return end
    ESX = exports['es_extended']:getSharedObject()
    
    local PlayerData = {}
    
    -- UpdatePlayerData
    function UpdatePlayerData()
        PlayerData = ESX.GetPlayerData()
    end
    
    -- Register events for money updates
    RegisterNetEvent('esx:updatePlayerData', function(xPlayer)
        UpdatePlayerData()
    end)
    
    -- Initial load
    UpdatePlayerData()
    
    -- GetPlayerJobName
    function GetPlayerJobName()
        UpdatePlayerData()
        if PlayerData and PlayerData.job and PlayerData.job.name then
            return PlayerData.job.name
        end
        return nil
    end
    
    -- GetPlayerJobGrade
    function GetPlayerJobGrade()
        UpdatePlayerData()
        if PlayerData and PlayerData.job and PlayerData.job.grade then
            return PlayerData.job.grade
        end
        return nil
    end
    
    -- GetPlayerData
    function GetPlayerData(callback)
        UpdatePlayerData()
        if callback ~= nil then
            callback(PlayerData)
        end
    end
    
    local charInfoCallback = nil
    
    -- GetPlayerCharInfo
    function GetPlayerCharInfo()
        UpdatePlayerData()
        local identifier = PlayerData.identifier
        if identifier then
            TriggerServerEvent('peace-treasure:GetPlayerCharInfo', identifier)
            -- Wait for callback
            charInfoCallback = nil
            local timeout = 0
            while charInfoCallback == nil and timeout < 100 do
                Wait(10)
                timeout = timeout + 1
            end
            if charInfoCallback then
                return charInfoCallback
            end
        end
        return nil
    end
    
    RegisterNetEvent('peace-treasure:ReceivePlayerCharInfo')
    AddEventHandler('peace-treasure:ReceivePlayerCharInfo', function(character)
        charInfoCallback = character
    end)
    
    -- GetPlayerItems
    function GetPlayerItems()
        UpdatePlayerData()
        if PlayerData and PlayerData.inventory then
            return PlayerData.inventory
        end
        return {}
    end
    
    -- GetPlayerItemByName
    function GetPlayerItemByName(itemName)
        local items = GetPlayerItems()
        for _, item in pairs(items) do
            if item.name == itemName then
                return item
            end
        end
        return nil
    end
    
    -- Notification
    function sendNotification(message, theme, duration)
        ESX.ShowNotification(message)
    end
    
    -- GetSharedItem
    function GetSharedItem(itemName)
        if ESX.GetItemLabel then
            return { label = ESX.GetItemLabel(itemName) }
        end
        return nil
    end
    
    -- GetPlayerCash
    function GetPlayerCash()
        UpdatePlayerData()
        local typeToUse = Config.MoneyType or 'cash'
        if PlayerData and PlayerData.accounts then
            for _, account in ipairs(PlayerData.accounts) do
                if typeToUse == 'cash' and (account.name == 'money' or account.name == 'cash') then
                    return account.money
                elseif typeToUse == 'money' and account.name == 'money' then
                    return account.money
                elseif typeToUse == 'bank' and account.name == 'bank' then
                    return account.money
                end
            end
        end
        if typeToUse == 'money' and PlayerData and PlayerData.money then
            return PlayerData.money
        end
        return 0
    end
end)

Last updated