📚
Dusa all scripts documentation
  • Home
  • General Questions
    • Escrow System
    • Error parsing script ... <\1>
    • Failed to verify protected resource
    • You lack the required entitlement
    • If nothing fixed your problems
  • Need Help?
  • Scripts
    • Police Job
      • Installation
      • Configuration
      • Client
        • Exports
        • Events
      • Server
        • Callbacks
      • Common Issues
    • Evidence
      • Installation
      • Configuration
      • Client
        • Events
      • How to add custom weapon compatibility?
      • Common Issues
    • Hud
      • Installation
      • Configuration
      • Client
        • Events
        • Exports
      • Server
        • Events
    • Vehicle Keys
      • Installation
      • How to give keys to player? (e.g on dealerships)
      • Client
        • Exports
        • Events
      • Server
        • Exports
        • Events
    • Billing
      • Installation
      • Configuration & Exports (ESX)
      • Configuration & Exports (QB)
    • Police MDT
      • Installation
      • Configuration & Exports (ESX/QBCore)
    • Dispatch
      • Installation
      • On other resources, how can I integrate dispatch?
      • How to send custom dispatch?
      • Client
        • Exports
        • Events
        • Handlers
      • Server
        • Exports
    • Multicharacter + Spawn Selector
      • Installation
      • Configuration & Exports (ESX)
      • Configuration & Exports (QB)
Powered by GitBook
On this page
  • Client Side
  • Server Side
  1. Scripts
  2. Vehicle Keys

How to give keys to player? (e.g on dealerships)

If the gallery system or similar systems you use haven't provided an integration, you can easily perform the integration yourself by following the steps below.

Client Side

function GiveVehicleKeys(plate, vehicle)
    exports.dusa_vehiclekeys:GiveKeys(plate)
end

If you need to embed it into

RegisterNetEvent('qb-vehicleshop:client:TestDrive', function()
    if not inTestDrive and ClosestVehicle ~= 0 then
        inTestDrive = true
        local prevCoords = GetEntityCoords(PlayerPedId())
        tempShop = insideShop -- temp hacky way of setting the shop because it changes after the callback has returned since you are outside the zone
        QBCore.Functions.TriggerCallback('qb-vehicleshop:server:spawnvehicle', function(netId, properties, vehPlate)
            local timeout = 5000
            local startTime = GetGameTimer()
            while not NetworkDoesNetworkIdExist(netId) do
                Wait(10)
                if GetGameTimer() - startTime > timeout then
                    return
                end
            end
            local veh = NetworkGetEntityFromNetworkId(netId)
            NetworkRequestControlOfEntity(veh)
            SetEntityAsMissionEntity(veh, true, true)
            Citizen.InvokeNative(0xAD738C3085FE7E11, veh, true, true)
            SetVehicleNumberPlateText(veh, vehPlate)
            exports['LegacyFuel']:SetFuel(veh, 100)
            
            -- HERE
            exports.dusa_vehiclekeys:GiveKeys(vehPlate)
            --

            TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1)
            SetVehicleEngineOn(veh, true, true, false)
            testDriveVeh = netId
            QBCore.Functions.Notify(Lang:t('general.testdrive_timenoti', { testdrivetime = Config.Shops[tempShop]['TestDriveTimeLimit'] }), "success")
        end, 'TESTDRIVE', Config.Shops[tempShop]['ShowroomVehicles'][ClosestVehicle].chosenVehicle, Config.Shops[tempShop]['TestDriveSpawn'], true) 

        createTestDriveReturn()
        startTestDriveTimer(Config.Shops[tempShop]['TestDriveTimeLimit'] * 60, prevCoords)
    else
        QBCore.Functions.Notify(Lang:t('error.testdrive_alreadyin'), 'error')
    end
end)

Server Side

Actually, there is no change on the server side, only the player's ID should be sent (source)

function GiveVehicleKeys(source, plate, vehicle)
    local src = source
    exports.dusa_vehiclekeys:GiveKeys(src, plate)
end
PreviousInstallationNextClient

Last updated 2 months ago