• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Custom Spell Inconsistency

Level 1
Joined
Mar 2, 2024
Messages
2
Hello guys! This is my first time posting here and I'm kind of a noob when it comes to triggers; all my knowledge is GUI and I search how to make most of the things I try.

I have a custom skill concept I want to execute, and it feels like I'm almost done with it, but what happens is... It's way too inconsistent and something I can't point out is probably leaking.

The concept itself is: On my map, every playable hero will start with a trait ability that can't be levelled up. This one will start with an active skill called Lunar Infusion, which is a buff spell (made out of Bloodlust) that'll mark an allied unit and spawn a dummy on top of the buffed unit every 2 seconds, which will then cast Lunar Strike (made out of Acid Bomb) at a random nearby enemy also every 2 seconds, dealing 10 + (Caster Intelligence) damage. The buff has permanent duration but can only be applied to a single target at once. If the hero tries to buff another target, the previous one will be removed.

The triggers can probably be briefed, but take it easy on me since I'm just a beginner. My issue is: Trigger 1 and 2 seems to work just fine, but the third trigger seems to be leaking or failing since the dummy is inconsistent when casting Lunar Strike. Sometimes he will, sometimes he won't.

Trigger 1: Lunar Infusion's buff setup
  • Infusao Lunar Setup
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Lunar Infusion
    • Actions
      • Set VariableSet Caster = (Casting unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Infundido_Target Equal to No unit
        • Then - Actions
          • Set VariableSet Infundido_Target = (Target unit of ability being cast)
          • Special Effect - Create a special effect attached to the origin of Infundido_Target using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
        • Else - Actions
          • Unit - Remove All buffs from Infundido_Target
          • Set VariableSet Infundido_Target = (Target unit of ability being cast)
          • Special Effect - Create a special effect attached to the origin of Infundido_Target using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
Trigger 2: Picking available targets for the Lunar Strike
  • Mira Lunar
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Remove all units from MiraLunar_Targets.
      • Unit Group - Pick every unit in (Units within 800.00 of (Position of Infundido_Target) matching (((Picked unit) belongs to an enemy of (Owner of Caster).) Equal to True).) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to MiraLunar_Targets
Trigger 3: Dummy creation and Lunar Strike execution
  • Golpe Lunar
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
      • (Infundido_Target is alive) Equal to True
    • Actions
      • Set VariableSet MiraLunar_AlvoAleatorio = (Random unit from MiraLunar_Targets)
      • Unit - Create 1 Dummy Lunar Strike for (Owner of Caster) at (Position of Infundido_Target) facing Default building facing degrees
      • Unit - Add Lunar Strike to (Last created unit)
      • Unit - Order (Last created unit) to Neutral Alchemist - Acid Bomb MiraLunar_AlvoAleatorio
      • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
I haven't created the last trigger to setup the Lunar Strike's damage yet because I'm trying to fix this problem first. As for the variables which I don't know if they're right:

Caster = Unit
InfundidoTarget (Target of the Lunar Infusion) = Unit
MiraLunar_Targets (Available targets for Lunar Strike) = Unit Group
MiraLunar_AlvoAleatorio (Random target for Lunar Strike) = Unit

Thanks in advance!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,555
Hello, so I recreated your spell in the map attached down below. It relies on two simple but powerful systems:
Missile System
Unit Indexer
I recommend learning how to take advantage of these systems since they enable you to create more advanced triggers. Using these allowed me to design my triggers to be completely MUI, meaning you could give this ability to any number of units and it'll still work as intended.

Regarding your triggers, here's some mistakes:

1) You're using the wrong Event in your first trigger. You almost always want to use the Starts effect Event when casting spells:
  • Events
    • Unit - A unit Starts the effect of an ability
Begins casting occurs during the "wind-up" animation that plays before executing an ability. So any trigger using this Event will run regardless of whether you successfully cast the ability or not. This is a big problem since the user can easily cancel the cast with a "Stop" command or the caster could get stunned/interrupted from an outside source.

2) It doesn't make sense to have both Trigger 2 and Trigger 3. You want the Actions of both of these triggers to happen at the same time, yet you're separating their logic and losing control of which trigger occurs first. You should combine them into one trigger. Then in this single trigger you can use an If Then Else action to ask your question "Is Infundido_Target alive?" and proceed to run the necessary actions if True or False. Learn more here: If Then Else.

3) Your Unit Group doesn't have enough filters to exclude unwanted units and you need to use (Matching unit) not (Picked unit):
  • Unit Group - Pick every unit in (Units within 800.00 of (Position of Infundido_Target) matching (((Matching unit) belongs to an enemy of (Owner of Caster).) Equal to True).) and do (Actions)
Checking if they're owned by enemies isn't enough, you need to filter out Dead units, Buildings, Invulnerable units, Magic immune units, Mechanical units, etc. Remember that Acid Bomb can't target any of those.

4) I doubt you want to Remove ALL buffs from the target:
  • Unit - Remove All buffs from Infundido_Target
You should use the Remove specific buff action and only get rid of Lunar Infusion.

5) You're leaking a Unit Group and a Point here:
  • Unit Group - Pick every unit in (Units within 800.00 of (Position of Infundido_Target) matching (((Picked unit) belongs to an enemy of (Owner of Caster).) Equal to True).) and do (Actions)
And you leak a Point here:
  • Unit - Create 1 Dummy Lunar Strike for (Owner of Caster) at (Position of Infundido_Target) facing Default building facing degrees
There's plenty of tutorials on memory leaks and how to clean them up.
 

Attachments

  • Luanr Infusion Uncle1.w3m
    87.7 KB · Views: 5
Last edited:
Level 1
Joined
Mar 2, 2024
Messages
2
Thank you so much for the pointers! I really appreciate it so I can know what I'm doing wrong. Oh, and I'll also take a look into the tutorials you linked, thanks again :D
 
Top