local x, y, z = getCharCoordinates(PLAYER_PED)
local buffer, nearestdriver, nearestdriver_id, nearestdriver_nick
for _, v in ipairs(getAllChars()) do
local result, id = sampGetPlayerIdByCharHandle(v)
if result and v ~= PLAYER_PED then
local distance = getDistanceBetweenCoords3d(x, y, z, getCharCoordinates(v))
if buffer == nil or distance < buffer and isCharInAnyCar(v) and v == getDriverOfCar(storeCarCharIsInNoSave(v)) then
buffer, nearestdriver, nearestdriver_id, nearestdriver_nick = distance, v, id, sampGetPlayerNickname(id)
end
end
end