I just finnished a trigger that actually targets the closest unit of matching type
what im doing is having peons mine diffrent ores by attacking rocks of diffrent types. Each time a peon attackes a rock the peons custom variable is increased by 1. when the peons custom variable reaches 10, the "target closest town hall" trigger is activated. using the variable "ReturnDistance" I've estabilshed a way to target the closest town hall.
-Actions
--Set ReturnDistance = 100000.00
--Unit Group - Pick every unit in (Units owned by Player 1 (Red) of type Town Hall) and do (if ((Distance between (Position of (Attacking unit)) and (Position of (Picked unit))) Less than ReturnDistance) then do (Set GatherDistance = (Distance between (Position of (Attacking unit)) and (Position of (Picked unit))) else (Do nothing))
--Unit Group - Pick every unit in (Units owned by Player 1 (Red) of type Town Hall) and do (If ((Distance between (Position of (Attacking unit)) and (Position of (Picked unit))) Equal to ReturnDistance) then do (Unit - Order (Attacking unit) to Attack (Picked unit)) else do (Do nothing))
Im sure it can be ironed out a bit, but it does work.
Now, to get the peon to return back to the same rock it was mining at before is another barrier.
maybe, if i number each rock and before the peon goes to return its resources i have the trigger set the peons custom variable to that specific rock. and the rest should fall in easily.
we'll see.
Thanks for all the help everyone.
-Post