function getClosestCarId()
local minDist = 9999
local closestId = -1
local x, y, z = getCharCoordinates(PLAYER_PED)
for i = 400, 600 do
local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
if streamed then
local xi, yi, zi = getCarCoordinates(pedID)
local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
if dist < minDist then
minDist = dist
closestId = getCarModel(pedID)
end
end
end
return closestId
end