forked from Simnation/Main
77 lines
2.4 KiB
Lua
77 lines
2.4 KiB
Lua
![]() |
local QBCore = exports['qb-core']:GetCoreObject()
|
||
|
|
||
|
-- Check if player has a backpack equipped
|
||
|
function CheckForBackpack()
|
||
|
local ped = PlayerPedId()
|
||
|
|
||
|
-- Get the current bag drawable ID (component 5 is the bag slot)
|
||
|
local currentBag = GetPedDrawableVariation(ped, 5)
|
||
|
|
||
|
-- Check if this bag ID is in our config
|
||
|
if Config.Backpacks[currentBag] then
|
||
|
return currentBag
|
||
|
end
|
||
|
|
||
|
return nil
|
||
|
end
|
||
|
|
||
|
-- Open backpack inventory command
|
||
|
RegisterCommand('openbackpack', function()
|
||
|
local backpackId = CheckForBackpack()
|
||
|
|
||
|
if backpackId then
|
||
|
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
||
|
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId
|
||
|
|
||
|
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId)
|
||
|
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 to check if we should show backpack
|
||
|
RegisterNetEvent('inventory:client:OpenInventory', function()
|
||
|
-- Small delay to let the main inventory open first
|
||
|
Citizen.Wait(100)
|
||
|
|
||
|
-- Check if player has a backpack and automatically show the backpack tab
|
||
|
local backpackId = CheckForBackpack()
|
||
|
if backpackId then
|
||
|
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
||
|
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId
|
||
|
|
||
|
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId)
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
-- Monitor for clothing changes to update backpack status
|
||
|
Citizen.CreateThread(function()
|
||
|
local lastBackpack = nil
|
||
|
|
||
|
while true do
|
||
|
Citizen.Wait(1000) -- Check every second
|
||
|
|
||
|
local currentBackpack = CheckForBackpack()
|
||
|
|
||
|
-- If backpack status changed
|
||
|
if currentBackpack ~= lastBackpack then
|
||
|
lastBackpack = currentBackpack
|
||
|
|
||
|
-- If player removed a backpack, we could add additional logic here
|
||
|
if not currentBackpack then
|
||
|
-- Player removed backpack
|
||
|
else
|
||
|
-- Player equipped backpack
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
-- Initialize when player loads
|
||
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||
|
-- Nothing needed here, backpack will be checked when inventory is opened
|
||
|
end)
|