Kill Summoned units after Summoner Dies

eric922

Active Member
Reaction score
0
How would you make it so when a unit dies, all of it's summoned units die also? Would I do this with triggers?

I tried to make a trigger that adds the summoned units to a "Unit Group Array" and then when the summoning unit dies, have a trigger that kills all of the units that were added to the Unit Group, but didn't work.
 

O.A

Quantum physics rules
Reaction score
29
You should always post your trigger as well so folks can see what's not working. You can copy the trigger as text in between the tags [.wc3][./wc3] (without the punctuation marks)

That being said, using a Unit Group array is a good way to do this if you don't need MUI, something like this;
Trigger:
  • AddAllThings
    • Events
    • Unit - A unit Spawns a summoned unit
    • Conditions
    • Actions
    • Unit Group - Add (Triggering unit) to Aug_SummonedUnits[(Player number of (Owner of (Triggering unit)))]


Trigger:
  • KillAllThings
    • Events
    • Unit - A unit Dies
    • Conditions
    • Actions
    • Unit Group - Pick every unit in Aug_SummonedUnits[(Player number of (Owner of (Triggering unit)))] and do (Actions)
    • Loop - Actions
    • Unit - Kill (Picked unit)
    • Unit Group - Remove all units from Aug_SummonedUnits[(Player number of (Owner of (Triggering unit)))]


Fill in the conditions and other things based on your map.
 

eric922

Active Member
Reaction score
0
I tried this and it did not work, maybe I did something wrong? I am making a Necromancer in my game and he summons skeletons when attacked. When I kill the Necromancer I would like all of his summons to die as well.

For the "Unit Group" variable, I called mine "Skeleton_Array" and variable type is Unit Group, size is 10. I didn't know what to put for the size so I tested it with different numbers and each test failed to kill the summoned units after the Necromancer dies. Here is my code:

Trigger:
  • Necro Skeletons
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
    • Actions
      • Unit Group - Add (Summoned unit) to Skeleton_Array[(<i>Player number of (Owner of (Triggering unit</i>)))]


Trigger:
  • Kill Necro Skeletons
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Skeleton_Array[(Player number of (Owner of (Triggering unit)))] and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)
          • Unit Group - Remove all units from Skeleton_Array[(Player number of (Owner of (Triggering unit)))]


I tried with conditions to, but then took them out to simplify the trigger once I saw that it was not working.
The part that I really don't understand is this part: Skeleton_Array[(Player number of (Owner of (Triggering unit)))]
I do not know what this part means or does.
Trigger:
  • Unit Group - Add (Summoned unit) to Skeleton_Array[(Player number of (Owner of (Triggering unit)))]



UPDATE:
I found a way to kill all summoned units for the entire player after a Necromancer dies. This is better that what I had before, but I would like to make a trigger that only kills the summoned units of the unit that specifically summoned them. Example; you are fighting two necromancers at once and you kill one, all summoned units from both necromancers would die. I would like to make it so only the summoned units of the specific necromancer who died, would die at the same time.

Here is the code anyway, it might help:
Trigger:
  • Kill Necro Skeletons
    • Events
      • Unit - A unit Dies
    • Conditions
      • (((Dying unit) is Summoned) Equal to False) and ((Owner of (Dying unit)) Equal to Player 12 (Brown))
    • Actions
      • Unit Group - Pick every unit in (Units owned by (Owner of (Dying unit)) matching (((Matching unit) is Summoned) Equal to True)) and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)
 
Last edited:

Accname

2D-Graphics enthusiast
Reaction score
1,462
I found a way to kill all summoned units for the entire player after a Necromancer dies. This is better that what I had before, but I would like to make a trigger that only kills the summoned units of the unit that specifically summoned them. Example; you are fighting two necromancers at once and you kill one, all summoned units from both necromancers would die. I would like to make it so only the summoned units of the specific necromancer who died, would die at the same time.
The correct terminology is MPI vs MUI. What you have right now is MPI (Multi-Player-Instanceable), you kill all summoned units that belong to a certain player. What you want is MUI (Multi-Unit-Instanceable), killing all units summoned by a certain unit.

To make the triggers MUI you are going to need a way to reference the summoner by the summons. There 3 ways to do this that I know of:
1) Get a unit indexing library. This could be heavy weight and overkill if you use it only for this single purpose.
2) Use Hashtables, a very reliable option but for beginners its often hard to understand at first how they work.
3) Use a little glitch and abuse the Rally ability. Give the summoned units the Rally ability and, when summoned, make them set their rally-point to their summoner. Later, you can use the rally-point to reference the summone of the unit.
 

O.A

Quantum physics rules
Reaction score
29
You don't need to set up the size of most arrays at all. It looks like the trigger you have made is for player 12, and if your array size is set to 10 the trigger probably won't work because of that, not sure.
'Player number of (Owner of (Triggering unit))' takes the number of the player (1-12) and places the units into that slot in the array. (E.g Player 4 = Skeleton Array [4]).

But like I said if you need MUI these triggers are useless. This only works if you have, for example, one hero per player whose summoned units you wish to kill off.
Sounds like you want MUI, which will not be as simple. Accname has listed options for that already I see.
 

eric922

Active Member
Reaction score
0
Does anyone know of a good Hash Table tutorial for WC3? I have taken a few programming classes including Python and Perl, so I am familiar with how hash tables work. Basically it's an array where each value has a corresponding key value.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Basically it's an array where each value has a corresponding key value.
Not really, no.

A hashtable is, first and foremost, a table. Its a 2-dimensional data structure.
Every cell of the table contains one piece of data. The data can be of any type, and every cell of the table can hold a different type of data.

Now comes the "hash" part. The cells are not indexed with normal integers like in a standard table (like a 2 dimensional array for example) instead they are indexed by 2 keys.
One key for the column, and one key for the row. The keys can also be any kind of data. You can use 2 Strings, one String and an Integer, a String and a Unit, two Units, a Unit and a Player, anything.
In the background the keys will be hashed to generate integer values out of them, but I am not goin to explain the technical stuff.

What is important is that its a 2-dimensional table that can use any kinds of keys, of any type, to store any number of data, of any type.
Its powerful, its complex and its really damn useful.
 

Slapshot136

Divide et impera
Reaction score
471
3) Use a little glitch and abuse the Rally ability. Give the summoned units the Rally ability and, when summoned, make them set their rally-point to their summoner. Later, you can use the rally-point to reference the summone of the unit.

wouldn't the Rally disappear when the summoner dies?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
wouldn't the Rally disappear when the summoner dies?
Nope. Works like a charm.

Of course, the downside of this is, that the summons must NOT be controllable by the owner! If the owner changes the rally point then this will obviously not work anymore...

I attached a demo map showing how this would be done.
 

Attachments

  • KillDemSummonerz.w3x
    17.6 KB · Views: 392
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top