Installation Guide

This comprehensive guide outlines the necessary steps to integrate the QB-Shops system with weapon licenses. Ensure you follow each step meticulously for a successful implementation.

Prerequisites

  • Ensure that your QB-Shops system is up to date with the latest version. This integration requires the use of an updated QB-Shops version.

  • Follow the Below Steps. ⬇️


Step 1: Database Setup

  • Execute the following SQL query to create a new table named weapon_restrict in your database:

    CREATE TABLE `weapon_restrict` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `name` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
        `uses` INT(11) NULL DEFAULT '0',
        PRIMARY KEY (`id`) USING BTREE
    )
    COLLATE='utf8mb3_general_ci'
    ENGINE=InnoDB
    AUTO_INCREMENT=4
    ;

Step 2: Update Weapons Shop Config

  • In your weapons shop configuration file, add the following lines at the end:

    ['weapons'] = {
        -- Existing weapon entries...
    
        {name = 'weapon_pistol', price = 2500, amount = 5, info = {}, type = 'weapon', requiredLicense = { 'weapon' }, requiredLicenseItem = { 'weaponlicense' }, increaseuse = true},
        {name = 'weapon_snspistol', price = 1500, amount = 5, info = {}, type = 'weapon', requiredLicense = { 'weapon' }, requiredLicenseItem = { 'weaponlicense' }, increaseuse = true},
        {name = 'weapon_vintagepistol', price = 4000, amount = 5, info = {}, type = 'weapon', requiredLicense = { 'weapon' }, requiredLicenseItem = { 'weaponlicense' }, increaseuse = true},
    },
  • Ensure that increaseuse and requiredLicenseItem are set to 'true' and

    { 'weaponlicense' } respectively for the specified weapons.


Step 3: Modify QB-Inventory Code

  • In the qb-inventory/server/main.lua file, find the section containing:

    elseif QBCore.Shared.SplitStr(shopType, "_")[1] == "Itemshop" then
        -- Existing code...
  • Replace it with the provided⬇️ code block.

    elseif QBCore.Shared.SplitStr(shopType, "_")[1] == "Itemshop" then
        local hasitem = Player.Functions.GetItemByName("weaponlicense")
        local work = false
        local bankBalance = Player.PlayerData.money["bank"]
        local cashBalance = Player.PlayerData.money["cash"]
    
        if hasitem then
            local licencename = hasitem.info.firstname.. " ".. hasitem.info.lastname
            local existingLicense = MySQL.prepare.await('SELECT * FROM weapon_restrict WHERE name = ?', { licencename })
            if existingLicense then
                if existingLicense.uses then
    
                    if bankBalance >= price or cashBalance >= price then
    
                        if not itemData or (itemData.increaseuse and existingLicense.uses >= 5) then
                            TriggerClientEvent('QBCore:Notify', src, 'You can only buy '.. 5 ..' weapons on your Weapon License', 'error', 5000)
                            return
                        end
        
                        if itemData.increaseuse then
                            MySQL.Sync.execute('UPDATE weapon_restrict SET uses = uses + 1 WHERE name = ?', { licencename })
                        end							
                    end
                else
                    TriggerClientEvent('QBCore:Notify', src, 'Error processing weapon license information', 'error', 5000)
                end
            else
                MySQL.Sync.execute('INSERT INTO weapon_restrict (name, uses) VALUES (?, 0)', { licencename })
            end
        end
        if Player.Functions.RemoveMoney("cash", price, "itemshop-bought-item") then
            if QBCore.Shared.SplitStr(itemData.name, "_")[1] == "weapon" then
                itemData.info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4))
                itemData.info.quality = 100
            end
            AddItem(src, itemData.name, fromAmount, toSlot, itemData.info)
            TriggerClientEvent('qb-shops:client:UpdateShop', src, QBCore.Shared.SplitStr(shopType, "_")[2], itemData, fromAmount)
            QBCore.Functions.Notify(src, itemInfo["label"] .. " bought!", "success")
            TriggerEvent("qb-log:server:CreateLog", "shops", "Shop item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price)
        elseif bankBalance >= price then
            if Player.PlayerData.metadata.isbankfreezed then return TriggerClientEvent('QBCore:Notify', src, "Your Bank Account is freezed", "error", 3500) end
            Player.Functions.RemoveMoney("bank", price, "itemshop-bought-item")
            if QBCore.Shared.SplitStr(itemData.name, "_")[1] == "weapon" then
                itemData.info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4))
                itemData.info.quality = 100
            end
            AddItem(src, itemData.name, fromAmount, toSlot, itemData.info)
            TriggerClientEvent('qb-shops:client:UpdateShop', src, QBCore.Shared.SplitStr(shopType, "_")[2], itemData, fromAmount)
            QBCore.Functions.Notify(src, itemInfo["label"] .. " bought!", "success")
            TriggerEvent("qb-log:server:CreateLog", "shops", "Shop item bought", "green", "**"..GetPlayerName(src) .. "** bought a " .. itemInfo["label"] .. " for $"..price)
        else
            QBCore.Functions.Notify(src, "You don't have enough cash..", "error")
        end
    else    

Step 4: Add Utility Function

  • Add the following function anywhere in the qb-shops/client/main.lua file:

    local function hasLicenseItem(licenses)
        for _, license in ipairs(licenses) do
            local hasitem = exports['qb-inventory']:HasItem(license)
            if hasitem then return true end
        end
        return false
    end

Step 5: Update Shop Product Check

Modify the code block in the same qb-shops/client/main.lua file that checks for required licenses:

  • Replace this

    if curProduct.requiredLicense and not hasLicense(curProduct.requiredLicense, PlayerData.metadata["licences"]) then
        -- Existing code...
    end
  • With:

    if curProduct.requiredLicense and not hasLicenseItem(curProduct.requiredLicenseItem) then
        -- Existing code...
    end

Last updated