RegisterNetEvent('esx:spawnVehicle')
AddEventHandler('esx:spawnVehicle', function(vehicleName)
local model = (type(vehicleName) == 'number' and vehicleName or GetHashKey(vehicleName))
if IsModelInCdimage(model) then
local playerPed = PlayerPedId()
local playerCoords, playerHeading = GetEntityCoords(playerPed), GetEntityHeading(playerPed)
ESX.Game.SpawnVehicle(model, playerCoords, playerHeading, function(vehicle)
local plate = GetVehicleNumberPlateText(vehicle)
TriggerServerEvent('garage:addKeys', plate)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
end)
else
TriggerEvent('chat:addMessage', {args = {'^1SYSTEM', 'Invalid vehicle model.'}})
end
end)