local QBCore = exports['qb-core']:GetCoreObject() -- Debug function to print all clothing components function PrintAllClothingComponents() local ped = PlayerPedId() local components = {} local gender = IsPedMale(ped) and 0 or 1 print("Character Gender: " .. (gender == 0 and "Male" or "Female")) -- Component IDs: 0=face, 1=mask, 2=hair, 3=torso, 4=leg, 5=bag, 6=shoes, 7=accessory, 8=undershirt, 9=kevlar, 10=badge, 11=torso2 for i = 0, 11 do local drawable = GetPedDrawableVariation(ped, i) local texture = GetPedTextureVariation(ped, i) local palette = GetPedPaletteVariation(ped, i) components[i] = { drawable = drawable, texture = texture, palette = palette } print("Component " .. i .. ": Drawable=" .. drawable .. ", Texture=" .. texture .. ", Palette=" .. palette) end -- Props: 0=hat, 1=glasses, 2=ear, 6=watch, 7=bracelet for i = 0, 7 do if i ~= 3 and i ~= 4 and i ~= 5 then -- Skip invalid prop IDs local prop = GetPedPropIndex(ped, i) local texture = GetPedPropTextureIndex(ped, i) print("Prop " .. i .. ": Index=" .. prop .. ", Texture=" .. texture) end end return components, gender end -- Command to print all clothing components (for debugging) RegisterCommand('checkclothing', function() local components, gender = PrintAllClothingComponents() lib.notify({ title = 'Debug', description = 'Clothing components printed to console. Gender: ' .. (gender == 0 and "Male" or "Female"), type = 'info' }) end, false) -- Get character gender (0 = male, 1 = female) function GetCharacterGender() local ped = PlayerPedId() return IsPedMale(ped) and 0 or 1 end -- Check if player has a backpack equipped with gender detection function CheckForBackpack() local ped = PlayerPedId() local gender = GetCharacterGender() -- Get the current bag drawable ID (component 5 is the bag slot) local currentBag = GetPedDrawableVariation(ped, 5) local currentTexture = GetPedTextureVariation(ped, 5) if Config.Debug then print("Current bag: Gender=" .. gender .. ", Drawable=" .. currentBag .. ", Texture=" .. currentTexture) end -- Check if this bag ID is in our config for the current gender if Config.Backpacks[gender] and Config.Backpacks[gender][currentBag] then -- If we need to check for specific textures as well if Config.Backpacks[gender][currentBag].textures then if Config.Backpacks[gender][currentBag].textures[currentTexture] then return currentBag, currentTexture, gender end else -- If we don't care about texture, just return the drawable return currentBag, currentTexture, gender end end return nil, nil, gender end -- Open backpack inventory command RegisterCommand('openbackpack', function() local backpackId, textureId, gender = CheckForBackpack() if backpackId then local citizenId = QBCore.Functions.GetPlayerData().citizenid local backpackStashId = "backpack_" .. citizenId .. "_" .. gender .. "_" .. backpackId .. "_" .. textureId TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId, gender) else lib.notify(Config.Notifications.noBackpack) end end, false) -- Register key binding RegisterKeyMapping('openbackpack', 'Open Backpack Inventory', 'keyboard', Config.BackpackKey) -- Listen for inventory open event RegisterNetEvent('inventory:client:OpenInventory', function() -- Check if player has a backpack local backpackId, textureId, gender = CheckForBackpack() if backpackId then local citizenId = QBCore.Functions.GetPlayerData().citizenid local backpackStashId = "backpack_" .. citizenId .. "_" .. gender .. "_" .. backpackId .. "_" .. textureId -- Small delay to let the main inventory open first Citizen.Wait(100) TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId, gender) end end) -- Monitor for clothing changes to update backpack status Citizen.CreateThread(function() local lastBackpack = nil local lastTexture = nil local lastGender = nil while true do Citizen.Wait(1000) -- Check every second local currentBackpack, currentTexture, currentGender = CheckForBackpack() -- If backpack status changed if currentBackpack ~= lastBackpack or currentTexture ~= lastTexture or currentGender ~= lastGender then lastBackpack = currentBackpack lastTexture = currentTexture lastGender = currentGender -- If player removed a backpack, we could add additional logic here if not currentBackpack then -- Player removed backpack if Config.Debug then print("Backpack removed") end else -- Player equipped backpack if Config.Debug then print("Backpack equipped: Gender=" .. currentGender .. ", ID=" .. currentBackpack .. ", Texture=" .. currentTexture) end end end end end) -- Event for checking backpack info RegisterNetEvent('backpack:client:checkBackpack', function() local backpackId, textureId, gender = CheckForBackpack() TriggerServerEvent('backpack:server:showBackpackInfo', backpackId, textureId, gender) end) -- Event for listing all clothing (debug) RegisterNetEvent('backpack:client:listClothing', function() PrintAllClothingComponents() lib.notify({ title = 'Debug', description = 'Clothing components printed to console', type = 'info' }) end) -- Initialize when player loads RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() -- Nothing needed here, backpack will be checked when inventory is opened Citizen.Wait(1000) -- Wait a bit for player data to be ready local backpackId, textureId, gender = CheckForBackpack() if backpackId then if Config.Debug then print("Player loaded with backpack: Gender=" .. gender .. ", ID=" .. backpackId .. ", Texture=" .. textureId) end else if Config.Debug then print("Player loaded without backpack. Gender=" .. gender) end end end)