@Sygvur: AFAIK GetUnitGoldCost only works for the standard/default units ... however i dont recall if it crashed wc3 when used for custom-units, or if it just returned the value of the base-unit.
Grundy's way might work if you order the last order again... (maybe using some library like LastOrder)
btw Grundy, did you try issue that autocast-trigger order with an immediate order or not ? If not you could try if an immediate order interrupts the current order aswell or not ..
And i still...
damage detection is really tricky, and can cause many errors if not coded >very< well.
So i would advides you to use a established system for your map, like: Light Leakless Damage Detect (LLDD), ADamage or IDDS
If you just started your map, i would use IDDS, if not i would recommend LLDD...
strange, when i tested this (abuse) yesterday it didnt work for me...
EDIT: i get syntax error now, "cant convert handle h to integer" ... well i use Zoxc's Parser, which enforces strict type safety ...to laze to switch to pjass for testing this again right now.