void AISetStockUnitNext (int player, int count, string aliasUnitType, bool when);
this stock will only be stocked given bool is true.
Say you give When as:
(AITechCount(player, c_ZU_Queen, c_techCountCompleteOnly) > 1) == true
whatever aliasUnitType you put up there will only be stocked once our when here is true.
It's like a setstock with an if.
You can have say:
AISetStockUnitNext (player, 2, c_TB_Armory, AIHasRes(player, 500, 100) );
which will stock an armory when the AI gets >= 500 minerals and 100 gas.