My function was only intended to set the clients aim vector to an origin regardless where this origin is.
btw : there is a much more efficient way
Code:
stock setClientAIM ( Client, Entity )
{
static Float:vecOrigin[ 3 ];
static Float:vecTarget[ 3 ];
static Float:angResult[ 3 ];
entity_get_vector( Client, EV_VEC_origin, vecOrigin );
entity_get_vector( Entity, EV_VEC_origin, vecTarget );
vecOrigin[ 0 ] = vecTarget[ 0 ] - vecOrigin[ 0 ];
vecOrigin[ 1 ] = vecTarget[ 1 ] - vecOrigin[ 1 ];
vecOrigin[ 2 ] = vecTarget[ 2 ] - vecOrigin[ 2 ];
vector_to_angle( vecOrigin, angResult );
entity_set_vector( Client, EV_VEC_angles, angResult );
entity_set_int( Client, EV_INT_fixangle, 1 );
}
but what you need is more like
Code:
stock getNextEnemy ( Client )
{
new end = get_maxplayers();
new Float:minr = float( getTeleportRange( Client ) );
new Ret = 0;
new Float:rang;
for ( new Enemy = 1; Enemy <= end; Enemy++ )
{
if ( !is_user_connected( Enemy ) )
continue;
if ( !is_user_alive( Enemy ) || Enemy == Client )
continue;
if ( getGameMODE() > 0 && getClientTEAM( Enemy ) == getClientTEAM( Client ) )
continue;
// add in view cone / trace line here
rang = entity_range( Enemy, Client );
if ( rang < minr )
{
Ret = Enemy ;
minr = rang;
}
}
return Ret;
}
This finds the closest enemy next to you ( but with z dimension because its actually for the ESF Mod ^^ ) but if you add inviewcone (and traceline?) the origins then you should have reached your goal
Of course you need to get the natives I used mod specific
And for enemy2 you will need also need to add something like the smallest( floatabs(floatacos( dotp( playera, playerb ) ) )) as i did with the distance
for dotp you may consult your favourite math formula collection^^
or use pm's xs library