Page cover

🧠How to Install

FiveStar Script

Requirements

Before starting, make sure you have the latest version of qb_target Script installed on your server

You can fully customize the config file and customize the qb_target or qb_inventory or ox_invnetory scripts

Add Ammo item

#1 Make sure that all ammo item are registered in your inventory system.

Befor starting it, go to qb-core/shared/items.lua and add the following items

Config.Ammos = { 
    ["5.56mm"] = { Name = "5.56x45mm", Price = 10, Count = 20 },
    ["7.62mm"] = { Name = "7.62x39mm", Price = 10, Count = 20 },
    ["9mm"] = { Name = "9x19mm", Price = 10, Count = 20 },
    ["12_gauge"] = { Name = "12ga Rifled", Price = 10, Count = 20 },
    ["25_acp"] = { Name = ".25ACP Auto", Price = 10, Count = 20 },
    ["32_acp"] = { Name = "32ACP Auto", Price = 10, Count = 20 },
    ["44_magnum"] = { Name = ".357 Magnum", Price = 10, Count = 20 },
    ["45_acp"] = { Name = "45ACP Auto", Price = 10, Count = 20 },
    ["50mm_bmg"] = { Name = ".50 BMG", Price = 10, Count = 20 },
    ["54r"] = { Name = "7.62x39mm", Price = 10, Count = 20 },
    ["rocket"] = { Name = "Rocket", Price = 10, Count = 20 },
    ["grenade"] = { Name = "Grenade", Price = 10, Count = 20 },
    ["ammo_laser"] = { Name = "Laser charge", Price = 5000, Count = 250 },
}

Example:

["5.56mm"]              = { name = '5.56mm', label = '5.56x45mm', weight = 4, type = 'item', image = '5.56mm.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = '5.56x45mm for a weapon' },
...

#2 Open qb-core/shared/items.lua, This is qb default ammo, delete these

-- Ammo ITEMS
pistol_ammo                  = { name = 'pistol_ammo', label = 'Pistol ammo', weight = 200, type = 'item', image = 'pistol_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for Pistols' },
rifle_ammo                   = { name = 'rifle_ammo', label = 'Rifle ammo', weight = 1000, type = 'item', image = 'rifle_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for Rifles' },
smg_ammo                     = { name = 'smg_ammo', label = 'SMG ammo', weight = 500, type = 'item', image = 'smg_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for Sub Machine Guns' },
shotgun_ammo                 = { name = 'shotgun_ammo', label = 'Shotgun ammo', weight = 500, type = 'item', image = 'shotgun_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for Shotguns' },
mg_ammo                      = { name = 'mg_ammo', label = 'MG ammo', weight = 1000, type = 'item', image = 'mg_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for Machine Guns' },
snp_ammo                     = { name = 'snp_ammo', label = 'Sniper ammo', weight = 1000, type = 'item', image = 'rifle_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for Sniper Rifles' },
emp_ammo                     = { name = 'emp_ammo', label = 'EMP Ammo', weight = 200, type = 'item', image = 'emp_ammo.png', unique = false, useable = true, shouldClose = true, combinable = nil, description = 'Ammo for EMP Launcher' },

#3 Open qb-weapon/server/main.lua, line 208 to 222 is the ammo register code, delete it

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('qb-weapons:client:AddAmmo', source, properties.ammoType, properties.amount, item)
    end)
end

Pay attention to the photo 👇

#4 Open qb-weapons/client/main.lua, find register net event weapons:client:AddAmmo and replace it with the above code

RegisterNetEvent('weapons:client:AddAmmo', function(type, amount, itemData)
    local ped = cache.ped
    local weapon = GetSelectedPedWeapon(ped)
    if CurrentWeaponData then
        if QBCore.Shared.Weapons[weapon]["name"] ~= "weapon_unarmed" then
            if QBCore.Shared.Weapons[weapon]["ammotype"] ~= type then
                QBCore.Functions.Notify(type .." does not belong to this " .. QBCore.Shared.Weapons[weapon]["label"], "error")
                return
            end
            local total = GetAmmoInPedWeapon(ped, weapon)
            local _, maxAmmo = GetMaxAmmo(ped, weapon)
            if total < maxAmmo then
                QBCore.Functions.Progressbar("taking_bullets", Lang:t('info.loading_bullets'), Config.ReloadTime, false, true, {
                    disableMovement = false,
                    disableCarMovement = false,
                    disableMouse = false,
                    disableCombat = true,
                }, {}, {}, {}, function() -- Done
                    local newweapon = GetSelectedPedWeapon(ped)
                    if QBCore.Shared.Weapons[weapon] or QBCore.Shared.Weapons[weapon]["name"] ~= "weapon_unarmed" or QBCore.Shared.Weapons[weapon]["ammotype"] ~= type then
                        AddAmmoToPed(ped,weapon,amount)
                        TaskReloadWeapon(ped, false)
                        TriggerServerEvent("weapons:server:UpdateWeaponAmmo", CurrentWeaponData, total + amount)
                        TriggerServerEvent('weapons:server:removeWeaponAmmoItem', itemData)
                        TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items[itemData.name], "remove")
                        TriggerEvent('QBCore:Notify', Lang:t('success.reloaded'), "success")
                    end
                end, function()
                    QBCore.Functions.Notify(Lang:t('error.canceled'), "error")
                end)
            else
                QBCore.Functions.Notify(Lang:t('error.max_ammo'), "error")
            end
        else
            QBCore.Functions.Notify(Lang:t('error.no_weapon'), "error")
        end
    else
        QBCore.Functions.Notify(Lang:t('error.no_weapon'), "error")
    end
end)

#5 Open qb-core/shared/weapons.lua, all weapons are there and ammotype is written in front of it edit it

Register attachments

If you use ox_inventory, some of the weapon components are not added by the ox team and the list is not complete, the script does not encounter problems, but you cannot remove some attachments from the weapon.

Add License

Please put your license in server/license.lua | If your script is encrypted, enter your license

Last updated

Was this helpful?