- Joined
- Jan 9, 2005
- Messages
- 2,127
Is there a way (or a system) to limit the number of units a building can train? I don't just mean raise the limit for every X number if the building, but each building can train a fixed amount of units.
Eg: Barracks being limited to 5 Footmen. If I have 3 Barracks, I will be able to have a total of 15 Footmen, but one Barracks can ONLY train 5 of them.
One way I tried doing it is to use Charge Gold and Lumber and enable unit --> order train --> disable unit, but I couldn't queue them up because a building can't cast abilities while it's training a unit.
Another way I tried doing it was to just order the unit to cancel the unit if it counts beyond 5, but that doesn't work:
Any thoughts?
Eg: Barracks being limited to 5 Footmen. If I have 3 Barracks, I will be able to have a total of 15 Footmen, but one Barracks can ONLY train 5 of them.
One way I tried doing it is to use Charge Gold and Lumber and enable unit --> order train --> disable unit, but I couldn't queue them up because a building can't cast abilities while it's training a unit.
Another way I tried doing it was to just order the unit to cancel the unit if it counts beyond 5, but that doesn't work:
JASS:
function onTrainStart_Event takes nothing returns boolean
local unit Source = GetTriggerUnit()
local integer UnitType = GetTrainedUnitType()
local integer id = 0
if UnitType == 'vsd2' then
set id = GetUnitUserData(Source)
set MOD_AetherTendril_Count[id] = MOD_AetherTendril_Count[id] + 1
if MOD_AetherTendril_Count[id] > 5 then
call IssueImmediateOrderById(Source, 851976)
endif
endif
return false
endfunction
//===========================================================================
function InitTrig_onTrainStart_Event takes nothing returns nothing
set gg_trg_onTrainStart_Event = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_onTrainStart_Event, EVENT_PLAYER_UNIT_TRAIN_START )
call TriggerAddCondition( gg_trg_onTrainStart_Event, function onTrainStart_Event )
endfunction
Any thoughts?