forked from Simnation/Main
ed
This commit is contained in:
parent
0905e09ac9
commit
98a52d34f5
4 changed files with 125 additions and 30 deletions
|
@ -1,29 +1,83 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Check if player has a backpack equipped
|
-- 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
|
||||||
function CheckForBackpack()
|
function CheckForBackpack()
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
|
|
||||||
-- Get the current bag drawable ID (component 5 is the bag slot)
|
-- Get the current bag drawable ID (component 5 is the bag slot)
|
||||||
local currentBag = GetPedDrawableVariation(ped, 5)
|
local currentBag = GetPedDrawableVariation(ped, 5)
|
||||||
|
local currentTexture = GetPedTextureVariation(ped, 5)
|
||||||
|
|
||||||
|
print("Current bag: Drawable=" .. currentBag .. ", Texture=" .. currentTexture)
|
||||||
|
|
||||||
-- Check if this bag ID is in our config
|
-- Check if this bag ID is in our config
|
||||||
if Config.Backpacks[currentBag] then
|
if Config.Backpacks[currentBag] then
|
||||||
return currentBag
|
-- 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
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open backpack inventory command
|
-- Open backpack inventory command
|
||||||
RegisterCommand('openbackpack', function()
|
RegisterCommand('openbackpack', function()
|
||||||
local backpackId = CheckForBackpack()
|
local backpackId, textureId = CheckForBackpack()
|
||||||
|
|
||||||
if backpackId then
|
if backpackId then
|
||||||
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
||||||
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId
|
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId .. "_" .. textureId
|
||||||
|
|
||||||
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId)
|
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId)
|
||||||
else
|
else
|
||||||
lib.notify(Config.Notifications.noBackpack)
|
lib.notify(Config.Notifications.noBackpack)
|
||||||
end
|
end
|
||||||
|
@ -32,39 +86,42 @@ end, false)
|
||||||
-- Register key binding
|
-- Register key binding
|
||||||
RegisterKeyMapping('openbackpack', 'Open Backpack Inventory', 'keyboard', Config.BackpackKey)
|
RegisterKeyMapping('openbackpack', 'Open Backpack Inventory', 'keyboard', Config.BackpackKey)
|
||||||
|
|
||||||
-- Listen for inventory open event to check if we should show backpack
|
-- Listen for inventory open event
|
||||||
RegisterNetEvent('inventory:client:OpenInventory', function()
|
RegisterNetEvent('inventory:client:OpenInventory', function()
|
||||||
-- Small delay to let the main inventory open first
|
-- Check if player has a backpack
|
||||||
Citizen.Wait(100)
|
local backpackId, textureId = CheckForBackpack()
|
||||||
|
|
||||||
-- Check if player has a backpack and automatically show the backpack tab
|
|
||||||
local backpackId = CheckForBackpack()
|
|
||||||
if backpackId then
|
if backpackId then
|
||||||
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
local citizenId = QBCore.Functions.GetPlayerData().citizenid
|
||||||
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId
|
local backpackStashId = "backpack_" .. citizenId .. "_" .. backpackId .. "_" .. textureId
|
||||||
|
|
||||||
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId)
|
-- Small delay to let the main inventory open first
|
||||||
|
Citizen.Wait(100)
|
||||||
|
TriggerServerEvent('backpack:server:openInventory', backpackStashId, backpackId, textureId)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Monitor for clothing changes to update backpack status
|
-- Monitor for clothing changes to update backpack status
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
local lastBackpack = nil
|
local lastBackpack = nil
|
||||||
|
local lastTexture = nil
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
Citizen.Wait(1000) -- Check every second
|
Citizen.Wait(1000) -- Check every second
|
||||||
|
|
||||||
local currentBackpack = CheckForBackpack()
|
local currentBackpack, currentTexture = CheckForBackpack()
|
||||||
|
|
||||||
-- If backpack status changed
|
-- If backpack status changed
|
||||||
if currentBackpack ~= lastBackpack then
|
if currentBackpack ~= lastBackpack or currentTexture ~= lastTexture then
|
||||||
lastBackpack = currentBackpack
|
lastBackpack = currentBackpack
|
||||||
|
lastTexture = currentTexture
|
||||||
|
|
||||||
-- If player removed a backpack, we could add additional logic here
|
-- If player removed a backpack, we could add additional logic here
|
||||||
if not currentBackpack then
|
if not currentBackpack then
|
||||||
-- Player removed backpack
|
-- Player removed backpack
|
||||||
|
print("Backpack removed")
|
||||||
else
|
else
|
||||||
-- Player equipped backpack
|
-- Player equipped backpack
|
||||||
|
print("Backpack equipped: " .. currentBackpack .. " with texture " .. currentTexture)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,4 +130,27 @@ end)
|
||||||
-- Initialize when player loads
|
-- Initialize when player loads
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||||
-- Nothing needed here, backpack will be checked when inventory is opened
|
-- 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)
|
||||||
|
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)
|
end)
|
||||||
|
|
|
@ -7,7 +7,13 @@ Config.Backpacks = {
|
||||||
[158] = { -- Example: Small backpack drawable ID
|
[158] = { -- Example: Small backpack drawable ID
|
||||||
maxweight = 10000, -- 10kg
|
maxweight = 10000, -- 10kg
|
||||||
slots = 10,
|
slots = 10,
|
||||||
label = 'Small Backpack'
|
label = 'Small Backpack',
|
||||||
|
-- Optional: specific textures
|
||||||
|
textures = {
|
||||||
|
[0] = true, -- Texture ID 0
|
||||||
|
[1] = true, -- Texture ID 1
|
||||||
|
-- Add more textures if needed
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[41] = { -- Example: Medium backpack drawable ID
|
[41] = { -- Example: Medium backpack drawable ID
|
||||||
maxweight = 20000, -- 20kg
|
maxweight = 20000, -- 20kg
|
||||||
|
@ -34,6 +40,9 @@ Config.Backpacks = {
|
||||||
-- Key to open backpack inventory (default: B)
|
-- Key to open backpack inventory (default: B)
|
||||||
Config.BackpackKey = 'B'
|
Config.BackpackKey = 'B'
|
||||||
|
|
||||||
|
-- Debug mode - prints additional information to console
|
||||||
|
Config.Debug = true
|
||||||
|
|
||||||
-- Notification settings
|
-- Notification settings
|
||||||
Config.Notifications = {
|
Config.Notifications = {
|
||||||
noBackpack = {
|
noBackpack = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Open backpack inventory
|
-- Open backpack inventory
|
||||||
RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, backpackId)
|
RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, backpackId, textureId)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, back
|
||||||
|
|
||||||
-- Open the inventory
|
-- Open the inventory
|
||||||
local backpackConfig = Config.Backpacks[backpackId]
|
local backpackConfig = Config.Backpacks[backpackId]
|
||||||
|
if not backpackConfig then
|
||||||
|
print("Error: Backpack config not found for ID " .. backpackId)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
exports["tgiann-inventory"]:OpenInventory(src, "stash", backpackStashId, {
|
exports["tgiann-inventory"]:OpenInventory(src, "stash", backpackStashId, {
|
||||||
maxweight = backpackConfig.maxweight,
|
maxweight = backpackConfig.maxweight,
|
||||||
slots = backpackConfig.slots,
|
slots = backpackConfig.slots,
|
||||||
|
@ -26,27 +31,35 @@ RegisterNetEvent('backpack:server:openInventory', function(backpackStashId, back
|
||||||
Config.Logs.openColor,
|
Config.Logs.openColor,
|
||||||
'**Player:** ' .. Player.PlayerData.name ..
|
'**Player:** ' .. Player.PlayerData.name ..
|
||||||
'\n**Backpack Type:** ' .. backpackConfig.label ..
|
'\n**Backpack Type:** ' .. backpackConfig.label ..
|
||||||
'\n**Backpack ID:** ' .. backpackStashId)
|
'\n**Backpack ID:** ' .. backpackId ..
|
||||||
|
'\n**Texture ID:** ' .. textureId ..
|
||||||
|
'\n**Stash ID:** ' .. backpackStashId)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Add command to check backpack info
|
-- Add command to check backpack info
|
||||||
QBCore.Commands.Add('checkbackpack', 'Check your backpack info', {}, false, function(source, args)
|
QBCore.Commands.Add('checkbackpack', 'Check your backpack info', {}, false, function(source, args)
|
||||||
-- Get the player's current bag drawable
|
|
||||||
TriggerClientEvent('backpack:client:checkBackpack', source)
|
TriggerClientEvent('backpack:client:checkBackpack', source)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Add command to list all clothing (for debugging)
|
||||||
|
QBCore.Commands.Add('listclothing', 'List all clothing components (Debug)', {}, false, function(source, args)
|
||||||
|
TriggerClientEvent('backpack:client:listClothing', source)
|
||||||
|
end)
|
||||||
|
|
||||||
-- Receive backpack info from client and show notification
|
-- Receive backpack info from client and show notification
|
||||||
RegisterNetEvent('backpack:server:showBackpackInfo', function(backpackId)
|
RegisterNetEvent('backpack:server:showBackpackInfo', function(backpackId, textureId)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if backpackId then
|
if backpackId and Config.Backpacks[backpackId] then
|
||||||
local backpackConfig = Config.Backpacks[backpackId]
|
local backpackConfig = Config.Backpacks[backpackId]
|
||||||
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
title = 'Backpack Info',
|
title = 'Backpack Info',
|
||||||
description = 'Type: ' .. backpackConfig.label ..
|
description = 'Type: ' .. backpackConfig.label ..
|
||||||
|
'\nDrawable ID: ' .. backpackId ..
|
||||||
|
'\nTexture ID: ' .. textureId ..
|
||||||
'\nCapacity: ' .. (backpackConfig.maxweight / 1000) .. 'kg' ..
|
'\nCapacity: ' .. (backpackConfig.maxweight / 1000) .. 'kg' ..
|
||||||
'\nSlots: ' .. backpackConfig.slots,
|
'\nSlots: ' .. backpackConfig.slots,
|
||||||
type = 'info',
|
type = 'info',
|
||||||
|
@ -56,10 +69,3 @@ RegisterNetEvent('backpack:server:showBackpackInfo', function(backpackId)
|
||||||
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.noBackpack)
|
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.noBackpack)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Add this event handler for the client to send backpack info
|
|
||||||
RegisterNetEvent('backpack:client:checkBackpack', function()
|
|
||||||
local src = source
|
|
||||||
local backpackId = CheckForBackpack()
|
|
||||||
TriggerServerEvent('backpack:server:showBackpackInfo', backpackId)
|
|
||||||
end)
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ config.carryItmes = {
|
||||||
},
|
},
|
||||||
moveRate = 1.0
|
moveRate = 1.0
|
||||||
},
|
},
|
||||||
safe = {
|
plastic_box = {
|
||||||
model = `v_res_smallplasticbox`,
|
model = `v_res_smallplasticbox`,
|
||||||
bone = 28422,
|
bone = 28422,
|
||||||
offset = vector3(5.0, 5.0, 1.0),
|
offset = vector3(5.0, 5.0, 1.0),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue