CFPRO is example 
in my country this geometry stuff is teached in class 7-8
If you remember some alfa angel of a triangel it's prity easy to make the math on 3D cord's
the 2D cord's yep there are a bit harder
.int closest = -1; //if it remains -1 there is no enemies around
float distance = 9999.9;
//loop these for all enemies that meets other checks (not over walls, not ghosts, etc)
//assume that me is a position vector of your local player , him is a position vector of enemy and index is the enemy local index
float tdist = sqrt(pow(me.x-him.x, 2)+pow(me.y-him.y, 2)+pow(me.z-him.z, 2));
if (tdist<distance)
{
distance = tdist;
closest = index;
}
):int closest = -1; //if it remains -1 there is no enemies around
float distance = 9999.9;
//loop these for all enemies that meets other checks (not over walls, not ghosts, etc)
//assume that camyaw, campitch are the current camera rotation angles, aimyaw, aimpitch are angles calculated by aimbot routine and index is the enemy local index
float ncamyaw = camyaw>=0?camyaw:camyaw+2*M_PI;
float ncampitch = campitch>=0?campitch:campitch+2*M_PI;
float naimyaw = aimyaw>=0?aimyaw:aimyaw+2*M_PI;
float naimpitch = aimpitch>=0?aimpitch:aimpitch+2*M_PI;
float ydif = abs(naimyaw-ncamyaw); //validate this value which should be <= fov/2
float pdif =abs(naimpitch-ncampitch);
if (pdif+ydif<distance)
{
distance = pdif+ydif;
closest = index;
}
