JG Docs
Dealerships

License Check

This guide currently only works with JG Dealerships V2.

First, add the following to config.lua.

-- License Requirements
-- Configure license requirements for dealerships
-- Note: In V2, dealership locations are stored in the database
-- Use the dealership ID (UUID) from the dealership_locations to configure license requirements
Config.DealershipLicenses = {
   ["b4dbbcca-a7ba-462a-b772-3c3e6434612c"] = { -- Replace with your dealership ID
     enabled = true,
     licenseType = "driver" -- The license type required (e.g., "boat", "pilot", "driver")
   },
}

Replace the ShowroomPreCheck(dealershipId) function in config-cl.lua with the code below.

---@param dealershipId string
---@return boolean allowed
function ShowroomPreCheck(dealershipId)
  local licenseConfig = lib.callback.await("jg-dealerships:server:get-dealership-license-config", false, dealershipId)
  
  if not licenseConfig then
    return true
  end

  if not licenseConfig.enabled then
    return true
  end

  local Player = Framework.Client.GetPlayerData()
  local hasLicense = Player.metadata and Player.metadata['licences'] and Player.metadata['licences'][licenseConfig.licenseType]

  if not hasLicense then
    local msg = "You require a " .. licenseConfig.licenseType .. " license to access this showroom."
    Framework.Client.Notify(msg, "error", 5000)
    return false
  end

  return true
end

Add the code below to config-sv.lua for this integration to work.

---@param src integer
---@param dealershipId string
---@return table|nil configuration { enabled: boolean, licenseType: string }
lib.callback.register("jg-dealerships:server:get-dealership-license-config", function(src, dealershipId)
  if not dealershipId then
    return nil
  end

  local licenseConfig = Config.DealershipLicenses[dealershipId]
  
  if not licenseConfig then
    return nil
  end

  return licenseConfig
end)