From 37ada40b219c84dee6a02fe6e1d572ab20af48c7 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 23 Dec 2018 12:21:28 +0100 Subject: [PATCH] Fixed ammo duplicate on restoreLoadout, fixes #171 --- client/main.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index b4c305d9..bc0f6ad3 100644 --- a/client/main.lua +++ b/client/main.lua @@ -94,12 +94,19 @@ end) AddEventHandler('esx:restoreLoadout', function() local playerPed = PlayerPedId() + local ammoTypes = {} RemoveAllPedWeapons(playerPed, true) for i=1, #ESX.PlayerData.loadout, 1 do local weaponHash = GetHashKey(ESX.PlayerData.loadout[i].name) - GiveWeaponToPed(playerPed, weaponHash, ESX.PlayerData.loadout[i].ammo, false, false) + GiveWeaponToPed(playerPed, weaponHash, 0, false, false) + local ammoType = GetPedAmmoTypeFromWeapon(playerPed, weaponHash) + + if not ammoTypes[ammoType] then + AddAmmoToPed(playerPed, weaponHash, ESX.PlayerData.loadout[i].ammo) + ammoTypes[ammoType] = true + end end LoadoutLoaded = true