Something like
_enemyunit = enemygroup count units
_friendlyunit = friendgroup count units
if (_enemyunit > _friendlyunits) THEN {
repeat "_x allowfleeing 1" for each group friendgroup
Call that script in a trigger, with two groups, one named enemygroup, one named friendgroup.. Friendgroup will run..
I've no idea if that is right, it should be though...
- Ben