Find the AddItem function and update it as follows: (qb-inventory/server/functions.lua)
Find the relevant code block in step 1, replace it with the code line given below in step 2.
inventory[slot] = {
name = item,
amount = amount,
info = info or {},
label = itemInfo.label,
description = itemInfo.description or '',
weight = itemInfo.weight,
type = itemInfo.type,
unique = itemInfo.unique,
useable = item == "housekeys" and true or itemInfo.useable, -- Add Line
image = itemInfo.image,
shouldClose = itemInfo.shouldClose,
slot = slot,
combinable = itemInfo.combinable
}
STEP 2 - Find the AddItem function and update it as follows:
(qb-inventory/server/functions.lua)
Find the : exports('SetItemData', SetItemData) function.
STEP 3 - Find the relevant code block in step 1, replace it with the code line given below in step 2.
exports('SetItemData', SetItemData)
local function AddHouseKeyInfo(item, info)
if item == "housekeys" then
if not info then info = {} end
info.HouseId = info.HouseId or "Unknown"
info.KeyData = info.KeyData or "default_key"
info.useable = true
end
return info
end
function UseItem(itemName, ...)
local itemData = QBCore.Functions.CanUseItem(itemName)
if itemName == "housekeys" then
local args = {...}
local src = args[1]
local itemData = args[2]
if src and itemData and itemData.info and itemData.info.HouseId then
TriggerClientEvent('Scode:Hom:Client:UseHouseKeys', src,
itemData.info.HouseId,
itemData.info.KeyData
)
return
end
end
if type(itemData) == "table" and itemData.func then
itemData.func(...)
end
end
exports('UseItem', UseItem)
STEP 4 - Find the AddItem function and update it as follows: (qb-inventory/server/main.lua)
You can add the following code block anywhere in qb-inventory/server/main.lua.
RegisterNetEvent('qb-inventory:server:OpenInventory', function(inventoryType, id, other)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
if inventoryType == "stash" then
local houseId = tonumber(string.match(id, "HouseStash_(%d+)"))
local stashId = tonumber(string.match(id, "HouseStash_%d+_(%d+)"))
QBCore.Functions.TriggerCallback('Scode:Hom:Server:CheckStashAccess', source, function(hasAccess)
if hasAccess then
local stashData = {
name = id,
label = other.label or ("House " .. houseId .. " - Stash " .. stashId),
maxweight = other.maxweight,
slots = other.slots,
inventory = {}
}
if not Inventories[id] then
Inventories[id] = {
label = stashData.label,
slots = stashData.slots,
maxweight = stashData.maxweight,
inventory = {},
isOpen = false,
items = {}
}
end
local playerItems = Player.PlayerData.items
TriggerClientEvent('qb-inventory:client:openInventory', src, playerItems, {
name = id,
label = stashData.label,
maxweight = stashData.maxweight,
slots = stashData.slots,
inventory = Inventories[id].items
})
else
TriggerClientEvent('QBCore:Notify', src, 'Bu stasha erişiminiz yok!', 'error')
end
end, houseId, stashId)
end
end)
QBCore.Functions.CreateUseableItem("housekeys", function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
if item.info and item.info.HouseId then
TriggerClientEvent('Scode:Hom:Client:UseHouseKeys', source, {
HouseId = item.info.HouseId,
KeyData = item.info.KeyData
})
else
TriggerClientEvent('QBCore:Notify', source, 'Bu anahtar hasarlı görünüyor!', 'error')
end
end)
RegisterNetEvent('qb-inventory:server:GiveItem', function(target, item, amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if item.name == "housekeys" then
local keyInfo = {
HouseId = item.info.HouseId,
KeyData = item.info.KeyData,
label = item.info.label
}
if AddItem(target, "housekeys", 1, nil, keyInfo) then
RemoveItem(src, "housekeys", 1, item.slot)
end
end
end)