function getNearestID()
local chars = getAllChars()
local mx, my, mz = getCharCoordinates(PLAYER_PED)
local nearId, dist = nil, 10000
for i,v in ipairs(chars) do
if doesCharExist(v) and v ~= PLAYER_PED then
local vx, vy, vz = getCharCoordinates(v)
local cDist = getDistanceBetweenCoords3d(mx, my, mz, vx, vy, vz)
local r, id = sampGetPlayerIdByCharHandle(v)
if r and cDist < dist then
dist = cDist
nearId = id
end
end
end
return nearId
end
local id = getNearestID()