Improved saving loadouts (see desc)

- Only save weapon components if needed, wont save default clip anymore, and if no other component is available then its not saved at all

- Tint index not stored if not above 0
- Weapon label not saved in database since its useless
- Validate weapon on player load
This commit is contained in:
ElPumpo
2020-03-01 10:54:03 +01:00
parent 79d53a5550
commit 4d9af4e1ab
3 changed files with 52 additions and 16 deletions
+17 -6
View File
@@ -133,13 +133,24 @@ function loadESXPlayer(identifier, playerId)
return a.label < b.label
end)
if result[1].loadout then
userData.loadout = json.decode(result[1].loadout)
if result[1].loadout and result[1].loadout ~= '' then
local loadout = json.decode(result[1].loadout)
-- compatibility with old loadouts
for k,v in ipairs(userData.loadout) do
if not v.components then v.components = {} end
if not v.tintIndex then v.tintIndex = 0 end
for name,weapon in pairs(loadout) do
local label = ESX.GetWeaponLabel(name)
if label then
if not weapon.components then weapon.components = {} end
if not weapon.tintIndex then weapon.tintIndex = 0 end
table.insert(userData.loadout, {
name = name,
ammo = weapon.ammo,
label = label,
components = weapon.components,
tintIndex = weapon.tintIndex
})
end
end
end