This should work depending on what exactly you want to do. Just modify it to suit your needs. Like check to see if script is attached to what ever and set how far the player should be or whatever.
GameObject *Get_Nearest_Solider(GameObject *obj) // Get the nearest solider next to a object
{
float closestdist = FLT_MAX;
Vector3 obj_pos = Commands->Get_Position(obj);
GameObject *object = 0;
SLNode<BaseGameObj> *x = GameObjManager::GameObjList.Head();
while (x)
{
GameObject *o = (GameObject *)x->Data();
if (o && As_SoldierGameObj(o))
{
Vector3 player_pos = Commands->Get_Position(o);
float dist = Commands->Get_Distance(player_pos,obj_pos);
if (dist < closestdist)
{
closestdist = dist;
object = o;
}
}
x = x->Next();
}
return object;
}