Assuming m.playerShip is the player's ship you want to check against, something like that should work:
// get new selection and fill it with behaviour-4-ships, but not asteroids
e.inactiveEnemies := GetFreeSel();
Select(e.inactiveEnemies, s.behaviour = 4 & Not(s.class >= 99 & s.class <= 134));
Debug("## Inactive Enemies"); Dump(e.inactiveEnemies);
// pick the one, that's closest to the player's main ship
e.closestEnemy := PickMax(e.inactiveEnemies, 1 / distance(s.this, m.playerShip));
Debug("Closest enemy is", e.closestEnemy);
// clean up
DeleteSelect(e.inactiveEnemies);
When selecting the behaviour-4-ships, you'll want to make sure not to select any asteroids in the scene, so I've included a condition based on the ship's class. Shipclasses 99 to 134 are asteroids in my mod... it may be different in yours, so adjust accordingly.