Here is something that may get you what you want.
// Will only return a target if they have mage or priest levels, are alive,
// can be seen, and are an enemy. Otherwise returns OBJECTINVALID.
// Mage levels are weighted for.
// Only PC's, Henchmen, and Dominated types are concidered.
object PriorityTarget()
{
object oTarget = OBJECT_INVALID;
int nCount = 1;
object oCantidate = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, nCount, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY );
while(GetIsObjectValid(oCantidate))
{
int PriorityLevel = 0;
if(GetMaster(oCantidate) == OBJECT_INVALID || GetAssociateType(oCantidate) == ASSOCIATE_TYPE_HENCHMAN|| GetAssociateType(oCantidate) == ASSOCIATE_TYPE_DOMINATED)
{
int SorcerorLavels = GetLevelByClass(CLASS_TYPE_SORCERER)*2;
int WizardLavels = GetLevelByClass(CLASS_TYPE_WIZARD)*2;
int ClericLevels = GetLevelByClass(CLASS_TYPE_CLERIC);
int DruidLavels = GetLevelByClass(CLASS_TYPE_DRUID);
int CandidatePriorityLevel = SorcerorLavels+WizardLavels+ClericLevels+DruidLavels;
if(CandidatePriorityLevel > PriorityLevel)
oTarget = oCantidate;
}
oCantidate = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, ++nCount, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY );
}
return oTarget;
}