How to make Lighning Shield damage only ennemies with a simple trigger

Level 1
Joined
Apr 2, 2023
Messages
1
Hi everyone, this is my first post here. I hope i'm not posting something already existing elsewhere.
But since I couldn't find a solution to this problem earlier, i moved some brain cells to try and do it by myself, and it worked !
So i'm guessing it could help some other folks looking for a simple solution to make the Lightning Shield ability not damage your allies.

First, i set the damage from the ability in the object editor to 0, area of effect to 2. (Duration is up to you but you will have to adapt it in the wait xxx seconds in Trigger 1)
Also i changed the Lightning Shield effect in the effect/enchantment editor to remove the special effect. (You don't want the visual damage effect to apply on allies)

Now i create 2 triggers, one when the spell effect is initiated, and the other one will be a periodic 1 second event. Here is my code :

Trigger 1 :
  • Bouclier de foudre Objet
    • Evénements
      • Unité - A unit Initie l'effet d'une compétence
    • Conditions
      • (Ability being cast) Egal à Bouclier de foudre74
    • Actions
      • Set Unit_BouclierFoudreCible = (Target unit of ability being cast)
      • Set UnitLanceBouclierFoudre = (Triggering unit)
      • Set BOOL_BouclierFoudreON = TRUE
      • Déclencheur - Turn on Iteration degats bouclier foudre <gen>
      • Wait 15.00 seconds
      • Set BOOL_BouclierFoudreON = FALSE
      • Déclencheur - Turn off Iteration degats bouclier foudre <gen>
Trigger 2 :
  • Iteration degats bouclier foudre
    • Evénements
      • Temps - Every 1.00 seconds of game time
    • Conditions
      • BOOL_BouclierFoudreON Egal à TRUE
      • (Unit_BouclierFoudreCible is alive) Egal à TRUE
    • Actions
      • Groupe unité - Pick every unit in (Units in (Region centered at (Position of Unit_BouclierFoudreCible) with size (600.00, 600.00)) matching ((((Matching unit) belongs to an enemy of (Owner of UnitLanceBouclierFoudre)) Egal à TRUE) and ((((Matching unit) is alive) Egal à TRUE) and (((Matchin and do (Actions)
        • Boucle - Actions
          • Unité - Cause UnitLanceBouclierFoudre to damage (Picked unit), dealing (50.00 x (Real((Level of UnitLanceBouclierFoudre)))) damage of attack type Sorts and damage type Foudre
          • Effet spécial - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Orc\LightningShield\LightningShieldBuff.mdl
And this is it ! Hope this helps, tell me if you think it's a good idea, or maybe there's a simplier way to do it !
Have a good day !
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
That's a great start and could work fine for your map, but I'd like to note:

1) This forum is used to ask for help on fixing a trigger or script. You could probably post this here if you wanted to showcase it to others:

2) Unfortunately, these triggers are making some crucial mistakes that will cause all sorts of problems. In your tests it may work, or appear to work, but you need to consider the following:
  • Does this work for multiple units at once? In other words, can I have 2 or more Lightning Shields active at once without issues?
  • Does this work regardless of what the Cooldown of my Lightning Shield ability is? What happens if I spam the ability?
  • Does this use efficient logic? Are these good practices?
  • Does this work like the original Lightning Shield ability? For example, multiple Lightning Shields do not stack their damage.
  • Does this create memory leaks? This can be crucial for a smooth experience throughout the game!
I don't say this to discourage you, this is a good start. A lot of those Actions are close to perfect and the concept is going in the right direction. However, I wouldn't suggest this to others until all or most of the issues have been sorted out.

With that in mind, here's an example I made which you could use as a learning tool.
It's a triggered Lightning Shield that works like the original ability, accounting for the points I made above.
I used a technique called Unit Indexing to help make it MUI, which means it'll work for multiple units at once without any issues:
1738016987099.png

  • Custom Lightning Shield Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Lightning Shield
    • Actions
      • Set CLS_Target = (Target unit of ability being cast)
      • Set CLS_ID = (Custom value of CLS_Target)
      • Set CLS_Caster[CLS_ID] = (Triggering unit)
      • -------- --------
      • -------- Customize the damage (every 0.50 seconds), the area of effect, and whether or not multiple shields stack damage: --------
      • Set CLS_Damage[CLS_ID] = 10.00
      • Set CLS_Area_Of_Effect[CLS_ID] = 160.00
      • Set CLS_Is_Stacking_Damage[CLS_ID] = False
      • -------- --------
      • Unit Group - Add CLS_Target to CLS_Buff_Group
      • Trigger - Turn on Custom Lightning Shield Interval <gen>
  • Custom Lightning Shield Interval
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in CLS_Buff_Group and do (Actions)
        • Loop - Actions
          • Set CLS_Target = (Picked unit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (CLS_Target has buff Lightning Shield) Equal to True
            • Then - Actions
              • Set CLS_ID = (Custom value of CLS_Target)
              • -------- --------
              • Set CLS_Point = (Position of CLS_Target)
              • Set CLS_Damage_Group = (Units within CLS_Area_Of_Effect[CLS_ID] of CLS_Point.)
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CLS_Is_Stacking_Damage[CLS_ID] Equal to True
                • Then - Actions
                  • -------- Allow multiple Lightning Shields to stack their damage: --------
                  • Unit Group - Pick every unit in CLS_Damage_Group and do (Actions)
                    • Loop - Actions
                      • Set CLS_Other_Target = (Picked unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (CLS_Other_Target is alive) Equal to True
                          • (CLS_Other_Target belongs to an enemy of (Owner of CLS_Caster[CLS_ID]).) Equal to True
                          • (CLS_Other_Target is A ground unit) Equal to True
                          • CLS_Other_Target Not equal to CLS_Target
                        • Then - Actions
                          • Special Effect - Create a special effect attached to the origin of CLS_Other_Target using Abilities\Spells\Orc\LightningShield\LightningShieldBuff.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • Unit - Cause CLS_Caster[CLS_ID] to damage CLS_Other_Target, dealing CLS_Damage[CLS_ID] damage of attack type Spells and damage type Normal
                        • Else - Actions
                • Else - Actions
                  • -------- Prevent multiple Lightning Shields from dealing damage at the same time: --------
                  • Unit Group - Pick every unit in CLS_Damage_Group and do (Actions)
                    • Loop - Actions
                      • Set CLS_Other_Target = (Picked unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (CLS_Other_Target is alive) Equal to True
                          • (CLS_Other_Target belongs to an enemy of (Owner of CLS_Caster[CLS_ID]).) Equal to True
                          • (CLS_Other_Target is A ground unit) Equal to True
                          • CLS_Other_Target Not equal to CLS_Target
                          • CLS_Is_Target_Immune[(Custom value of CLS_Other_Target)] Equal to False
                        • Then - Actions
                          • Set CLS_Is_Target_Immune[(Custom value of CLS_Other_Target)] = True
                          • Unit Group - Add CLS_Other_Target to CLS_Immune_Group
                          • Special Effect - Create a special effect attached to the origin of CLS_Other_Target using Abilities\Spells\Orc\LightningShield\LightningShieldBuff.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • Unit - Cause CLS_Caster[CLS_ID] to damage CLS_Other_Target, dealing CLS_Damage[CLS_ID] damage of attack type Spells and damage type Normal
                        • Else - Actions
              • -------- --------
              • Custom script: call RemoveLocation( udg_CLS_Point )
              • Custom script: call DestroyGroup( udg_CLS_Damage_Group )
            • Else - Actions
              • Unit Group - Remove CLS_Target from CLS_Buff_Group.
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (CLS_Buff_Group is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
      • -------- --------
      • Unit Group - Pick every unit in CLS_Immune_Group and do (Actions)
        • Loop - Actions
          • Set CLS_Other_Target = (Picked unit)
          • Set CLS_Is_Target_Immune[(Custom value of CLS_Other_Target)] = False
          • Unit Group - Remove CLS_Other_Target from CLS_Immune_Group.
 

Attachments

  • Custom Lightning Shield 2.w3m
    25.7 KB · Views: 2
Last edited:
Top