You're on the right track. Set the encounter to inactive and do something like this... (not to pick on dwarves
'>
<code>
void main() {
object oPC = GetEnteringObject();
if (GetRacialType(oPC) == RACIAL_TYPE_DWARF)
SetEncounterActive(TRUE);
}
</code>
But the trickier bit will be checking the faction. You probably will want the script to get a member of the territory's faction (maybe one with a nice unique tag so it's easy) to do the hostility check. I don't believe you can get the faction of the encounter as such.
GetObjectByTag and then GetIsEnemy would probably do it.