From 8ddd2b9136aad2872e4b19d7f5b66ed9f7f6ec5b Mon Sep 17 00:00:00 2001 From: Mohammad amin Jafarian Date: Tue, 5 Nov 2024 01:18:56 +0330 Subject: [PATCH] add useItem Hook --- server.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server.lua b/server.lua index 7020d2686..81400722b 100644 --- a/server.lua +++ b/server.lua @@ -356,6 +356,17 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m consume = 1 data.component = true elseif consume then + if not TriggerEventHooks('useItem', { + source = source, + fromInventory = inventory.id, + fromType = inventory.type, + itemSlot = slot, + itemName = itemName, + itemDurability = durability, + itemConsume = consume, + itemMetadata = data.metadata + }) then return end + if data.count >= consume then local result = item.cb and item.cb('usingItem', item, inventory, slot) @@ -368,6 +379,17 @@ 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 + if not TriggerEventHooks('useItem', { + source = source, + fromInventory = inventory.id, + fromType = inventory.type, + itemSlot = slot, + itemName = itemName, + itemDurability = durability, + itemConsume = consume, + itemMetadata = data.metadata + }) then return end + inventory.usingItem = data -- This is used to call an external useItem function, i.e. ESX.UseItem -- If an error is being thrown on item use there is no internal solution. We previously kept a list