That's pretty easy

Just create a trigger, add all possible events to it involving Players
ordering there units to do stuff related to combat, add an if/then/else
action that checks if the attacked unit is allied. If no, it won't do anything.
If yes, then it will check if the targetted unit is owned by the triggering player.
If yes, then it won't do anything, else, it will order the triggering unit to stop immediately.