QBCORE

license check for qbcore

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-sv.lua "jg-dealerships:server:showroom-pre-check"

Framework.Server.CreateCallback("jg-dealerships:server:showroom-pre-check", function(src, cb, dealershipId)
  local allowed = false
  
  -- QBCORE LICENSE CHECKS
  local Player = QBCore.Functions.GetPlayer(src)
  local licenseCheck = Config.DealershipLocations[dealershipId].licenseCheck
  local license = Player.PlayerData.metadata['licences'][Config.DealershipLocations[dealershipId].license]
  if licenseCheck then
    if not license then
      allowed = false

    elseif license  then
      allowed = true
    end
  else
    allowed = true
  end
  
  -- Write some server-sided code here. Again, update the "allowed" variable
  
  if not allowed then
    Framework.Server.Notify(src, "You require a ".. Config.DealershipLocations[dealershipId].license.. " license", "error")
    return cb({ error = true })
  end
  
  return cb()
end)

Only want to setup individual dealerships and not all you can replace config-sv function with the following config-sv.lu

Framework.Server.CreateCallback("jg-dealerships:server:showroom-pre-check", function(src, cb, dealershipId)
  local allowed = false

  -- QBCORE License Check
  -- dealershipId is the name of your dealership in the config.lua
  if dealershipId == "boat" then
    local Player = QBCore.Functions.GetPlayer(src)
    local license = Player.PlayerData.metadata['licences'][Config.DealershipLocations[dealershipId].license]
    if not license then
      allowed = false
    end
  end

  -- Write some server-sided code here. Again, update the "allowed" variable

  if not allowed then
    Framework.Server.Notify(src, "You require a ".. Config.DealershipLocations[dealershipId].license.. " license", "error")
    return cb({ error = true })
  end

  return cb()
end)

Last updated