Skip to main content

ps-mdt

server/dbm.lua
function ManageLicense(identifier, type, status, source)
local Player = QBCore.Functions.GetPlayerByCitizenId(identifier)
local licenseStatus = nil
if status == "give" then
if Player ~= nil then
licenseStatus = true
TriggerClientEvent('LicenseManager:addLicense', Player.PlayerData.source, type)
else
licenseStatus = false
end
elseif status == "revoke" then
licenseStatus = false
exports.bcs_licensemanager:RevokeLicense(identifier, type, source)
end
if Player ~= nil then
local licences = Player.PlayerData.metadata["licences"]
local newLicenses = {}
for k, v in pairs(licences) do
local status = v
if k == type then
status = licenseStatus
end
newLicenses[k] = status
end
Player.Functions.SetMetaData("licences", newLicenses)
else
local licenseType = '$.licences.' .. type
local result = MySQL.query.await(
'UPDATE `players` SET `metadata` = JSON_REPLACE(`metadata`, ?, ?) WHERE `citizenid` = ?',
{ licenseType, licenseStatus, identifier }) --seems to not work on older MYSQL versions, think about alternative
end
end

function UpdateAllLicenses(identifier, incomingLicenses, source)
local Player = QBCore.Functions.GetPlayerByCitizenId(identifier)
if Player ~= nil then
for k, v in pairs(incomingLicenses) do
if v then
TriggerClientEvent('LicenseManager:addLicense', Player.PlayerData.source, k)
else
exports.bcs_licensemanager:RevokeLicense(identifier, k, source)
end
end
Player.Functions.SetMetaData("licences", incomingLicenses)
else
local result = MySQL.scalar.await('SELECT metadata FROM players WHERE citizenid = @identifier',
{ ['@identifier'] = identifier })
result = json.decode(result)

result.licences = result.licences or {
['driver'] = true,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}

for k, _ in pairs(incomingLicenses) do
result.licences[k] = incomingLicenses[k]
if not incomingLicenses[k] then
exports.bcs_licensemanager:RevokeLicense(identifier, k, source)
end
end
MySQL.query.await('UPDATE `players` SET `metadata` = @metadata WHERE citizenid = @citizenid',
{ ['@metadata'] = json.encode(result), ['@citizenid'] = identifier })
end
end

Add src as the argument in both function, find them in server/main.lua

server/main.lua
    ManageLicense(cid, type, status, src)

UpdateAllLicenses(cid, licenses, src)