you dont realy need a script to make groups and units to fall back, all you have to do is, say you wanted a group of soldiers to attack a town is to place there waypoint into the town and create a second waypoin leading away, and then create a trigger in the town for west or whatever side you are playing on and then sincronise it to the waypoint in the town so when this trigger is activated the groups will retreat to somewhere out of the town, or you could make it so that when the CO dies with this command in the condition box in the trigger: not alive unitname.