local function d(d,M,b)local f=Cryo.List.sort(d,function(d,b)local f=M[d]or math.huge local t=M[b]or math.huge return f<t end)local t={}for d,f in ipairs(f)do if#t>=b.maxLocators then break end local v=M[f]or 0 if v>b.thresholdDistance then table.insert(t,f)end end return t end return d

local function selectUserIdsByDistance(userIds, distanceFromCamera, configuration)
	-- Sort the players according to the distance to you
	local sortedByDistance = Cryo.List.sort(userIds, function(a, b)
		local distance1 = distanceFromCamera[a] or math.huge
		local distance2 = distanceFromCamera[b] or math.huge

		return distance1 < distance2
	end)

	-- Limit the total number of indicators
	local res = {}
	for _, userId in ipairs(sortedByDistance) do
		if #res >= configuration.maxLocators then
			break
		end

		local distance = distanceFromCamera[userId] or 0
		if distance > configuration.thresholdDistance then
			table.insert(res, userId)
		end
	end

	return res
end

return selectUserIdsByDistance
