Armory problem with ammo

Hello to everyone! I want to change the code about weapons-ammo in armorys to sync the ammo of weapon you deposit!I know where i can change the ammo value when you take out weapon! In esx_policejob\server\main.lua at line 277 this code

276 local xPlayer = ESX.GetPlayerFromId(source)
277 xPlayer.addWeapon(weaponName, 500)

But i want to change the code when you add weapon in armory to save your ammo and when you take it out to have the same ammo you haved before! Like i have put my weapon in armory with 89 ammo and i want to take it out with 89 ammo!! If anyone know a solution about this pls share it with me !

1 Like

If you want to save the amount of ammo someone puts back you’d need to save it in the database.

You’ll want to create a server side trigger.

Ex:

RegisterServerEvent("esx_policejob:policeArmoryPut")
AddEventHandler("esx_policejob:policeArmoryPut", function(name,nameIdentifier,wepaonName,weaponAmmo)
   MySQL.Async.execute('INSERT INTO policeArmory (sourceName, sourceIdentifer, wepaonName, weaponAmmo) VALUES (@sourceName, @sourceIdentifer, @wepaonName, @weaponAmmo)',
            {
				['@sourceName']        = name,
                ['@sourceIdentifer']        = nameIdentifier,
                ['@wepaonName'] = wepaonName,
				['@weaponAmmo'] = weaponAmmo
            })

end)

and run a client side for the esx_policejob:policeArmoryPut trigger saving the appropriate info.

Then you’ll also want to make another server side esx_policejob:policeArmoryGet that removes that specific record, or you can have another colom that tracks it by date and time and if someone picked their weapon/ammo up.

I feel like that should be enough info to get you started.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.