License Check
Firstly you will need to add the following to each dealership in the config.lua
licenseCheck = false, -- false = no license required to open dealership
license = 'driver', -- this is the license name required
You will need to replace the following function in config-cl.lua function ShowroomPreCheck(dealershipId)
function ShowroomPreCheck(dealershipId)
local Player = Framework.Client.GetPlayerData()
local licenseCheck = Config.DealershipLocations[dealershipId].licenseCheck
local license = Player.metadata['licences'][Config.DealershipLocations[dealershipId].license]
if licenseCheck then
if not license then
allowed = false
elseif license then
print(license)
allowed = true
end
else
allowed = true
end
if not allowed then
local msg = "You require a ".. Config.DealershipLocations[dealershipId].license
Framework.Client.Notify(msg, "error", 1000 )
return false
end
return true
end
function ShowroomPreCheck(dealershipId)
local allowed = true
local licenseCheck = Config.DealershipLocations[dealershipId].licenseCheck
local licenseType = Config.DealershipLocations[dealershipId].license
if licenseCheck and licenseType then
local hasLicense = lib.callback.await('jg-dealerships:server:check-license', false, licenseType)
if not hasLicense then
allowed = false
end
end
if not allowed then
local msg = "You require a " .. licenseType .. " license to access this showroom."
Framework.Client.Notify(msg, "error", 1000)
return false
end
return true
end
-- the code block below is pasted inside the config-sv.lua
lib.callback.register('jg-dealerships:server:check-license', function(src, licenseType)
local identifier = Framework.Server.GetPlayerIdentifier(src)
local result = MySQL.scalar.await(
'SELECT type FROM user_licenses WHERE type = ? AND owner = ?',
{licenseType, identifier}
)
return result ~= nil
end)
Do you only want license check for individual dealerships? Then replace the config-cl function with the following
function ShowroomPreCheck(dealershipId)
if dealershipId ~= "boat" then
return true
end
local allowed = true
local Player = Framework.Client.GetPlayerData()
local licenseType = Config.DealershipLocations[dealershipId].license
local licenseCheck = Config.DealershipLocations[dealershipId].licenseCheck
local hasLicense = Player.metadata['licences'] and Player.metadata['licences'][licenseType]
if licenseCheck then
if not hasLicense then
allowed = false
end
end
if not allowed then
local msg = "You require a " .. licenseType .. " license to access this showroom."
Framework.Client.Notify(msg, "error", 1000)
return false
end
return true
end
function ShowroomPreCheck(dealershipId)
-- Only check licenses for "boat" dealership
if dealershipId ~= "boat" then
return true
end
local allowed = true
local licenseCheck = Config.DealershipLocations[dealershipId].licenseCheck
local licenseType = Config.DealershipLocations[dealershipId].license
if licenseCheck and licenseType then
local hasLicense = lib.callback.await('jg-dealerships:server:check-license', false, licenseType)
if not hasLicense then
allowed = false
end
end
if not allowed then
local msg = "You require a " .. licenseType .. " license to access this showroom."
Framework.Client.Notify(msg, "error", 1000)
return false
end
return true
end
-- the code block below is pasted inside the config-sv.lua
lib.callback.register('jg-dealerships:server:check-license', function(src, licenseType)
local identifier = Framework.Server.GetPlayerIdentifier(src)
local result = MySQL.scalar.await(
'SELECT type FROM user_licenses WHERE type = ? AND owner = ?',
{licenseType, identifier}
)
return result ~= nil
end)
Last updated
Was this helpful?