You can detect relationship by GetTeamRelation() function.
If you only want other ships say something to you (mothership) it's easy. You attach trigger to certain flight which activates when near mothership.
In fact this is already in-game and used with the Trader random contacts.