From b690851a4872df1f4ec608a98e4b6bb129db4f4d Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 2 Jan 2024 10:09:51 +1100 Subject: [PATCH] fix(server): usingItem corrections Set usingItem when calling external useItem functions (ESX/QB). Don't set usingItem if item use failed (e.g. error, canceled). --- server.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.lua b/server.lua index a965351688..e19e6de026 100644 --- a/server.lua +++ b/server.lua @@ -354,6 +354,7 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m return TriggerClientEvent('ox_lib:notify', source, { type = 'error', description = locale('item_not_enough', item.name) }) end elseif not item.weapon and server.UseItem then + inventory.usingItem = data -- This is used to call an external useItem function, i.e. ESX.UseItem / QBCore.Functions.CanUseItem -- If an error is being thrown on item use there is no internal solution. We previously kept a list -- of usable items which led to issues when restarting resources (for obvious reasons), but config @@ -363,7 +364,6 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m end data.consume = consume - inventory.usingItem = data ---@type boolean local success = lib.callback.await('ox_inventory:usingItem', source, data) @@ -374,6 +374,8 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m if not success then return end + inventory.usingItem = data + if consume and consume ~= 0 and not data.component then data = inventory.items[data.slot]