From cb8050a13aeab4d860229add5c72b05d0085ed94 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sat, 25 May 2024 10:30:44 +1000 Subject: [PATCH] fix(client): respect weapon clip size in vehicles I don't know why GTA5's weapon/ammo natives are so dogshit. Resolves #1712. --- client.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/client.lua b/client.lua index b0609aeac..6a01adf48 100644 --- a/client.lua +++ b/client.lua @@ -601,14 +601,25 @@ local function useSlot(slot, noAnim) if newAmmo == currentAmmo then return end - if cache.vehicle then - SetAmmoInClip(playerPed, currentWeapon.hash, newAmmo) + AddAmmoToPed(playerPed, currentWeapon.hash, addAmmo) + if cache.vehicle then if cache.seat > -1 or IsVehicleStopped(cache.vehicle) then TaskReloadWeapon(playerPed, true) - end + else + -- This is a hacky solution for forcing ammo to properly load into the + -- weapon clip while driving; without it, ammo will be added but won't + -- load until the player stops doing anything. i.e. if you keep shooting, + -- the weapon will not reload until the clip empties. + -- And yes - for some reason RefillAmmoInstantly needs to run in a loop. + lib.waitFor(function() + RefillAmmoInstantly(playerPed) + + local _, ammo = GetAmmoInClip(playerPed, currentWeapon.hash) + return ammo == newAmmo or nil + end) + end else - AddAmmoToPed(playerPed, currentWeapon.hash, addAmmo) Wait(100) MakePedReload(playerPed)