Skip to content

Commit

Permalink
fix(client): respect weapon clip size in vehicles
Browse files Browse the repository at this point in the history
I don't know why GTA5's weapon/ammo natives are so dogshit.
Resolves #1712.
  • Loading branch information
thelindat committed May 25, 2024
1 parent 54e91d1 commit cb8050a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit cb8050a

Please sign in to comment.