Sync consumed ammo with server properly

No more security issues here!
This commit is contained in:
ElPumpo
2020-03-22 09:43:43 +01:00
parent ff9930068f
commit 9a1dfa42ca
4 changed files with 48 additions and 56 deletions
+12 -39
View File
@@ -393,53 +393,26 @@ if Config.EnableHud then
end)
end
-- Save loadout
-- Keep track of ammo usage
Citizen.CreateThread(function()
local lastLoadout = {}
while true do
Citizen.Wait(5000)
local playerPed, loadout, loadoutChanged = PlayerPedId(), {}, false
Citizen.Wait(0)
for k,v in ipairs(Config.Weapons) do
local weaponName = v.name
local weaponHash = GetHashKey(weaponName)
if isDead then
Citizen.Wait(500)
else
local playerPed = PlayerPedId()
if HasPedGotWeapon(playerPed, weaponHash, false) then
local ammo, tintIndex, weaponComponents = GetAmmoInPedWeapon(playerPed, weaponHash), GetPedWeaponTintIndex(playerPed, weaponHash), {}
if IsPedShooting(playerPed) then
local _,weaponHash = GetCurrentPedWeapon(playerPed, true)
local weapon = ESX.GetWeaponFromHash(weaponHash)
for k2,v2 in ipairs(v.components) do
if HasPedGotWeaponComponent(playerPed, weaponHash, v2.hash) then
table.insert(weaponComponents, v2.name)
end
if weapon then
local ammoCount = GetAmmoInPedWeapon(playerPed, weaponHash)
TriggerServerEvent('esx:updateWeaponAmmo', weapon.name, ammoCount)
end
if not lastLoadout[weaponName] or lastLoadout[weaponName] ~= ammo then
loadoutChanged = true
end
lastLoadout[weaponName] = ammo
table.insert(loadout, {
name = weaponName,
ammo = ammo,
label = v.label,
components = weaponComponents,
tintIndex = tintIndex
})
else
if lastLoadout[weaponName] then
loadoutChanged = true
end
lastLoadout[weaponName] = nil
end
end
if loadoutChanged and isLoadoutLoaded then
ESX.PlayerData.loadout = loadout
TriggerServerEvent('esx:updateLoadout', loadout)
end
end
end)