268268
269269-- Creates useables defined in useables.config.lua
270270function Core .Classes .Inventory .CreateUseables ()
271+ local items = Core .Classes .Inventory :GetState (" Items" ) or {}
272+
271273 for item , itemData in pairs (Config .Items ) do
272274 if itemData .useable and itemData .onUse then
273275 if type (itemData .onUse ) == " function" then
@@ -282,6 +284,31 @@ function Core.Classes.Inventory.CreateUseables ()
282284 end )
283285 end
284286 end
287+
288+ local registered = {}
289+ for _ , itemName in pairs (Config .Weapons .AmmoItems ) do
290+ if itemName and not registered [itemName ] and items [itemName ] then
291+ registered [itemName ] = true
292+ Core .Classes .Inventory .CreateUseableItem (itemName , function (source )
293+ TriggerClientEvent (Config .ClientEventPrefix .. ' ReloadWeapon' , source )
294+ end )
295+ end
296+ end
297+
298+ for itemName , itemData in pairs (items ) do
299+ local isWeapon = itemData .type == " weapon" or (type (itemName ) == " string" and itemName :sub (1 , 7 ) == " weapon_" )
300+ if itemData .useable and not isWeapon then
301+ if not Framework .Server .GetUseableItem (itemName ) then
302+ local label = itemData .label or itemName
303+ Core .Classes .Inventory .CreateUseableItem (itemName , function (source )
304+ local player = Framework .Server .GetPlayer (source )
305+ if player then
306+ Core .Classes .Inventory .Utilities .Notify (player , (label .. " has no use action configured" ), " error" )
307+ end
308+ end )
309+ end
310+ end
311+ end
285312end
286313
287314-- Sync player inventors to database
571598function Core .Classes .Inventory .ValidateAndUseItem (src , itemData )
572599 if itemData then
573600 local itemInfo = Core .Classes .Inventory :GetState (" Items" )[itemData .name ]
601+ local isWeapon = itemData .type == " weapon" or (type (itemData .name ) == " string" and itemData .name :sub (1 , 7 ) == " weapon_" )
574602
575603 -- Handle weapon types
576- if itemData . type == " weapon " then
604+ if isWeapon then
577605
578606 -- Validate quality
579607 if itemData .info .quality then
@@ -612,13 +640,13 @@ end
612640function Core .Classes .Inventory .UseItem (item , ...)
613641 local itemData = Framework .Server .GetUseableItem (item )
614642 local callback = type (itemData ) == ' table' and
615- (rawget (itemData , ' __cfx_functionReference' ) and itemData or itemData .cb or itemData .callback ) or
643+ (rawget (itemData , ' __cfx_functionReference' ) and itemData or itemData .cb or itemData .callback or itemData . func ) or
616644 type (itemData ) == ' function' and itemData
617645 if not callback then
618646 return Core .Utilities .Log ({
619647 type = " error" ,
620648 title = " Core.Classes.Inventory.UseItem" ,
621- message = " Unable to use item, no callback found."
649+ message = ( " Unable to use item '%s' , no callback found." ): format ( tostring ( item ))
622650 })
623651 end
624652
0 commit comments