forked from Simnation/Main
ed
This commit is contained in:
parent
98a52d34f5
commit
44c5ed941b
3 changed files with 126 additions and 72 deletions
|
@ -4,6 +4,9 @@ local QBCore = exports['qb-core']:GetCoreObject()
|
|||
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
|
||||
|
@ -30,54 +33,63 @@ function PrintAllClothingComponents()
|
|||
end
|
||||
end
|
||||
|
||||
return components
|
||||
return components, gender
|
||||
end
|
||||
|
||||
-- Command to print all clothing components (for debugging)
|
||||
RegisterCommand('checkclothing', function()
|
||||
PrintAllClothingComponents()
|
||||
local components, gender = PrintAllClothingComponents()
|
||||
lib.notify({
|
||||
title = 'Debug',
|
||||
description = 'Clothing components printed to console',
|
||||
description = 'Clothing components printed to console. Gender: ' .. (gender == 0 and "Male" or "Female"),
|
||||
type = 'info'
|
||||
})
|
||||
end, false)
|
||||
|
||||
-- Check if player has a backpack equipped with improved detection
|
||||
-- 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)
|
||||
|
||||
print("Current bag: Drawable=" .. currentBag .. ", Texture=" .. currentTexture)
|
||||
if Config.Debug then
|
||||
print("Current bag: Gender=" .. gender .. ", Drawable=" .. currentBag .. ", Texture=" .. currentTexture)
|
||||
end
|
||||
|
||||
-- Check if this bag ID is in our config
|
||||
if Config.Backpacks[currentBag] then
|
||||
-- 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[currentBag].textures then
|
||||
if Config.Backpacks[currentBag].textures[currentTexture] then
|
||||
return currentBag, currentTexture
|
||||
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
|
||||
return currentBag, currentTexture, gender
|
||||
end
|
||||
end
|
||||
|
||||
return nil, nil
|
||||
return nil, nil, gender
|
||||
end
|
||||
|
||||
-- Open backpack inventory command
|
||||
RegisterCommand('openbackpack', function()
|
||||
local backpackId, textureId = CheckForBackpack()
|
||||
local backpackId, textureId, gender = CheckForBackpack()
|
||||
|
||||
if backpackId then
|
||||
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
||||
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId .. "_" .. textureId
|
||||
local backpackStashId = "backpack_" .. citizenId .. "_" .. gender .. "_" .. backpackId .. "_" .. textureId
|
||||
|
||||
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId)
|
||||
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId, gender)
|
||||
else
|
||||
lib.notify(Config.Notifications.noBackpack)
|
||||
end
|
||||
|
@ -89,14 +101,14 @@ RegisterKeyMapping('openbackpack', 'Open Backpack Inventory', 'keyboard', Config
|
|||
-- Listen for inventory open event
|
||||
RegisterNetEvent('inventory:client:OpenInventory', function()
|
||||
-- Check if player has a backpack
|
||||
local backpackId, textureId = CheckForBackpack()
|
||||
local backpackId, textureId, gender = CheckForBackpack()
|
||||
if backpackId then
|
||||
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
||||
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId .. "_" .. textureId
|
||||
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)
|
||||
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId, gender)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -104,45 +116,39 @@ end)
|
|||
Citizen.CreateThread(function()
|
||||
local lastBackpack = nil
|
||||
local lastTexture = nil
|
||||
local lastGender = nil
|
||||
|
||||
while true do
|
||||
Citizen.Wait(1000) -- Check every second
|
||||
|
||||
local currentBackpack, currentTexture = CheckForBackpack()
|
||||
local currentBackpack, currentTexture, currentGender = CheckForBackpack()
|
||||
|
||||
-- If backpack status changed
|
||||
if currentBackpack ~= lastBackpack or currentTexture ~= lastTexture then
|
||||
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
|
||||
print("Backpack equipped: " .. currentBackpack .. " with texture " .. currentTexture)
|
||||
if Config.Debug then
|
||||
print("Backpack equipped: Gender=" .. currentGender .. ", ID=" .. currentBackpack .. ", Texture=" .. currentTexture)
|
||||
end
|
||||
end
|
||||
end
|
||||
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 = 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)
|
||||
local backpackId, textureId, gender = CheckForBackpack()
|
||||
TriggerServerEvent('backpack:server:showBackpackInfo', backpackId, textureId, gender)
|
||||
end)
|
||||
|
||||
-- Event for listing all clothing (debug)
|
||||
|
@ -154,3 +160,19 @@ RegisterNetEvent('backpack:client:listClothing', function()
|
|||
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)
|
||||
|
|
|
@ -2,9 +2,10 @@ Config = {}
|
|||
|
||||
-- Bag component IDs and their inventory properties
|
||||
-- These are the drawable IDs for the "bags" component (component ID 5)
|
||||
-- Separated by gender (0 = male, 1 = female)
|
||||
Config.Backpacks = {
|
||||
-- [drawableId] = inventory properties
|
||||
[158] = { -- Example: Small backpack drawable ID
|
||||
[0] = { -- Male backpacks
|
||||
[31] = { -- Example: Small backpack drawable ID for males
|
||||
maxweight = 10000, -- 10kg
|
||||
slots = 10,
|
||||
label = 'Small Backpack',
|
||||
|
@ -15,26 +16,54 @@ Config.Backpacks = {
|
|||
-- Add more textures if needed
|
||||
}
|
||||
},
|
||||
[41] = { -- Example: Medium backpack drawable ID
|
||||
[41] = { -- Example: Medium backpack drawable ID for males
|
||||
maxweight = 20000, -- 20kg
|
||||
slots = 15,
|
||||
label = 'Medium Backpack'
|
||||
},
|
||||
[44] = { -- Example: Large backpack drawable ID
|
||||
[44] = { -- Example: Large backpack drawable ID for males
|
||||
maxweight = 30000, -- 30kg
|
||||
slots = 20,
|
||||
label = 'Large Backpack'
|
||||
},
|
||||
[52] = { -- Example: Tactical backpack drawable ID
|
||||
[52] = { -- Example: Tactical backpack drawable ID for males
|
||||
maxweight = 40000, -- 40kg
|
||||
slots = 25,
|
||||
label = 'Tactical Backpack'
|
||||
},
|
||||
[81] = { -- Example: Hiking backpack drawable ID
|
||||
[81] = { -- Example: Hiking backpack drawable ID for males
|
||||
maxweight = 50000, -- 50kg
|
||||
slots = 30,
|
||||
label = 'Hiking Backpack'
|
||||
}
|
||||
},
|
||||
[1] = { -- Female backpacks
|
||||
[29] = { -- Example: Small backpack drawable ID for females
|
||||
maxweight = 10000, -- 10kg
|
||||
slots = 10,
|
||||
label = 'Small Backpack'
|
||||
},
|
||||
[39] = { -- Example: Medium backpack drawable ID for females
|
||||
maxweight = 20000, -- 20kg
|
||||
slots = 15,
|
||||
label = 'Medium Backpack'
|
||||
},
|
||||
[42] = { -- Example: Large backpack drawable ID for females
|
||||
maxweight = 30000, -- 30kg
|
||||
slots = 20,
|
||||
label = 'Large Backpack'
|
||||
},
|
||||
[49] = { -- Example: Tactical backpack drawable ID for females
|
||||
maxweight = 40000, -- 40kg
|
||||
slots = 25,
|
||||
label = 'Tactical Backpack'
|
||||
},
|
||||
[77] = { -- Example: Hiking backpack drawable ID for females
|
||||
maxweight = 50000, -- 50kg
|
||||
slots = 30,
|
||||
label = 'Hiking Backpack'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-- Key to open backpack inventory (default: B)
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
-- Open backpack inventory
|
||||
RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, backpackId, textureId)
|
||||
RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, backpackId, textureId, gender)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
||||
if not Player then return end
|
||||
|
||||
-- Open the inventory
|
||||
local backpackConfig = Config.Backpacks[backpackId]
|
||||
if not backpackConfig then
|
||||
print("Error: Backpack config not found for ID " .. backpackId)
|
||||
if not Config.Backpacks[gender] or not Config.Backpacks[gender][backpackId] then
|
||||
print("Error: Backpack config not found for Gender=" .. gender .. ", ID=" .. backpackId)
|
||||
return
|
||||
end
|
||||
|
||||
local backpackConfig = Config.Backpacks[gender][backpackId]
|
||||
|
||||
exports["tgiann-inventory"]:OpenInventory(src, "stash", backpackStashId, {
|
||||
maxweight = backpackConfig.maxweight,
|
||||
slots = backpackConfig.slots,
|
||||
|
@ -30,6 +31,7 @@ RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, back
|
|||
Config.Logs.openTitle,
|
||||
Config.Logs.openColor,
|
||||
'**Player:** ' .. Player.PlayerData.name ..
|
||||
'\n**Gender:** ' .. (gender == 0 and "Male" or "Female") ..
|
||||
'\n**Backpack Type:** ' .. backpackConfig.label ..
|
||||
'\n**Backpack ID:** ' .. backpackId ..
|
||||
'\n**Texture ID:** ' .. textureId ..
|
||||
|
@ -48,16 +50,17 @@ QBCore.Commands.Add('listclothing', 'List all clothing components (Debug)', {},
|
|||
end)
|
||||
|
||||
-- Receive backpack info from client and show notification
|
||||
RegisterNetEvent('backpack:server:showBackpackInfo', function(backpackId, textureId)
|
||||
RegisterNetEvent('backpack:server:showBackpackInfo', function(backpackId, textureId, gender)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
||||
if backpackId and Config.Backpacks[backpackId] then
|
||||
local backpackConfig = Config.Backpacks[backpackId]
|
||||
if backpackId and Config.Backpacks[gender] and Config.Backpacks[gender][backpackId] then
|
||||
local backpackConfig = Config.Backpacks[gender][backpackId]
|
||||
|
||||
TriggerClientEvent('ox_lib:notify', src, {
|
||||
title = 'Backpack Info',
|
||||
description = 'Type: ' .. backpackConfig.label ..
|
||||
'\nGender: ' .. (gender == 0 and "Male" or "Female") ..
|
||||
'\nDrawable ID: ' .. backpackId ..
|
||||
'\nTexture ID: ' .. textureId ..
|
||||
'\nCapacity: ' .. (backpackConfig.maxweight / 1000) .. 'kg' ..
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue