πŸ”₯All scripts on our website are 50% off!πŸ”₯
Logo

License Item Configuration

By default, the license is applied to the database (both on ESX and QB). If you want to deliver licenses as items, you have several options:

Option 1: Items Created in the Core

If you have created license items in your core with metadata support, you can modify the applyLicense function in config.lua (line 385):

QBCore Example

elseif Config.Framework == "qb" then
    if license == 'A' then
        local licenseTable = xPlayer.PlayerData.metadata['licences']
        licenseTable[Config.licenseNameMoto] = true
        xPlayer.Functions.SetMetaData('licences', licenseTable)
        local info = {}
        info.playerName = xPlayer.PlayerData.charinfo.firstname .. ' ' .. xPlayer.PlayerData.charinfo.lastname
        info.citizenid = xPlayer.PlayerData.citizenid
        xPlayer.Functions.AddItem('motorcycle_license', 1, nil, info)
    elseif license == 'B' then
        local licenseTable = xPlayer.PlayerData.metadata['licences']
        licenseTable[Config.licenseNameCar] = true
        xPlayer.Functions.SetMetaData('licences', licenseTable)
        local info = {}
        info.playerName = xPlayer.PlayerData.charinfo.firstname .. ' ' .. xPlayer.PlayerData.charinfo.lastname
        info.citizenid = xPlayer.PlayerData.citizenid
        xPlayer.Functions.AddItem('car_license', 1, nil, info)
    elseif license == 'C' then
        local licenseTable = xPlayer.PlayerData.metadata['licences']
        licenseTable[Config.licenseNameTruck] = true
        xPlayer.Functions.SetMetaData('licences', licenseTable)
        local info = {}
        info.playerName = xPlayer.PlayerData.charinfo.firstname .. ' ' .. xPlayer.PlayerData.charinfo.lastname
        info.citizenid = xPlayer.PlayerData.citizenid
        xPlayer.Functions.AddItem('truck_license', 1, nil, info)
    end
end

Option 2: License Script Integration

If you're using a license script, you can use their provided trigger or export:

Example with Trigger

if Config.Framework == "esx" then
    if license == 'A' then
        SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
            ['@type'] = Config.licenseNameMoto,
            ['@owner'] = xPlayer.identifier
        })
        TriggerEvent("licenses:addLicense", xPlayer.source, "motorcycle")
    elseif license == 'B' then
        SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
            ['@type'] = Config.licenseNameCar,
            ['@owner'] = xPlayer.identifier
        })
        TriggerEvent("licenses:addLicense", xPlayer.source, "car")
    elseif license == 'C' then
        SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
            ['@type'] = Config.licenseNameTruck,
            ['@owner'] = xPlayer.identifier
        })
        TriggerEvent("licenses:addLicense", xPlayer.source, "truck")
    end
end

Option 3: Command-Based (Not Recommended)

If your license script allows adding licenses via command:

if Config.Framework == "esx" then
    if license == 'A' then
        SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
            ['@type'] = Config.licenseNameMoto,
            ['@owner'] = xPlayer.identifier
        })
        ExecuteCommand("addlicense ".." "..xPlayer.source.." ".. "motorcycle")
    elseif license == 'B' then
        SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
            ['@type'] = Config.licenseNameCar,
            ['@owner'] = xPlayer.identifier
        })
        ExecuteCommand("addlicense ".." "..xPlayer.source.." ".. "car")
    elseif license == 'C' then
        SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
            ['@type'] = Config.licenseNameTruck,
            ['@owner'] = xPlayer.identifier
        })
        ExecuteCommand("addlicense ".." "..xPlayer.source.." ".. "truck")
    end
end