License Before buying a car

Good day

I would like to find out if it’s possible to set a requirement to have a license before you can buy a car.
I am new to five servers any advice would be appreciated.

Without mentioning specific resources you’re using, the overall answer is most certainly yes. It’s rather simple - you just need to add a logic check (“if [this] then X”) into your code, hooking into whatever resource you have handling licenses to check for the player owning the license, and then allowing one to proceed with purchasing a vehicle. How exactly that’d be done depends on the specific resources used for both of those.

thank you . iam using qb_driving school

Hey :wave:

If you are using qb-driving school you would want to use these functions to check if a player has there license before purchasing a car.


If Using qb-vehicleshop

--[[ look for event qb-vehicleshop:server:buyShowroomVehicle ]]
 --[[ Replace the whole event with this, it will be shorter as I did make it a bit more simple]]
RegisterNetEvent('qb-vehicleshop:server:buyShowroomVehicle', function(vehicle)
    local src = source
    vehicle = vehicle.buyVehicle
    local pData = QBCore.Functions.GetPlayer(src)
    local cid = pData.PlayerData.citizenid
    local cash =['cash']
    local bank =['bank']
    local vehiclePrice = QBCore.Shared.Vehicles[vehicle]['price']
    local plate = GeneratePlate()

    if cash > tonumber(vehiclePrice) or bank > tonumber(vehiclePrice) then
        if pData.PlayerData.metadata['licences']['driver'] == true then --[[Changed this here]]
            MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
            TriggerClientEvent('QBCore:Notify', src, Lang:t('success.purchased'), 'success')
            TriggerClientEvent('qb-vehicleshop:client:buyShowroomVehicle', src, vehicle, plate)
            if cash > tonumber(vehiclePrice) then
                pData.Functions.RemoveMoney('cash', vehiclePrice, 'vehicle-bought-in-showroom')
                pData.Functions.RemoveMoney('bank', vehiclePrice, 'vehicle-bought-in-showroom')
            TriggerClientEvent('QBCore:Notify', src, 'You dont have a license', 'error') --[[Changed this here]]
        TriggerClientEvent('QBCore:Notify', src, Lang:t('error.notenoughmoney'), 'error')

Remember to keep a backup of it as I did not test this and its just to the best of my knowledge :slight_smile:

Hope this helps!

Thank you so much. going to give it a shot when I get home and ill give feed back