By default, the license is applied to the database (both on ESX and QB). If what you want is to perform a license delivery as an item you must take into account if the license is simply an item that you have created in your core. For example, something like: "boat_license", "yacht_license". Or if it is managed by a license script.
ITEMS CREATED IN THE CORE
If you have created the item from the core, as if it were any other type of item and your core allows you to have metadata in the items you can do the following assuming that you have the items indicated above
In line 362 of config.lua you have an open function called "applyLicense" in which you can edit what happens when a user successfully completes the practical test.
function applyLicense(xPlayer, license)
if Config.Framework == "esx" then
if license == 'OUPV' then
SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
['@type'] = Config.licenseNameBoat,
['@owner'] = xPlayer.identifier
})
elseif license == 'YM' then
SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
['@type'] = Config.licenseNameYacht,
['@owner'] = xPlayer.identifier
})
end
elseif Config.Framework == "qb" then
if license == 'OUPV' then
local licenseTable = xPlayer.PlayerData.metadata['licences']
licenseTable[Config.licenseNameBoat] = true
xPlayer.Functions.SetMetaData('licences', licenseTable)
elseif license == 'YM' then
local licenseTable = xPlayer.PlayerData.metadata['licences']
licenseTable[Config.licenseNameYacht] = true
xPlayer.Functions.SetMetaData('licences', licenseTable)
end
end
end
In this example we will use the QB version to add an item to the user, according to the test he has performed.
We will use the following code to deliver the item with the metadata of the name and citizenid. This way each license delivered will be unique:
local info = {}
info.playerName = xPlayer.PlayerData.charinfo.firstname .. ' ' .. xPlayer.PlayerData.charinfo.lastname
info.citizenid = xPlayer.PlayerData.citizenid
xPlayer.Functions.AddItem('boat_license', 1, nil, info)
the code would look like this:
elseif Config.Framework == "qb" then
if license == 'OUPV' then
local licenseTable = xPlayer.PlayerData.metadata['licences']
licenseTable[Config.licenseNameBoat] = 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('boat_license', 1, nil, info)
elseif license == 'YM' then
local licenseTable = xPlayer.PlayerData.metadata['licences']
licenseTable[Config.licenseNameYacht] = 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('yacht_license', 1, nil, info)
end
end
ITEMS GENERATED BY LICENSE SCRIPT
If instead of creating the license items manually, you are using a license script it may be easier to adapt the code. You will have to check the documentation of your license script but usually you will be given an export or trigger that you can run in any function.
Imagine that we have this trigger obtained from the licensing script documentation:
An example, in this case on the esx side would look like this:
if Config.Framework == "esx" then
if license == 'OUPV' then
SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
['@type'] = Config.licenseNameBoat,
['@owner'] = xPlayer.identifier
})
TriggerEvent("licenses:addLicense", xPlayer.source, "boat")
elseif license == 'YM' then
SqlFunc(Config.Mysql, 'execute', 'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
['@type'] = Config.licenseNameYacht,
['@owner'] = xPlayer.identifier
})
TriggerEvent("licenses:addLicense", xPlayer.source, "yacht")
end
[...]
BY COMMAND
As a third option, although we do not recommend it. It is possible to deliver licenses if your licensing script allows you to deliver a license to a user by command.
For example, if the script has the command /addlicense ID Type