• 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.

Unit Specific Lifesteal (attacks done by a specific unit heal a specific unit)

Level 2
Joined
Nov 27, 2017
Messages
10
So I plan to make a unit get healed if another unit attacks someone.
Eg: (Summoned unit attacks enemy (attacked enemy is organic/non-mechanical), Summoner is healed for X hp)
I only intended to heal the unit for a fixed value since I am not good in triggers, but it seems that simple variable and set hp is not that easy to do.

Does anybody know how to do it?
 
Last edited:
Level 30
Joined
Aug 29, 2012
Messages
1,382
That's straightforward enough, first you store your hero into a variable somewhere

  • Set Hero
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet SummonerUnit = Archmage 0000 <gen>
So you can refer to it in the lifesteal

  • Life Drain
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Water Elemental (Level 1)
      • (Damage From Normal Attack) Equal to True // boolean condition
      • ((Triggering unit) is Mechanical) Equal to False // boolean condition
    • Actions
      • Unit - Set life of SummonerUnit to ((Life of SummonerUnit) + 100.00)
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Chaosium shows a correct method, but note that it will only work for one summoner at a time. This is because a global variable is used to store the summoner, which cannot have multiple values. You can get around this in two ways, generally:
  • Use two parallel array variables to hold both the summoner and the summoned unit. SummonerUnit[1] would correspond to the summoner and SummonedUnit[1] would correspond to the summoned unit. You can then figure out which 'pair' should be healed by first looping over all the summoned units until you find one that's the same unit as the damage source; then you look at same index of the corresponding SummonerUnit[] array and heal that unit.

  • Use a Unit Indexer system, which effectively assigns all units on the map a unique value that can be used as an array index. You would first associate the pair upon spawning the summoned unit (something like Set SummonerUnit[Custom Value of (Summoned Unit)] = Summoning Unit) and then just read this variable in order to find the associated unit.
 
Level 2
Joined
Nov 27, 2017
Messages
10
Now that days have passed, it got me thinking. What about the ones that are pre-spawned in the map? For example, the Archmage that used in the trigger, what if you tried to summon them first (altar)?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
what if you tried to summon them first (altar)?
Not too sure what you're trying to say here.

Anyway, as long as a Water Elemental (Level 1) damages a unit, the Archmage (or whoever you set SummonerUnit to) will get healed:
  • (Unit-type of (Damage source)) Equal to Water Elemental (Level 1)
You could extend this logic to account for all of the different types of Water Elementals:
  • Life Drain
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • Or - Multiple conditions
        • (Unit-type of (Damage source)) Equal to Water Elemental (Level 1)
        • (Unit-type of (Damage source)) Equal to Water Elemental (Level 2)
        • (Unit-type of (Damage source)) Equal to Water Elemental (Level 3)
      • (Damage From Normal Attack) Equal to True
      • ((Triggering unit) is Mechanical) Equal to False
    • Actions
      • Unit - Set life of SummonerUnit to ((Life of SummonerUnit) + 100.00)
Or you could simplify it to account for any kind of Summoned units:
  • Life Drain
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • ((Damage source) is Summoned) Equal to True
      • (Damage From Normal Attack) Equal to True
      • ((Triggering unit) is Mechanical) Equal to False
    • Actions
      • Unit - Set life of SummonerUnit to ((Life of SummonerUnit) + 100.00)
You may want to check who owns those units as well:
  • (Owner of (Damage source)) Equal to (Owner of SummonerUnit)
This way the triggers only run if the Water Elementals/Summons are owned by Player that owns the Archmage (SummonerUnit).

If you want to make this more advanced so it will work for any number of Archmages at the same time then you can use an indexing technique like Pyro suggested.
 
Top