You need to set some variable on the object to define what team it is on. Then, when targeting, check the instance variable to see if the object is a valid target. In the conditions you should do something like this:
Pick Sprites in range.
Sprite has peerid = enemy.peerid (or Sprite has peerid <> self.peerid)
Pick closest Sprite.
All these conditions need to be in a single action. That way, each following condition would filter the list. First you pick all sprites in range. Then keep only the sprites from the previous list that are enemies. Then choose the closest sprite from the previous list.