EVENT_PLAYER_UNIT_DAMAGED
or EVENT_PLAYER_UNIT_DAMAGING
for that.call TriggerRegisterAnyUnitEventBJ(gg_trg_<trigger_name>, EVENT_PLAYER_UNIT_DAMAGED)
.Do you know if you can get the attacking unit in this case ? i'm trying to make a system in which a neutral unit, when attacked becomes hostile and stores the player number of the attacker, and when the unit reaches a certain point, if it has been attacked, its faction then becomes hostile to the attacking player. But as I use the custom script method, "attacking unit" isn't initialized in the fundtion. Here is the code :Yeah. I forgot to mention that when dealing with damage instances, the Unit is attacked event is not the appropriate one to use. Here are two ways to detect spell damage.
You'll need to use the player unit eventEVENT_PLAYER_UNIT_DAMAGED
orEVENT_PLAYER_UNIT_DAMAGING
for that.
To register the trigger (that should detect spell damage) to these events, you'll have to delve into custom script, and call the following line at map initialization:
call TriggerRegisterAnyUnitEventBJ(gg_trg_<trigger_name>, EVENT_PLAYER_UNIT_DAMAGED)
.
From there, you can check whether the damage dealt comes from a spell or not based on its attack type. A bit of custom script here and there, and the snippet should somewhat look like this:
Your Trigger
Events
Comment: -------- Unfortunately, GUI does not offer the option to register a generic version of the PLAYER_UNIT_DAMAGED event --------
Comment: -------- so the registration of this trigger to said event will have to be done in a separate trigger --------
Conditions
Actions
Custom Script: if (BlzGetEventAttackType() != ATTACK_TYPE_NORMAL) then
Custom Script: return
Custom Script: endif
Comment: -------- You can now deal with the spell damage instance as you please --------
Initialization Trigger
Events
Game - Map Initialization
Conditions
Actions
Comment: -------- This will register "Your Trigger" to the event EVENT_PLAYER_UNIT_DAMAGED --------
Custom Script: call TriggerRegisterAnyUnitEventBJ(gg_trg_Your_Trigger, EVENT_PLAYER_UNIT_DAMAGED)
Alternatively, if you're okay with using Bribe's Damage Engine 5.9.0.0, download the system and copy-paste it in your map. Then, you can set up your trigger like this:
Your Trigger
Events
Game - DamageEvent becomes Greater than 1.00
Conditions
Actions
Comment - This trigger has detected a spell damage instance.