• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Triggering on damage dealt by spell

Status
Not open for further replies.
Unfortunately, there is no specific event that can be triggered when a spell (and a spell exclusively) deals damage to a target.

In more recent versions of wc3 (1.29+), there is a player version of the unit damaged event which you can use to watch such moments. It is more trivial to check for damage from there in (1.30?) and above by comparing the damage type of the spell with the normal attack damage (DAMAGE_TYPE_NORMAL).

In prior versions (1.2:cool:, you will have to use an ability based off of Runed Bracers to essentially invert the damage instance, although this can come with its own set of problems. When you see the inverted damage instance, you'll have to reverse it to actually deal damage (this means that the damage dealt comes from a spell). Bribe's Damage Engine 3.8.0.0 can actually come in handy here.
 
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 event EVENT_PLAYER_UNIT_DAMAGED or EVENT_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.
 
Level 2
Joined
Apr 4, 2022
Messages
13
That's exactly what i was looking for !

I have hesitated to add the Damage engine recently, but i don't really see the point, it is too complete for what i need. If I the future i'm interested by its other feature, perhaps I will add it, but in the mean time, your first bit of code is all I need :) thanks a lot !
 
Level 2
Joined
Apr 4, 2022
Messages
13
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 event EVENT_PLAYER_UNIT_DAMAGED or EVENT_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.
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 :

  • boatTakesDamage
    • Events
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Attacked unit)) Equal to Galion (player)
          • (Unit-type of (Attacked unit)) Equal to Galion (neutral)
          • (Unit-type of (Attacked unit)) Equal to Ship of the line
          • (Unit-type of (Attacked unit)) Equal to Fluit (neutral)
          • (Unit-type of (Attacked unit)) Equal to Fluit (player)
          • (Unit-type of (Attacked unit)) Equal to Frigate
          • (Unit-type of (Attacked unit)) Equal to Sloop
    • Actions
      • Game - Display to (All players) the text: (Name of (Owner of (Attacking unit)))
      • Game - Display to (All players) the text: (Name of (Owner of (Attacked unit)))
      • Special Effect - Create a special effect at (Position of (Attacked unit)) using Objects\Spawnmodels\Human\FragmentationShards\FragBoomSpawn.mdl
      • Special Effect - Set Position - Z of (Last created special effect) to 200.00
      • Special Effect - Set Time of (Last created special effect) to 1.00
      • Unit Group - Pick every unit in (Units within 2000.00 of (Position of (Attacked unit)) matching (((Matching unit) belongs to an ally of (Owner of (Attacked unit)).) Equal to Vrai).) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Picked unit)) controller) Not equal to User
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Owner of (Picked unit)) Equal to Player 13 (Maroon)
                      • (Owner of (Picked unit)) Equal to Player 14 (Navy)
                      • (Owner of (Picked unit)) Equal to Player 15 (Turquoise)
                • Then - Actions
                  • Unit - Set Unit: (Attacked unit)'s Integer Field: Gold Bounty Awarded - Number of Dice ('ubdi') to Value: (Player number of (Owner of (Attacking unit)))
                • Else - Actions
              • Set VariableSet tmpDest = (Rally-Point of (Attacked unit) as a point)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of (Picked unit)) Equal to Player 13 (Maroon)
                • Then - Actions
                  • Unit - Change ownership of (Picked unit) to Player 16 (Violet) and Change color
                  • Unit - Order (Picked unit) to Move To (Center of marroonPorts[(Unit: (Picked unit)'s Integer Field: Lumber Bounty Awarded - Base ('ulba'))])
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of (Picked unit)) Equal to Player 14 (Navy)
                    • Then - Actions
                      • Unit - Change ownership of (Picked unit) to Player 17 (Wheat) and Change color
                      • Unit - Order (Picked unit) to Move To (Center of navyPorts[(Unit: (Picked unit)'s Integer Field: Lumber Bounty Awarded - Base ('ulba'))])
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of (Picked unit)) Equal to Player 15 (Turquoise)
                        • Then - Actions
                          • Unit - Change ownership of (Picked unit) to Player 18 (Peach) and Change color
                          • Unit - Order (Picked unit) to Move To (Center of turquoisePorts[(Unit: (Picked unit)'s Integer Field: Lumber Bounty Awarded - Base ('ulba'))])
                        • Else - Actions
              • Game - Display to (All players) the text: (String((Unit: (Picked unit)'s Integer Field: Gold Bounty Awarded - Base ('ubba'))))
            • Else - Actions
this is triggered by this event : EVENT_PLAYER_UNIT_DAMAGED

Here in the code, attacked unit works fine but the attacked unit part doesn't, and that prevents me to store the attacker's number in an integer field.

If i can't get the unit, can i at least get the ability ?
 
Last edited:
Level 13
Joined
Feb 5, 2018
Messages
567
Change conditions to "Damage Target", there is no attacking unit when you run the trigger by the damage event custom script. The trigger is then "Damage Target" and "Damage Source", you should have these conditions if you are on the latest patch. These functions should exist by default.
 
Status
Not open for further replies.
Top