WaitForUnitEvent
not ratedThis function halts the calling trigger (thread) until the specified unit event occurs. It checks with the specified interval. An interval of 0 makes the function check the event as often as possible. The condition works like the one of a normal trigger. If you don't want to use a condition, pass null to the function.
You can pass either a unit or a unit group to the function. If you pass a unit group the function will wait until the specified event occurs to *any* of the units in the group. The condition can be used to control this however.
This function uses IterateGroup© technology, many thanks to dataangel. Inlined for optimization.
Example:
function myfunction_conditions takes nothing returns boolean
return GetTriggerPlayer() == GetOwningPlayer(GetTriggerUnit())
endfunction
local conditionfunc c = Condition(function myfunction_conditions)
call WaitForUnitEvent(udg_my_unit, EVENT_UNIT_SELECTED, 0, c)
call DestroyCondition(c)
In this example the function waits for udg_my_unit to be selected by its owner, checking as often as possible. BoolExprMakeTemporary doesn't work for destroying the condition as the function sleeps and requires the condition to be available until the function has finished, so you have to create/destroy it manually.
If null was used as condition to the function it would stop waiting when *any* player selected the unit.
If a unit group was used instead of udg_my_unit then the function would stop waiting when *any* of the units were selected by its owner.
You can pass either a unit or a unit group to the function. If you pass a unit group the function will wait until the specified event occurs to *any* of the units in the group. The condition can be used to control this however.
This function uses IterateGroup© technology, many thanks to dataangel. Inlined for optimization.
Example:
function myfunction_conditions takes nothing returns boolean
return GetTriggerPlayer() == GetOwningPlayer(GetTriggerUnit())
endfunction
local conditionfunc c = Condition(function myfunction_conditions)
call WaitForUnitEvent(udg_my_unit, EVENT_UNIT_SELECTED, 0, c)
call DestroyCondition(c)
In this example the function waits for udg_my_unit to be selected by its owner, checking as often as possible. BoolExprMakeTemporary doesn't work for destroying the condition as the function sleeps and requires the condition to be available until the function has finished, so you have to create/destroy it manually.
If null was used as condition to the function it would stop waiting when *any* player selected the unit.
If a unit group was used instead of udg_my_unit then the function would stop waiting when *any* of the units were selected by its owner.