[Trigger] First Spell Ever, is it MUI/leakless?

Level 5
Jul 6, 2005
Yes it's just firebolt but I want to practice adding attribute damage to abilities.
  • FireBall
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fireball c
    • Actions
      • Set Fireball_Caster = (Triggering unit)
      • Set Fireball_Target = (Target unit of ability being cast)
      • Set Fireball_Attribute = (Intelligence of Fireball_Caster (Include bonuses))
      • Set Fireball_Level = (Level of (Ability being cast) for Fireball_Caster)
      • Set Fireball_Damage = (Real(((Fireball_Level x 15) + Fireball_Attribute)))
      • Set Fireball_TargetLoc = (Position of Fireball_Target)
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Unit - Cause Fireball_Caster to damage Fireball_Target, dealing Fireball_Damage damage of attack type Spells and damage type Unknown
      • Special Effect - Create a special effect attached to the hand, left of Fireball_Caster using units\human\phoenix\phoenix.mdl
      • Special Effect - Destroy (Last created special effect)
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Floating Text - Create floating text that reads ((String((Integer(Fireball_Damage)))) + !) above Fireball_Target with Z offset 0.00, using font size 10.00, color (100.00%, 5.00%, 5.00%), and 0.00% transparency
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change the fading age of (Last created floating text) to 3.00 seconds
      • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Custom script: call RemoveLocation(udg_Fireball_TargetLoc)
How can I sync the damage with the animation? Right now the target is damaged instantly, a few seconds before the fireball impacts.
Level 19
Sep 26, 2009
What you have right now is MUI and leakless, however the variable Fireball_TargetLoc serves no purpose, as you don't use it anywhere.

To sync the damage with animation brings a lot of problems. There's no way for you to easily get the time when unit is hit by the fireball. There are about 3 approaches to solving this problem, however only one is without any issues, yet it's the most complicated one.

Option #1 - calculate the time it would take for the fireball to travel to the target. This will only work if the target is static during the whole flight of the fireball (for example the unit is stunned), because else you have no way to determine where the target will move when the fireball is in flight (target can move/blink in any direction).

Option #2 - make the Fireball deal some constant damage, detect when unit takes damage via Damage Detection System (DDS), null that damage taken and instead deal to the target your own custom damage. The problem here is you have no way to determine what damaged the unit - you can get the source unit that dealt the damage, but you have no way to know if it was from the fireball spell. An example of this option failing is when your caster casts Flamestrike and then casts on the target a Fireball as well. When firebolt is in flight, the flamestrike spell will damage your target and fire the effect of the fireball prematurely.

Option #3 - Completely trigger the whole spell by creating a dummy unit with locust ability (= cannot be targeted/selected) which has the model of the firebolt. Mimic movement of fireball by periodically moving this dummy unit. Everytime you move the dummy, you check the distance of the dummy from the target. If it is close enough, you kill dummy and damage target. 100% fool-proof, yet most complicated.
Level 3
Jun 17, 2015
It instantly deal dmg because it can't detect the missle position.

Try to make a spell that create a fireball dummy, then move it every 0.01s facing target. If distance of dummy and target equal or less than 50 then deal dmg.

Ill send u a sample map later.

sorry for taking so long, i was busy until now

This trigger isnt MUI, so if you give it to 2 units and they cast it in the same time, it cause error (u can request ppl to fix it to MUI)

In the Loop trigger, i left the note that u can edit your custom damage there.


  • Test map for Faction.w3x
    15 KB · Views: 46
Last edited by a moderator:
Level 37
Jul 22, 2015
Here you go! I'm pretty new at triggers myself, so I may have added some redundant functions. I cleaned up your code a bit and made it MUI :) test it out yourself and let me know if you run into any problems. Props to Nichilus for suggesting Option #3!

If you want, you can do something like this to make the damage dealt variable "easier to access."

  • Set FB_Damage[FB_Index] = X])
and then changing this function in your loop.

  • Unit - Cause FB_Caster[FB_LoopInteger] to damage FB_Target[FB_LoopInteger], dealing FB_Damage[FB_LoopInteger] damage of attack type Spells and damage type Magic


  • Fireball.w3x
    15.6 KB · Views: 43