Skip to content

Commit

Permalink
Merge pull request #199 from Qwerty1Verified/main
Browse files Browse the repository at this point in the history
fix: prevent reload if weapon switched to incorrect ammo
  • Loading branch information
GhzGarage authored Sep 7, 2024
2 parents d87e3dc + 287c1b5 commit f5ea878
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ RegisterNetEvent('qb-weapons:client:SetWeaponQuality', function(amount)
end
end)

RegisterNetEvent('qb-weapons:client:AddAmmo', function(type, amount, itemData)
RegisterNetEvent('qb-weapons:client:AddAmmo', function(ammoType, amount, itemData)
local ped = PlayerPedId()
local weapon = GetSelectedPedWeapon(ped)

Expand All @@ -80,7 +80,7 @@ RegisterNetEvent('qb-weapons:client:AddAmmo', function(type, amount, itemData)
return
end

if QBCore.Shared.Weapons[weapon]['ammotype'] ~= type:upper() then
if QBCore.Shared.Weapons[weapon]['ammotype'] ~= ammoType:upper() then
QBCore.Functions.Notify(Lang:t('error.wrong_ammo'), 'error')
return
end
Expand All @@ -99,14 +99,18 @@ RegisterNetEvent('qb-weapons:client:AddAmmo', function(type, amount, itemData)
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
if QBCore.Shared.Weapons[weapon] then
AddAmmoToPed(ped, weapon, amount)
TaskReloadWeapon(ped, false)
TriggerServerEvent('qb-weapons:server:UpdateWeaponAmmo', CurrentWeaponData, total + amount)
TriggerServerEvent('qb-weapons:server:removeWeaponAmmoItem', itemData)
TriggerEvent('qb-inventory:client:ItemBox', QBCore.Shared.Items[itemData.name], 'remove')
TriggerEvent('QBCore:Notify', Lang:t('success.reloaded'), 'success')
weapon = GetSelectedPedWeapon(ped) -- Get weapon at time of completion

if QBCore.Shared.Weapons[weapon]?.ammotype ~= ammoType then
return QBCore.Functions.Notify(Lang:t('error.wrong_ammo'), 'error')
end

AddAmmoToPed(ped, weapon, amount)
TaskReloadWeapon(ped, false)
TriggerServerEvent('qb-weapons:server:UpdateWeaponAmmo', CurrentWeaponData, total + amount)
TriggerServerEvent('qb-weapons:server:removeWeaponAmmoItem', itemData)
TriggerEvent('qb-inventory:client:ItemBox', QBCore.Shared.Items[itemData.name], 'remove')
TriggerEvent('QBCore:Notify', Lang:t('success.reloaded'), 'success')
end, function()
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
end)
Expand Down

0 comments on commit f5ea878

Please sign in to comment.