client/editable.lua

local tgiann_inventory = GetResourceState("tgiann-inventory") ~= "missing"
local qb_inventory = GetResourceState("qb-inventory") ~= "missing"
local ox_inventory = GetResourceState("ox_inventory") ~= "missing"

local function removeItemDetect(itemName)
    if not gData then return end
    local itemData = config.items[gData.itemIndex]
    if not itemData then return end
    if itemData.item ~= itemName then return end
    disconnectChannel()
end

if tgiann_inventory then
    RegisterNetEvent("tgiann-inventory:dropItem")
    AddEventHandler("tgiann-inventory:dropItem", function(itemName)
        removeItemDetect(itemName)
    end)
elseif ox_inventory then
    CreateThread(function()
        while true do
            if gData then
                local itemData = config.items[gData.itemIndex]
                local count = exports.ox_inventory:Search('count', itemData.item)
                if count <= 0 then
                    removeItemDetect(itemData.item)
                end
            end
            Wait(1000)
        end
    end)
elseif qb_inventory then
    function DoRadioCheck(PlayerItems)
        if not gData then return end
        local itemData = config.items[gData.itemIndex]
        if not itemData then return end
        local hasItem = false

        for _, item in pairs(PlayerItems) do
            if item.name == itemData.item then
                hasItem = true
                break
            end
        end
        if not hasItem then
            removeItemDetect(itemData.name)
        end
    end

    RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
        DoRadioCheck({})
    end)

    RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
        DoRadioCheck(val.items)
    end)
end

Last updated