@@ -393,7 +393,10 @@ exports('CanAddItem', CanAddItem)
393
393
--- @param source number The player ' s server ID.
394
394
--- @return number - Returns the free weight of the players inventory. Error will return 0
395
395
function GetFreeWeight (source )
396
- if not source then warn (" Source was not passed into GetFreeWeight" ) return 0 end
396
+ if not source then
397
+ warn (' Source was not passed into GetFreeWeight' )
398
+ return 0
399
+ end
397
400
local Player = QBCore .Functions .GetPlayer (source )
398
401
if not Player then return 0 end
399
402
@@ -604,9 +607,9 @@ function OpenInventory(source, identifier, data)
604
607
end
605
608
606
609
if not inventory then inventory = InitializeInventory (identifier , data ) end
607
- inventory .maxweight = (data and data .maxweight ) or (inventory and inventory .maxweight ) or Config .StashSize .maxweight
608
- inventory .slots = (data and data .slots ) or (inventory and inventory .slots ) or Config .StashSize .slots
609
- inventory .label = (data and data .label ) or (inventory and inventory .label ) or identifier
610
+ inventory .maxweight = (data and data .maxweight ) or (inventory and inventory .maxweight ) or Config .StashSize .maxweight
611
+ inventory .slots = (data and data .slots ) or (inventory and inventory .slots ) or Config .StashSize .slots
612
+ inventory .label = (data and data .label ) or (inventory and inventory .label ) or identifier
610
613
inventory .isOpen = source
611
614
612
615
local formattedInventory = {
@@ -774,6 +777,7 @@ function RemoveItem(identifier, item, amount, slot, reason)
774
777
print (' RemoveItem: Invalid item' )
775
778
return false
776
779
end
780
+
777
781
local inventory
778
782
local player = QBCore .Functions .GetPlayer (identifier )
779
783
@@ -797,7 +801,17 @@ function RemoveItem(identifier, item, amount, slot, reason)
797
801
return false
798
802
end
799
803
800
- local inventoryItem = inventory [slot ]
804
+ local inventoryItem = nil
805
+ local itemKey = nil
806
+
807
+ for key , invItem in pairs (inventory ) do
808
+ if invItem .slot == slot then
809
+ inventoryItem = invItem
810
+ itemKey = key
811
+ break
812
+ end
813
+ end
814
+
801
815
if not inventoryItem or inventoryItem .name :lower () ~= item :lower () then
802
816
print (' RemoveItem: Item not found in slot' )
803
817
return false
@@ -811,13 +825,17 @@ function RemoveItem(identifier, item, amount, slot, reason)
811
825
812
826
inventoryItem .amount = inventoryItem .amount - amount
813
827
if inventoryItem .amount <= 0 then
814
- inventory [slot ] = nil
828
+ inventory [itemKey ] = nil
829
+ else
830
+ inventory [itemKey ] = inventoryItem
815
831
end
816
832
817
833
if player then player .Functions .SetPlayerData (' items' , inventory ) end
834
+
818
835
local invName = player and GetPlayerName (identifier ) .. ' (' .. identifier .. ' )' or identifier
819
836
local removeReason = reason or ' No reason specified'
820
837
local resourceName = GetInvokingResource () or ' qb-inventory'
838
+
821
839
TriggerEvent (
822
840
' qb-log:server:CreateLog' ,
823
841
' playerinventory' ,
0 commit comments