function FuncTrainOrder takes nothing returns nothing
local integer p = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
local integer t = GetUnitTypeId(GetTriggerUnit())
local string s = UnitId2String(GetIssuedOrderId())
if s==null then //UnitId2String returns null if the given order was not a unit training order
return
endif
if t=='h000' or t=='h01S' or t=='h02Z' or t=='h03Q' then //check whether triggering unit was a capital
set capitalunitqueue = capitalunitqueue + 1 //increment unit training count
if capitalunitqueue == 1 then //if the count is greater then 1, it was already removed
call removeFromGroup(GetTriggerUnit(), p, 0)
endif
endif
endfunction
function FuncTrainDone takes nothing returns nothing
local integer p = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
local integer t = GetUnitTypeId(GetTriggerUnit())
if t=='h000' or t=='h01S' or t=='h02Z' or t=='h03Q' then //check whether triggering unit was a capital
set capitalunitqueue = capitalunitqueue - 1 //decrement unit training count
if capitalunitqueue <= 0 then //if the count is greater 0, add it back to the group
call add2group(GetTriggerUnit(), p, 0)
endif
endif
endfunction