Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent reload if weapon switched to incorrect ammo #199

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading