From 0d11f29202b8885630cad89d6a9bdfa8e285f47b Mon Sep 17 00:00:00 2001 From: Lenzh Date: Mon, 22 May 2023 20:11:21 +0200 Subject: [PATCH 1/2] Ox_inv support for getWeaponInfo --- server/main.lua | 52 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/server/main.lua b/server/main.lua index 0ca8f649..28fc58f6 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1697,22 +1697,42 @@ end) QBCore.Functions.CreateCallback('getWeaponInfo', function(source, cb) local Player = QBCore.Functions.GetPlayer(source) local weaponInfos = {} - for _, item in pairs(Player.PlayerData.items) do - if item.type == "weapon" then - local invImage = ("https://cfx-nui-%s/html/images/%s"):format(Config.InventoryForWeaponsImages, item.image) - if invImage then - local weaponInfo = { - serialnumber = item.info.serie, - owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname, - weaponmodel = QBCore.Shared.Items[item.name].label, - weaponurl = invImage, - notes = "Self Registered", - weapClass = "Class 1", - } - table.insert(weaponInfos, weaponInfo) - end - end - end + if not Config.InventoryForWeaponsImages == "ox_inventory" then + for _, item in pairs(Player.PlayerData.items) do + if item.type == "weapon" then + local invImage = ("https://cfx-nui-%s/html/images/%s"):format(Config.InventoryForWeaponsImages, item.image) + if invImage then + local weaponInfo = { + serialnumber = item.info.serie, + owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname, + weaponmodel = QBCore.Shared.Items[item.name].label, + weaponurl = invImage, + notes = "Self Registered", + weapClass = "Class 1", + } + table.insert(weaponInfos, weaponInfo) + end + end + end + else -- ox inventory support + local inv = exports.ox_inventory:GetInventoryItems(source) + for _, item in pairs(inv) do + if string.find(item.name, "WEAPON_") then + local invImage = ("https://cfx-nui-ox_inventory/web/images/%s.png"):format(item.name) + if invImage then + weaponInfo = { + serialnumber = item.metadata.serial, + owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname, + weaponmodel = QBCore.Shared.Items[string.lower(item.name)].label, + weaponurl = invImage, + notes = "Self Registered", + weapClass = "Class 1", + } + break + end + end + end + end cb(weaponInfos) end) From ad02649cd1d660006206bc5b71b262915b402357 Mon Sep 17 00:00:00 2001 From: Lenzh Date: Wed, 24 May 2023 11:57:01 +0200 Subject: [PATCH 2/2] Update main.lua --- server/main.lua | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/server/main.lua b/server/main.lua index 28fc58f6..9b077aa4 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1697,24 +1697,7 @@ end) QBCore.Functions.CreateCallback('getWeaponInfo', function(source, cb) local Player = QBCore.Functions.GetPlayer(source) local weaponInfos = {} - if not Config.InventoryForWeaponsImages == "ox_inventory" then - for _, item in pairs(Player.PlayerData.items) do - if item.type == "weapon" then - local invImage = ("https://cfx-nui-%s/html/images/%s"):format(Config.InventoryForWeaponsImages, item.image) - if invImage then - local weaponInfo = { - serialnumber = item.info.serie, - owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname, - weaponmodel = QBCore.Shared.Items[item.name].label, - weaponurl = invImage, - notes = "Self Registered", - weapClass = "Class 1", - } - table.insert(weaponInfos, weaponInfo) - end - end - end - else -- ox inventory support + if Config.InventoryForWeaponsImages == "ox_inventory" then local inv = exports.ox_inventory:GetInventoryItems(source) for _, item in pairs(inv) do if string.find(item.name, "WEAPON_") then @@ -1732,6 +1715,23 @@ QBCore.Functions.CreateCallback('getWeaponInfo', function(source, cb) end end end + else -- qb/lj + for _, item in pairs(Player.PlayerData.items) do + if item.type == "weapon" then + local invImage = ("https://cfx-nui-%s/html/images/%s"):format(Config.InventoryForWeaponsImages, item.image) + if invImage then + local weaponInfo = { + serialnumber = item.info.serie, + owner = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname, + weaponmodel = QBCore.Shared.Items[item.name].label, + weaponurl = invImage, + notes = "Self Registered", + weapClass = "Class 1", + } + table.insert(weaponInfos, weaponInfo) + end + end + end end cb(weaponInfos) end)