You have only to use a trigger or two to detect the presence or absence of a unit and thus execute a script or command line.
Please, rename your thread title to be more descriptive of the subject matter so that future members can find what they need easier.
Try searching for topics on triggers, boundaries, spawns, zones, etc.
Check out the
COMREF for commands to use in those triggers, the
Missions Depot, that may have missions resembling what you need(all prior titles are relevant), or the
Editors Depot where hundreds of scripts, functions and tutorials already exist for you to download and browse through.