mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
improvement+fix(client/main): Save weapon ammo properly; create a timer for saving ammo instead of triggering an event every frame
This commit is contained in:
+15
-7
@@ -371,10 +371,17 @@ end
|
||||
function StartServerSyncLoops()
|
||||
-- keep track of ammo
|
||||
Citizen.CreateThread(function()
|
||||
local currentWeapon = {timer=0}
|
||||
while ESX.PlayerLoaded do
|
||||
Citizen.Wait(1000)
|
||||
local sleep = 5
|
||||
|
||||
local letSleep = true
|
||||
if currentWeapon.timer == sleep then
|
||||
local ammoCount = GetAmmoInPedWeapon(ESX.PlayerData.ped, currentWeapon.hash)
|
||||
TriggerServerEvent('esx:updateWeaponAmmo', currentWeapon.name, ammoCount)
|
||||
currentWeapon.timer = 0
|
||||
elseif currentWeapon.timer > sleep then
|
||||
currentWeapon.timer = currentWeapon.timer - sleep
|
||||
end
|
||||
|
||||
if IsPedArmed(ESX.PlayerData.ped, 4) then
|
||||
if IsPedShooting(ESX.PlayerData.ped) then
|
||||
@@ -382,14 +389,15 @@ function StartServerSyncLoops()
|
||||
local weapon = ESX.GetWeaponFromHash(weaponHash)
|
||||
|
||||
if weapon then
|
||||
local ammoCount = GetAmmoInPedWeapon(ESX.PlayerData.ped, weaponHash)
|
||||
TriggerServerEvent('esx:updateWeaponAmmo', weapon.name, ammoCount)
|
||||
currentWeapon.name = weapon.name
|
||||
currentWeapon.hash = weaponHash
|
||||
currentWeapon.timer = 100 * sleep
|
||||
end
|
||||
end
|
||||
else
|
||||
sleep = 200
|
||||
end
|
||||
if letSleep then
|
||||
Citizen.Wait(500)
|
||||
end
|
||||
Citizen.Wait(sleep)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user