Trigger API Reference\DCEI Events\Effect
void TriggerAddEffectEvent(string effectName, TypedCallback<EffectContext> trigger, bool simple = False)
void TriggerAddEffectEvent(string effectName, TypedCallback<EffectContext> trigger, bool simple = False)
Description
This event is triggered when an effect occurs. Use TriggeringEffectName and TriggeringEffectContext to get the name and context of the effect. This function can also pass the effect context as a parameter to the callback function.
Parameters
- string
effectName
the name of the effect which triggers the event. - TypedCallback<EffectContext>
trigger
the callback function that is run when the event is triggered. - bool
simple
this flag reduces overhead by preventing the usage of DCEI.Wait() within the trigger. You should only set this to true if the trigger does not use DCEI.Wait().
Callback Parameters
- EffectContext
effect_context
Example Usage
function OnDoNothing(effect_context)
local context = DCEI.TriggeringEffectContext
local caster_name = DCEI.GetUnitType(context.caster)
local source_name = DCEI.GetUnitType(context.source)
local target_name = DCEI.GetUnitType(context.target)
DCEI.LogMessage(caster_name .. " did nothing to " .. target_name .. " via " .. source_name .. ".")
end
DCEI.TriggerAddEffectEvent(DCEI.Effect("DoNothing"), OnDoNothing, true)
Related
void TriggerAddEffectHookEvent(string effectName, TypedCallback<EffectContext> trigger, bool simple = False)
void TriggerAddEffectHookEvent(string effectName, TypedCallback<EffectContext> trigger, bool simple = False)
Description
Effect hooks allow you to intercept an effect and modify the data before executing it during Lua run-time. In the following example, this effect hook intercepts a launch missile effect to make it use the very unit it’s attacking as the missile for the Launch Missile effect. See Using Effect Hooks
Parameters
- string
effectName
the name of the effect which triggers the event. - TypedCallback<EffectContext>
trigger
the callback function that is run when the event is triggered. - bool
simple
this flag reduces overhead by preventing the usage of DCEI.Wait() within the trigger. You should only set this to true
Callback Parameters
- EffectContext
effect_context
Example Usage
DCEI.TriggerAddEffectHookEvent(
DCEI.Effect("Standard RangedUnit Weapon Launch"),
function(context)
if DCEI.EvaluateEffectHookExpression("RandomChance 100%") ~= 0 then
local field_path = {"launchMissile", "missileUnit"}
local missile_unit = DCEI.GetUnitType(context.target)
DCEI.SetEffectHookFieldValue(field_path, missile_unit)
end
end
)