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

Better way of using multiple items! #189

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
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
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
Loading