Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 5ff6994

Browse files
committed
feat(server/inventory): send slot data to AddItem callback
Sends item data such as the slot, count, metadata, etc. as the second argument when an item was successfully given to the target. Mostly useful for getting the generated metadata for an item.
1 parent b52bb54 commit 5ff6994

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

modules/inventory/server.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ function Inventory.AddItem(inv, item, count, metadata, slot, cb)
541541
if type(item) ~= 'table' then item = Items(item) end
542542
if type(inv) ~= 'table' then inv = Inventory(inv) end
543543
count = math.floor(count + 0.5)
544-
local success, reason = false, nil
544+
local success, resp
545+
545546
if item then
546547
if inv then
547548
metadata, count = Items.Metadata(inv.id, item, metadata or {}, count)
@@ -570,23 +571,27 @@ function Inventory.AddItem(inv, item, count, metadata, slot, cb)
570571
if slot then
571572
Inventory.SetSlot(inv, item, count, metadata, slot)
572573
inv.weight = inv.weight + (item.weight + (metadata?.weight or 0)) * count
573-
success = true
574+
575+
if cb then
576+
success = true
577+
resp = inv.items[slot]
578+
end
574579

575580
if inv.type == 'player' then
576581
if shared.framework == 'esx' then Inventory.SyncInventory(inv) end
577582
TriggerClientEvent('ox_inventory:updateSlots', inv.id, {{item = inv.items[slot], inventory = inv.type}}, {left=inv.weight, right=inv.open and Inventories[inv.open]?.weight}, count, false)
578583
end
579584
else
580-
reason = 'inventory_full'
585+
resp = cb and 'inventory_full'
581586
end
582587
else
583-
reason = 'invalid_inventory'
588+
resp = cb and 'invalid_inventory'
584589
end
585590
else
586-
reason = 'invalid_item'
591+
resp = cb and 'invalid_item'
587592
end
588593

589-
if cb then cb(success, reason) end
594+
if cb then cb(success, resp) end
590595
end
591596
exports('AddItem', Inventory.AddItem)
592597

0 commit comments

Comments
 (0)