Skip to content

Commit

Permalink
Merge pull request #189 from M4RFY/main
Browse files Browse the repository at this point in the history
Better way of using multiple items!
  • Loading branch information
GhzGarage authored Jun 9, 2024
2 parents 08e2b1b + 15c5cce commit 68a36ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
9 changes: 7 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ RegisterNetEvent('qb-weapons:client:AddAmmo', function(type, amount, itemData)
return
end

if QBCore.Shared.Weapons[weapon]['name'] == 'weapon_unarmed' or QBCore.Shared.Weapons[weapon]['ammotype'] ~= type:upper() then
QBCore.Functions.Notify(Lang:t('error.no_weapon'), 'error')
if QBCore.Shared.Weapons[weapon]['name'] == 'weapon_unarmed' then
QBCore.Functions.Notify(Lang:t('error.no_weapon_in_hand'), 'error')
return
end

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

Expand Down
1 change: 1 addition & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local Translations = {
canceled = 'Canceled',
max_ammo = 'Max Ammo Capacity',
no_weapon = 'You have no weapon.',
wrong_ammo = 'Your ammo type is wrong.',
no_support_attachment = 'This weapon does not support this attachment.',
no_weapon_in_hand = 'You dont have a weapon in your hand.',
weapon_broken = 'This weapon is broken and can not be used.',
Expand Down
42 changes: 15 additions & 27 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,33 +205,21 @@ end, 'god')
-- Items

-- AMMO
QBCore.Functions.CreateUseableItem('pistol_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_PISTOL', 12, item)
end)

QBCore.Functions.CreateUseableItem('rifle_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_RIFLE', 30, item)
end)

QBCore.Functions.CreateUseableItem('smg_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_SMG', 20, item)
end)

QBCore.Functions.CreateUseableItem('shotgun_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_SHOTGUN', 10, item)
end)

QBCore.Functions.CreateUseableItem('mg_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_MG', 30, item)
end)

QBCore.Functions.CreateUseableItem('snp_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_SNIPER', 10, item)
end)

QBCore.Functions.CreateUseableItem('emp_ammo', function(source, item)
TriggerClientEvent('qb-weapons:client:AddAmmo', source, 'AMMO_EMPLAUNCHER', 10, item)
end)
local AmmoTypes = {
pistol_ammo = { ammoType = 'AMMO_PISTOL', amount = 30 },
rifle_ammo = { ammoType = 'AMMO_RIFLE', amount = 30 },
smg_ammo = { ammoType = 'AMMO_SMG', amount = 30 },
shotgun_ammo = { ammoType = 'AMMO_SHOTGUN', amount = 10 },
mg_ammo = { ammoType = 'AMMO_MG', amount = 30 },
snp_ammo = { ammoType = 'AMMO_SNIPER', amount = 10 },
emp_ammo = { ammoType = 'AMMO_EMPLAUNCHER', amount = 10 }
}

for ammoItem, properties in pairs(AmmoTypes) do
QBCore.Functions.CreateUseableItem(ammoItem, function(source, item)
TriggerClientEvent('weapons:client:AddAmmo', source, properties.ammoType, properties.amount, item)
end)
end

-- TINTS

Expand Down

0 comments on commit 68a36ab

Please sign in to comment.