Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 834957c

Browse files
committed
Add support for weapon reload useable items
1 parent 99335d7 commit 834957c

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

client/events/weapon.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ RegisterNetEvent(Config.ClientEventPrefix .. 'UseAmmoBox', function(itemRemove,
2222
return Core.Classes.Weapon.AmmoBoxes(itemRemove, itemGain)
2323
end)
2424

25+
RegisterNetEvent(Config.ClientEventPrefix .. 'ReloadWeapon', function()
26+
if source == '' then return end
27+
28+
return Core.Classes.Weapon.UpdateAmmo(true)
29+
end)
30+
2531
-- Recoil handler
2632
AddEventHandler('CEventGunShot', function(entities, eventEntity, args)
2733
local ped = PlayerPedId()

server/classes/inventory.lua

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ end
268268

269269
-- Creates useables defined in useables.config.lua
270270
function 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
285312
end
286313

287314
-- Sync player inventors to database
@@ -571,9 +598,10 @@ end
571598
function 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
612640
function 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

Comments
 (0)