If you have only one type of guard you don't need any unit-type variables. If you have many, I would suggest doing something like this to store the data about each guard
-
-------- On map init set these --------
-
Set GuardType[1] = Footman
-
Set GuardType[2] = Militia
-
Set GuardType[3] = Gyrocopter
-
-------- Set these on map init to correspond to each guard post; this COULD be automated to happen at run-time --------
-
Set Guard[1] = (the unit, however your get it. maybe from a unit group - pick, maybe you click preplaced units idk)
-
Set WhatGuard[1] = 1 //guard 1 is a footman
-
Set GuardPosition[1] = (Center of Guard 1 <gen>) //or maybe Position of Guard[1], etc.
-
Set GuardTraining[1] = false //to know if a guard is currently queued for training and dispatch to an unguarded location, so you don't overpopulate your queue as UreDeD suggested
-
Set Guard[2] = (the unit, however your get it)
-
Set WhatGuard[2] = 3 //guard 2 is a gyrocopter
-
Set GuardPosition[2] = (Center of Guard 2 <gen>)
-
Set GuardTraining[2] = false
-
...
Then when a unit dies, you loop through all the Guard[]s, find the one that's the same unit (whose index I'll call <number>), and train a GuardTypes[GuardPosition[<number>]], set GuardTraining[<number] = true, and set the rally point for the training unit to GuardPosition[<number>]. You'll have to consider training overlap with the rally point setting but I think that would be easier than detecting the trained unit event and trying to figure out where it's supposed to go once it's spawned.