diff --git a/README.md b/README.md index f219b61..199a176 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Discord: [Byte Labs](https://discord.gg/fqsqSjZfxE) # Frameworks 'qb' | 'esx' | 'nd' setr bl:framework 'qb' -# Inventories 'ox' | 'qb' +# Inventories 'ox' | 'qb' | 'codem' setr bl:inventory 'ox' # Context 'ox' | 'qb' diff --git a/client/inventory/all.lua b/client/inventory/all.lua index 76bb7e0..bf53059 100644 --- a/client/inventory/all.lua +++ b/client/inventory/all.lua @@ -43,6 +43,10 @@ function inventory.openInventory(invType, invId) local inventoryData = Utils.await('bl_bridge:validInventory', 10, invType, invId) if not inventoryData then return end TriggerServerEvent('inventory:server:OpenInventory', invType, invId, inventoryData) + elseif invFramework == 'codem'then + local inventoryData = Utils.await('bl_bridge:validInventory', 10, invType, invId) + if not inventoryData then return end + TriggerServerEvent('inventory:server:OpenInventory', invType, invId, inventoryData) end end diff --git a/init.lua b/init.lua index 9a51bde..6b3f6e1 100644 --- a/init.lua +++ b/init.lua @@ -29,7 +29,8 @@ Config = { ox = 'ox_inventory', qb = 'qb-inventory', ps = 'ps-inventory', - qs = 'qs-inventory' + qs = 'qs-inventory', + codem = 'codem-inventory' }, core = { nd = 'ND_Core', diff --git a/server/core/esx.lua b/server/core/esx.lua index c661b5c..708d2e2 100644 --- a/server/core/esx.lua +++ b/server/core/esx.lua @@ -124,4 +124,4 @@ function Core.GetPlayer(src) end Core.Players = shared.Players -return Core \ No newline at end of file +return Core diff --git a/server/core/qb.lua b/server/core/qb.lua index 8ba577f..f273122 100644 --- a/server/core/qb.lua +++ b/server/core/qb.lua @@ -135,4 +135,4 @@ function Core.hasPerms(...) return shared.Functions.HasPermission(...) end -return Core \ No newline at end of file +return Core diff --git a/server/inventory/codem.lua b/server/inventory/codem.lua new file mode 100644 index 0000000..1f1b2d2 --- /dev/null +++ b/server/inventory/codem.lua @@ -0,0 +1,67 @@ +local overrideFunction = {} +local registeredInventories = {} +overrideFunction.methods = { + Functions = { + addItem = { + originalMethod = 'AddItem', + modifier = { + effect = function(originalFun, name, amount, metadata, slot) + return originalFun(name, amount, slot, metadata) + end + } + }, + removeItem = { + originalMethod = 'RemoveItem', + }, + getItem = { + originalMethod = 'GetItemByName', + modifier = { + effect = function(originalFun, itemName) + local data = originalFun(itemName) + if not data then + return false, 'Item not exist or you don\'t have it' + end + return { + label = data.label, + name = data.name, + weight = data.weight, + slot = data.slot, + close = data.shouldClose, + stack = not data.unique, + metadata = data.info ~= '' and data.info or {}, + count = data.amount or 1 + } + end + } + } + }, + PlayerData = { + items = { + originalMethod = 'items', + }, + } +} + +function overrideFunction.registerInventory(id, data) + local type, name, items, slots, maxWeight in data + + for k,v in ipairs(items) do + v.amount = v.amount or 10 + v.slot = k + end + + registeredInventories[('%s-%s'):format(type, id)] = { + label = name, + items = items, + slots = slots or #items, + maxweight = maxWeight + } +end + +require'utils'.register('bl_bridge:validInventory', function(_, invType, invId) + local inventory = registeredInventories[('%s-%s'):format(invType, invId)] + if not inventory then return end + return inventory +end) + +return overrideFunction \ No newline at end of file diff --git a/server/inventory/ox.lua b/server/inventory/ox.lua index 4db408d..f83ded0 100644 --- a/server/inventory/ox.lua +++ b/server/inventory/ox.lua @@ -58,4 +58,4 @@ function overrideFunction.registerInventory(id, data) end end -return overrideFunction \ No newline at end of file +return overrideFunction diff --git a/server/inventory/qb.lua b/server/inventory/qb.lua index c452ab0..8e34a27 100644 --- a/server/inventory/qb.lua +++ b/server/inventory/qb.lua @@ -73,4 +73,4 @@ require'utils'.register('bl_bridge:validInventory', function(_, invType, invId) return inventory end) -return overrideFunction \ No newline at end of file +return overrideFunction