RegisterUsableItem() in a for loop not working

Hello,

I’m totally starting in lua and fivem developpement, and i would like to register some items as usable but i can’t.
Finally i found a way by duplicating the main.lua content for each magazine …, but it’s so ugly :stuck_out_tongue:
So, here the code not working :

in es_extended/locales/fr.lua
Locales['fr']['used_mag'] = 'vous rechargez ~o~%sx~s~ munitions dans votre %s.'

in esx_shops/config.lua

Config.Mags = {  --                             prix arme   prix mag (prix arme / 1000 * 5)
	{ Qtt = 32,    Name = 'MAG_PISTOL'},            -- 15000	75
	{ Qtt = 24,    Name = 'MAG_HEAVYPISTOL'},       -- 20000	100
	{ Qtt = 12,    Name = 'MAG_REVOLVER'},          -- 25000	125
	{ Qtt = 36,    Name = 'MAG_PISTOL50'},          -- 30000	150
	{ Qtt = 24,    Name = 'MAG_MICROSMG'},          -- 200000	1000
	{ Qtt = 42,    Name = 'MAG_SMG'},               -- 250000	1250
	{ Qtt = 42,    Name = 'MAG_ASSAULTRIFLE'},      -- 350000	1750
	{ Qtt = 42,    Name = 'MAG_COMPACTRIFLE'},      -- 400000	2000
	{ Qtt = 24,    Name = 'MAG_PUMPSHOTGUN'},       -- 300000	1500
	{ Qtt = 8,     Name = 'MAG_SNIPERRIFLE'},       -- 700000	3500
}

in esx_shops/server/main.lua

for i=1, #Config.Mags, 1 do
	
	ESX.RegisterUsableItem(Config.Mags[i], function(source)

		local _source = source
		local xPlayer = ESX.GetPlayerFromId(_source)
		local mag     = Config.Mags[i].Name
		local wea     = string.gsub (mag, "MAG_", "WEAPON_"),
		local qtt     = Config.Mags[i].Qtt

		xPlayer.removeInventoryItem(mag, 1)
		xPlayer.addWeapon(wea, qtt)

		TriggerClientEvent('esx:showNotification', source, _U('used_mag', ItemsLabels[wea], qtt))

	end)
	
end

It won’t work but if I replace Config.Mags[i].Name by ‘MAG_PISTOL’ or ‘MAG_PISTOL50’ it works, but like i said, it’s not like that we code !

Thanks in advance