@@ -18,7 +18,7 @@ function it.hasItem(source, item, amount, metadata)
1818 end
1919
2020 if it .inventory == ' origen' then
21- local itemCount = origen_inventory :GetItemCount (source , item , metadata or nil , true )
21+ local itemCount = origen_inventory :getItemCount (source , item , metadata or nil , true )
2222 if itemCount then
2323 if itemCount >= amount then return true else return false end
2424 end
@@ -74,7 +74,7 @@ function it.giveItem(source, item, amount, metadata)
7474
7575 -- TODO: Check if there is a feedback
7676 if it .inventory == ' origen' then
77- local added , _ = origen_inventory :AddItem (source , item , amount , nil , nil , metadata or nil )
77+ local added , _ = origen_inventory :add (source , item , amount , nil , nil , metadata or nil )
7878 return added
7979 end
8080
@@ -138,9 +138,9 @@ function it.removeItem(source, item, amount, metadata)
138138 end
139139
140140 if it .inventory == ' origen' then
141- local removedItem = origen_inventory :GetItemCount (source , item , metadata or nil , true )
141+ local removedItem = origen_inventory :getItemCount (source , item , metadata or nil , true )
142142 if removedItem >= amount then
143- origen_inventory :RemoveItem (source , item , amount , nil , metadata or nil )
143+ origen_inventory :removeItem (source , item , amount , nil , metadata or nil )
144144 return true
145145 end
146146 end
@@ -209,14 +209,6 @@ function it.createUsableItem(item, cb)
209209 end
210210end
211211
212- function it .toggleItem (source , toggle , name , amount , metadata )
213- if toggle == 1 or toggle == true then
214- it .giveItem (source , name , amount , metadata or nil )
215- elseif toggle == 0 or toggle == false then
216- it .removeItem (source , name , amount , metadata or nil )
217- end
218- end
219-
220212--- Get the item count of a specific item in the player's inventory.
221213--- @param source number : The player ' s server ID.
222214--- @param item string : The item name.
@@ -232,7 +224,7 @@ function it.getItemCount(source, item, metadata)
232224 end
233225
234226 if it .inventory == ' origen' then
235- local itemCount = origen_inventory :GetItemCount (source , item , metadata or nil , true )
227+ local itemCount = origen_inventory :getItemCount (source , item , metadata or nil , true )
236228 if itemCount then return itemCount else
237229 lib .print .error (' [bridge | getItemCount] There was an error while getting the item count of ' .. item .. ' in the inventory. [ERR-INV-05]' )
238230 return 0
@@ -301,115 +293,87 @@ function it.getItemLabel(source, itemName)
301293 return itemLabel or itemName
302294end
303295
304- function it .getItemWeight (item )
305- local itemWeight
296+ function it .canCarryItem (src , item , amount )
306297 if it .inventory == ' ox' then
307- itemWeight = ox_inventory . GetItemWeight ( item )
298+ return ox_inventory : CanCarryItem ( src , item , amount )
308299 end
309300
310301 if it .inventory == ' origen' then
311- itemWeight = origen_inventory .GetItemWeight (item )
302+ -- TODO: Check if the player can carry the item
303+ return true
312304 end
313305
314306 if it .inventory == ' codem' then
315- itemWeight = exports [' codem-inventory' ]:GetItemWeight (item )
307+ -- TODO: Check if the play can carry the item
308+ return true
316309 end
317-
310+
318311 if it .core == ' qb-core' then
319- if CoreObject .Shared .Items [item ] then
320- itemWeight = CoreObject .Shared .Items [item ].weight
312+ if GetResourceState (' qb-inventory' ) == ' started' then
313+ local canAdd , reason = exports [' qb-inventory' ]:CanAddItem (src , item , amount )
314+ return canAdd
315+ else
316+ return true
321317 end
322318 end
319+
323320 if it .core == ' esx' then
324- if CoreObject .GetItemWeight then
325- itemWeight = CoreObject .GetItemWeight (item )
326- end
321+ local xPlayer = it .getPlayer (src )
322+ return xPlayer .canCarryItem (item , amount )
327323 end
328- return itemWeight or 0
329324end
325+ -- itemList = {[item] = amount, [item] = amount}
326+ function it .canCarryItems (src , itemList )
330327
331- function it .getCurrentWeight (src )
332- local currentWeight
333328 if it .inventory == ' ox' then
334- currentWeight = ox_inventory .GetWeight (src )
335- end
336-
337- if it .inventory == ' origen' then
338- currentWeight = origen_inventory .GetWeight (src )
339- end
340-
341- if it .inventory == ' codem' then
342- currentWeight = exports [' codem-inventory' ]:GetCurrentWeight (src )
343- end
344-
345- if it .core == ' qb-core' then
346- local Player = CoreObject .Functions .GetPlayer (src )
347- if Player then
348- currentWeight = Player .Functions .GetWeight ()
329+ local totalWeight = 0
330+ for item , amount in pairs (itemList ) do
331+ local itemData = ox_inventory :Items (item )
332+ if itemData then
333+ totalWeight = totalWeight + (itemData .weight * amount )
334+ if Config .Debug then
335+ lib .print .info (' Item: ' .. item .. ' Weight: ' .. itemData .weight .. ' Amount: ' .. amount )
336+ lib .print .info (' Total Weight: ' .. totalWeight )
337+ end
338+ end
349339 end
350- end
351- if it .core == ' esx' then
352- local Player = CoreObject .GetPlayerFromId (src )
353- if Player then
354- currentWeight = Player .getWeight ()
355- end
356- end
357- return currentWeight or 0
358- end
359-
360- function it .getMaxWeight (src )
361- local maxWeight
362- if it .inventory == ' ox' then
363- maxWeight = ox_inventory .GetMaxWeight (src )
340+ local canCarry , _ = ox_inventory :CanCarryWeight (src , totalWeight )
341+ return canCarry
364342 end
365343
366344 if it .inventory == ' origen' then
367- maxWeight = origen_inventory .GetMaxWeight (src )
345+ -- TODO: Check if the player can carry the item
346+ return true
368347 end
369348
370349 if it .inventory == ' codem' then
371- maxWeight = exports [' codem-inventory' ]:GetMaxWeight (src )
350+ -- TODO: Check if the play can carry the item
351+ return true
372352 end
373353
374354 if it .core == ' qb-core' then
375- local Player = CoreObject .Functions .GetPlayer (src )
376- if Player then
377- maxWeight = Player .Functions .GetMaxWeight ()
378- end
355+ return true
379356 end
357+
380358 if it .core == ' esx' then
381- local Player = CoreObject .GetPlayerFromId (src )
382- if Player then
383- maxWeight = Player .getMaxWeight ()
359+ local xPlayer = it .getPlayer (src )
360+ local currentWeight = xPlayer .getWeight ()
361+ local totalWeight = 0
362+ for item , amount in pairs (itemList ) do
363+ -- Get item from the database
364+ MySQL .Async .fetchAll (' SELECT * FROM items WHERE name = @name' , {
365+ [' @name' ] = item
366+ }, function (itemData )
367+ if itemData [1 ] then
368+ totalWeight = totalWeight + (itemData [1 ].weight * amount )
369+ end
370+ end )
371+ end
372+ if currentWeight + totalWeight <= CoreObject .GetConfig ().MaxWeight then
373+ return true
374+ else
375+ return false
384376 end
385- end
386- return maxWeight or 0
387- end
388-
389- function it .canCarryItem (src , item , amount )
390- local itemWeight = it .getItemWeight (item )
391- local currentWeight = it .getCurrentWeight (src )
392- local maxWeight = it .getMaxWeight (src )
393- local totalWeight = itemWeight * amount
394- if currentWeight + totalWeight <= maxWeight then
395- return true
396- else
397- return false
398- end
399- end
400- -- itemList = {[item] = amount, [item] = amount}
401- function it .canCarryItems (src , itemList )
402- local totalWeight = 0
403- for item , amount in pairs (itemList ) do
404- local itemWeight = it .getItemWeight (item )
405- totalWeight = totalWeight + (itemWeight * amount )
406- end
407- local currentWeight = it .getCurrentWeight (src )
408- local maxWeight = it .getMaxWeight (src )
409- if currentWeight + totalWeight <= maxWeight then
410- return true
411- else
412- return false
413377 end
414378end
415379
0 commit comments