Kill Summoned units after Summoner Dies

eric922

Active Member
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
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
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
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
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
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
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
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
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

General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    Question: Is there a way to remove thread redirects? It creates a copy of the moved thread and takes up space, and I am leaning towards wanting to remove them in the Headline News. But if they have an expiration date, I guess I'm fine with it.
  • The Helper The Helper:
    If you move a thread please leave a permanent redirect. You can delete any redirects after 6 months. The redirects are left to help Search Engines find the moved content.
  • tom_mai78101 tom_mai78101:
    What if you move the permanent redirect, not the thread?
  • The Helper The Helper:
    I think that works but I have not messed with it. You can delete redirects though if you have to that will not delete the original thread
  • The Helper The Helper:
    if a redirect ends up in the same forum as the post it goes to though I think the redirect drops or fails or something but they are not bugged out and when you are working on an indirect the original post is safe.
  • The Helper The Helper:
    Happy Early Friday :)
    +1
  • V-SNES V-SNES:
    Happy Friday :)
  • tom_mai78101 tom_mai78101:
    Fun Friday for me
  • tom_mai78101 tom_mai78101:
    Happy Fun Friday to all.
    +2
  • The Helper The Helper:
    Happy Sunday everyone!!!
  • V-SNES V-SNES:
    Happy Sunday!!!
    +1
  • jonas jonas:
    Happy monday :p
  • jonas jonas:
    Everyone hates mondays?
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • jonas jonas:
    Happy belated tuesday
  • tom_mai78101 tom_mai78101:
    I found out you can't delete nor hide redirect links to existing threads. It will just stay there. I have no choice now but to start moving thread redirects to News Archive.
  • The Helper The Helper:
    That is not the way that it works for me I can delete redirects you just have to hit refresh sometimes big deletes will take a while as long as moves\
  • The Helper The Helper:
    You don't have to do that you can just leave stuff there in headline news for up to a year it was already down to like 8 months there is no rush.
  • The Helper The Helper:
    We need to do something about the Headline News forum now that Ghan got the News script to work on the forums. We need an Other category really now more than we need a headline news forum full of redirects
  • The Helper The Helper:
    wow i just noticed there are no redirects left in Headline news lol!
  • The Helper The Helper:
    so much for the redirects I think they are useless anyway because posts urls are set and the redirects were just extra if something is indexed by the search engine it still will be without the redirect since the original url does not change
  • tom_mai78101 tom_mai78101:
    I was wondering if it'd be best to consolidate all of the Headline News threads into 1 place, and then let the users click on navigation links that would show/hide threads based on their thread flairs? Splitting the Headline News up like this would mean the only way to see all of the news is to go to the Home page and check there.
  • jonas jonas:
    I usually just browse the homepage for news
  • tom_mai78101 tom_mai78101:
    Good to know.

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top