• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

Detect which spell killed unit?

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,555
You can use a Damage Engine to achieve this.

Otherwise, you could create a trigger that orders a unique Dummy unit to cast your spell instead of the Hero and then detect it like so:
  • Events
  • Unit - A unit dies
  • Conditions
  • Unit-type of (Killing unit) Equal to Your Unique Dummy Unit
  • Actions
  • Do stuff
You can use a Hashtable/Unit Indexer to link the Dummy unit to the Hero if need be.
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,555
And i have a 0 knowledge about Hashtable. Thank you for your help but i think i will pass this one.
Use a Unit Indexer instead, much easier to understand: GUI Unit Indexer 1.4.0.0
  • Events
  • Unit - A unit starts the effect of an ability
  • Conditions
  • (Ability being cast) Equal to Your Hero's Spell
  • Actions
  • Unit - Create 1 Unique Dummy Unit...
  • Set Variable YourHero[custom value of (Last created unit)] = (Casting unit)
  • Unit - Order (Last created unit) to cast the damaging spell on (Target unit of ability being cast)
Now you've linked the Dummy to the Hero (casting unit). So if the Dummy unit gets a kill you'll be able to reference the Hero that it's linked to and restore their mana.
  • Events
  • Unit - A unit dies
  • Conditions
  • Unit-type of (Killing unit) Equal to Your Unique Dummy Unit
  • Actions
  • Unit - Set mana of YourHero[custom value of (Killing unit)] to X
So the idea is that the Hero casts a "fake" version of the spell which does nothing besides run the "A unit starts the effect of an ability" trigger. That trigger then creates a Dummy unit that casts the real damaging version of the spell. This ensures that the Dummy unit deals the damage and scores the killing blow which is necessary for our "A unit dies" trigger. Remember, our Dummy unit can only ever deal damage with this one spell so any kills it gets are guaranteed to have come from this spell. Using the Hero as the (Killing unit) wouldn't work properly since our Hero can kill units using many different spells/attacks.

A non-MUI solution would be to use the Player Number instead of Unit Indexing. You could then easily link the Hero/Dummy like so:
  • Set Variable YourHero[Player number of (Owner of (Casting unit))] = (Casting unit)
  • Unit - Set mana of YourHero[Player number of (Owner of (Killing unit))] to X
 
Last edited:
Status
Not open for further replies.
Top