2025-07-30 01:18:19 +02:00
|
|
|
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
|
2025-07-30 01:31:07 +02:00
|
|
|
-- Debug function to print all clothing components
|
|
|
|
function PrintAllClothingComponents()
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
local components = {}
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Command to print all clothing components (for debugging)
|
|
|
|
RegisterCommand('checkclothing', function()
|
|
|
|
PrintAllClothingComponents()
|
|
|
|
lib.notify({
|
|
|
|
title = 'Debug',
|
|
|
|
description = 'Clothing components printed to console',
|
|
|
|
type = 'info'
|
|
|
|
})
|
|
|
|
end, false)
|
|
|
|
|
|
|
|
-- Check if player has a backpack equipped with improved detection
|
2025-07-30 01:18:19 +02:00
|
|
|
function CheckForBackpack()
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
|
|
|
-- Get the current bag drawable ID (component 5 is the bag slot)
|
|
|
|
local currentBag = GetPedDrawableVariation(ped, 5)
|
2025-07-30 01:31:07 +02:00
|
|
|
local currentTexture = GetPedTextureVariation(ped, 5)
|
|
|
|
|
|
|
|
print("Current bag: Drawable=" .. currentBag .. ", Texture=" .. currentTexture)
|
2025-07-30 01:18:19 +02:00
|
|
|
|
|
|
|
-- Check if this bag ID is in our config
|
|
|
|
if Config.Backpacks[currentBag] then
|
2025-07-30 01:31:07 +02:00
|
|
|
-- If we need to check for specific textures as well
|
|
|
|
if Config.Backpacks[currentBag].textures then
|
|
|
|
if Config.Backpacks[currentBag].textures[currentTexture] then
|
|
|
|
return currentBag, currentTexture
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- If we don't care about texture, just return the drawable
|
|
|
|
return currentBag, currentTexture
|
|
|
|
end
|
2025-07-30 01:18:19 +02:00
|
|
|
end
|
|
|
|
|
2025-07-30 01:31:07 +02:00
|
|
|
return nil, nil
|
2025-07-30 01:18:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Open backpack inventory command
|
|
|
|
RegisterCommand('openbackpack', function()
|
2025-07-30 01:31:07 +02:00
|
|
|
local backpackId, textureId = CheckForBackpack()
|
2025-07-30 01:18:19 +02:00
|
|
|
|
|
|
|
if backpackId then
|
|
|
|
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
2025-07-30 01:31:07 +02:00
|
|
|
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId .. "_" .. textureId
|
2025-07-30 01:18:19 +02:00
|
|
|
|
2025-07-30 01:31:07 +02:00
|
|
|
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId)
|
2025-07-30 01:18:19 +02:00
|
|
|
else
|
|
|
|
lib.notify(Config.Notifications.noBackpack)
|
|
|
|
end
|
|
|
|
end, false)
|
|
|
|
|
|
|
|
-- Register key binding
|
|
|
|
RegisterKeyMapping('openbackpack', 'Open Backpack Inventory', 'keyboard', Config.BackpackKey)
|
|
|
|
|
2025-07-30 01:31:07 +02:00
|
|
|
-- Listen for inventory open event
|
2025-07-30 01:18:19 +02:00
|
|
|
RegisterNetEvent('inventory:client:OpenInventory', function()
|
2025-07-30 01:31:07 +02:00
|
|
|
-- Check if player has a backpack
|
|
|
|
local backpackId, textureId = CheckForBackpack()
|
2025-07-30 01:18:19 +02:00
|
|
|
if backpackId then
|
|
|
|
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
2025-07-30 01:31:07 +02:00
|
|
|
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId .. "_" .. textureId
|
2025-07-30 01:18:19 +02:00
|
|
|
|
2025-07-30 01:31:07 +02:00
|
|
|
-- Small delay to let the main inventory open first
|
|
|
|
Citizen.Wait(100)
|
|
|
|
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId)
|
2025-07-30 01:18:19 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Monitor for clothing changes to update backpack status
|
|
|
|
Citizen.CreateThread(function()
|
|
|
|
local lastBackpack = nil
|
2025-07-30 01:31:07 +02:00
|
|
|
local lastTexture = nil
|
2025-07-30 01:18:19 +02:00
|
|
|
|
|
|
|
while true do
|
|
|
|
Citizen.Wait(1000) -- Check every second
|
|
|
|
|
2025-07-30 01:31:07 +02:00
|
|
|
local currentBackpack, currentTexture = CheckForBackpack()
|
2025-07-30 01:18:19 +02:00
|
|
|
|
|
|
|
-- If backpack status changed
|
2025-07-30 01:31:07 +02:00
|
|
|
if currentBackpack ~= lastBackpack or currentTexture ~= lastTexture then
|
2025-07-30 01:18:19 +02:00
|
|
|
lastBackpack = currentBackpack
|
2025-07-30 01:31:07 +02:00
|
|
|
lastTexture = currentTexture
|
2025-07-30 01:18:19 +02:00
|
|
|
|
|
|
|
-- If player removed a backpack, we could add additional logic here
|
|
|
|
if not currentBackpack then
|
|
|
|
-- Player removed backpack
|
2025-07-30 01:31:07 +02:00
|
|
|
print("Backpack removed")
|
2025-07-30 01:18:19 +02:00
|
|
|
else
|
|
|
|
-- Player equipped backpack
|
2025-07-30 01:31:07 +02:00
|
|
|
print("Backpack equipped: " .. currentBackpack .. " with texture " .. currentTexture)
|
2025-07-30 01:18:19 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Initialize when player loads
|
|
|
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|
|
|
-- Nothing needed here, backpack will be checked when inventory is opened
|
2025-07-30 01:31:07 +02:00
|
|
|
Citizen.Wait(1000) -- Wait a bit for player data to be ready
|
|
|
|
local backpackId, textureId = CheckForBackpack()
|
|
|
|
if backpackId then
|
|
|
|
print("Player loaded with backpack: " .. backpackId .. " texture: " .. textureId)
|
|
|
|
else
|
|
|
|
print("Player loaded without backpack")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Event for checking backpack info
|
|
|
|
RegisterNetEvent('backpack:client:checkBackpack', function()
|
|
|
|
local backpackId, textureId = CheckForBackpack()
|
|
|
|
TriggerServerEvent('backpack:server:showBackpackInfo', backpackId, textureId)
|
|
|
|
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'
|
|
|
|
})
|
2025-07-30 01:18:19 +02:00
|
|
|
end)
|