First we want you to know that our script only supports the following versions of the two most used frameworks, in older versions it may be usable but we do not provide support since the development focuses on the latest stable versions.
Update the server.cfg including the asset below the dependencies
If you will be also using the item protection you need to update some code depending of your inventory in use
ox_inventory
Replace this function in the file: ox_inventory/modules/inventory/server.lua
RegisterServerEvent('ox_inventory:giveItem', function(slot, target, count)
local fromInventory = Inventories[source]
local toInventory = Inventories[target]
if count <= 0 then count = 1 end
if toInventory?.player then
local data = fromInventory.items[slot]
if not data then return end
local item = Items(data.name)
-- Snippet to protect item swap
if exports['p6_bridge']:CheckIfProtectedItem(data.name) then
return TriggerClientEvent('ox_lib:notify', fromInventory.id, { type = 'error', description = "It's a protected item, cannot be transfer" })
end
-- Snippet to protect item swap
if not item or data.count < count or not Inventory.CanCarryItem(toInventory, item, count, data.metadata) or #(GetEntityCoords(fromInventory.player.ped) - GetEntityCoords(toInventory.player.ped)) > 15 then
return TriggerClientEvent('ox_lib:notify', fromInventory.id, { type = 'error', description = locale('cannot_give', count, data.label) })
end
local toSlot = Inventory.GetSlotForItem(toInventory, data.name, data.metadata)
local fromRef = ('%s:%s'):format(fromInventory.id, slot)
local toRef = ('%s:%s'):format(toInventory.id, toSlot)
if activeSlots[fromRef] or activeSlots[toRef] then
return TriggerClientEvent('ox_lib:notify', fromInventory.id, { type = 'error', description = locale('cannot_give', count, data.label) })
end
activeSlots[fromRef] = true
activeSlots[toRef] = true
local _ <close> = defer(function()
activeSlots[fromRef] = nil
activeSlots[toRef] = nil
end)
if TriggerEventHooks('swapItems', {
source = fromInventory.id,
fromInventory = fromInventory.id,
fromType = fromInventory.type,
toInventory = toInventory.id,
toType = toInventory.type,
count = data.count,
action = 'give',
fromSlot = data,
}) then
---@todo manually call swapItems or something?
if Inventory.AddItem(toInventory, item, count, data.metadata, toSlot) then
if Inventory.RemoveItem(fromInventory, item, count, data.metadata, slot) then
if server.loglevel > 0 then
lib.logger(fromInventory.owner, 'giveItem', ('"%s" gave %sx %s to "%s"'):format(fromInventory.label, count, data.name, toInventory.label))
end
return
end
end
end
return TriggerClientEvent('ox_lib:notify', fromInventory.id, { type = 'error', description = locale('cannot_give', count, data.label) })
end
end)