Struggling with custom chain lightning spell?

Level 1
Joined
Mar 13, 2021
Messages
5
Hey team, first post here so sorry if an image isn't the best way to post this. If there is a better way to post it please let me know and I'll edit the post.

I'm having trouble with a custom chain lightning spell which is intended to work the following way:

Ability 1: Deal damage to an enemy and apply "Static Charge" debuff to them.
Ability 2: Shot a bolt of lightning at the target and deal damage to them, the lightning will then bounce to all nearby enemies afflicted by Static Charge [Electric_Group].

The problem i'm having is that when there are two or more targets in [Electrocute_Group], it will strike one less target than intended. It works perfectly fine when [Electrocute_Group] contains one unit, but any number above 1 will result in n-1 targets hit.

Is there something that i'm missing here?

edit: thanks for the guide, have reuploaded trigger :)

  • Electrocute Copy
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Electrocute [E]
    • Actions
      • -------- Local Setup --------
      • Set VariableSet Electrocute_Caster = (Triggering unit)
      • Set VariableSet Spell_Power = (Real((Intelligence of Electrocute_Caster (Include bonuses))))
      • Set VariableSet Electrocute_Damage = (8 + (Integer((Spell_Power x 1.80))))
      • Set VariableSet Electrocute_Target[1] = (Target unit of ability being cast)
      • -------- Spell Effect --------
      • Wait 0.30 seconds
      • Set VariableSet Electrocute_Point[1] = (Position of Electrocute_Caster)
      • Set VariableSet Electrocute_Point[2] = (Position of Electrocute_Target[1])
      • Custom script: set udg_Electrocute_Lightning = AddLightningEx("FORK", true , GetLocationX(udg_Electrocute_Point[1]), GetLocationY(udg_Electrocute_Point[1]), 70, GetLocationX(udg_Electrocute_Point[2]), GetLocationY(udg_Electrocute_Point[2]), 70)
      • Special Effect - Create a special effect attached to the origin of Electrocute_Target[1] using Abilities\Weapons\Bolt\BoltImpact.mdl
      • Special Effect - Destroy (Last created special effect)
      • Set VariableSet Electrocute_Lightning = (Last created lightning effect)
      • Set VariableSet Electrocute_Health = (Life of Electrocute_Target[1])
      • -------- -------------------- --------
      • Unit - Set life of Electrocute_Target[1] to (Electrocute_Health - (Real((Electrocute_Damage x 2))))
      • Unit - Remove Static Charge (Custom) buff from Electrocute_Target[1]
      • Set VariableSet Electrocute_Group = (Units in (Playable map area) matching (((Matching unit) has buff Static Charge (Custom)) Equal to True))
      • For each (Integer Electrocute_Loop) from 1 to (Number of units in Electrocute_Group), do (Actions)
        • Loop - Actions
          • Wait 0.15 seconds
          • Set VariableSet Electrocute_Distance = 9999.00
          • Set VariableSet Electrocute_Target[2] = Electrocute_Target[1]
          • Set VariableSet Electrocute_Point[2] = (Position of Electrocute_Target[2])
          • Unit Group - Pick every unit in Electrocute_Group and do (Actions)
            • Loop - Actions
              • Set VariableSet Electrocute_Point[1] = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Electrocute_Distance Greater than (Distance between Electrocute_Point[1] and Electrocute_Point[2])
                • Then - Actions
                  • Set VariableSet Electrocute_Target[1] = (Picked unit)
                  • Set VariableSet Electrocute_Distance = (Distance between Electrocute_Point[1] and Electrocute_Point[2])
                • Else - Actions
          • Lightning - Destroy Electrocute_Lightning
          • Custom script: set udg_Electrocute_Lightning = AddLightningEx("FORK", true , GetLocationX(udg_Electrocute_Point[2]), GetLocationY(udg_Electrocute_Point[2]), 70, GetLocationX(udg_Electrocute_Point[1]), GetLocationY(udg_Electrocute_Point[1]), 70)
          • Special Effect - Create a special effect attached to the origin of Electrocute_Target[1] using Abilities\Weapons\Bolt\BoltImpact.mdl
          • Special Effect - Destroy (Last created special effect)
          • Set VariableSet Electrocute_Lightning = (Last created lightning effect)
          • Set VariableSet Electrocute_Health = (Life of Electrocute_Target[1])
          • Unit - Set life of Electrocute_Target[1] to (Electrocute_Health - (Real((Electrocute_Damage x 2))))
          • Unit Group - Remove Electrocute_Target[1] from Electrocute_Group.
          • Unit - Remove Static Charge (Custom) buff from Electrocute_Target[1]
      • Custom script: call RemoveLocation(udg_Electrocute_Point[1])
      • Custom script: call RemoveLocation(udg_Electrocute_Point[2])
 
Last edited:

Uncle

Warcraft Moderator
Level 39
Joined
Aug 10, 2018
Messages
3,977
First are foremost you want to use this Event:
  • Unit - A unit Starts the effect of an ability
Starts the effect happens at the precise moment that the ability executes it's effects (spends mana, goes on cd, launches a missile, deals damage, etc).
Begins casting happens prior to this, while your unit is still playing it's cast animation. This means that the Event will fire even if the unit cancels the cast. This could be exploited very easily by the players by repeatedly casting and cancelling.

Second, you want to use the "Cause damage" Action instead of subtracting Life from the enemies:
  • Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing 100 damage of attack type Spells and damage type Normal
This allows you to take advantage of Damage Types as well giving proper credit to the Killing unit for things like Bounty/Experience rewards.

For the n-1 targets hit issue, I'm sure it's something simple that we're overlooking but have you tried doing this:
  • For each (Integer Electrocute_Loop) from 1 to (Number of units in Electrocute_Group) + 1, do (Actions)
 
Level 1
Joined
Mar 13, 2021
Messages
5
First are foremost you want to use this Event:
  • Unit - A unit Starts the effect of an ability
Starts the effect happens at the precise moment that the ability executes it's effects (spends mana, goes on cd, launches a missile, deals damage, etc).
Begins casting happens prior to this, while your unit is still playing it's cast animation. This means that the Event will fire even if the unit cancels the cast. This could be exploited very easily by the players by repeatedly casting and cancelling.

Second, you want to use the "Cause damage" Action instead of subtracting Life from the enemies:
  • Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing 100 damage of attack type Spells and damage type Normal
This allows you to take advantage of Damage Types as well giving proper credit to the Killing unit for things like Bounty/Experience rewards.

For the n-1 targets hit issue, I'm sure it's something simple that we're overlooking but have you tried doing this:
  • For each (Integer Electrocute_Loop) from 1 to (Number of units in Electrocute_Group) + 1, do (Actions)
Thank you, I actually have specific reasons I do both of these things and usually I have the cool down incurred at the start of the trigger, but I’ve removed some of the wish wash / leak fixes to make the trigger more legible.
Just looking for the cause of the n-1 issue.

As for your solution I had tried that, but then it strikes the first target twice if there are no units in Electrocute group, so not an ideal solution. :(
 
Top