• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Remove unit within range of other unit

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
Dear Hive,

I have following issue: I made a production building as well as a second version of it, which represents "Page 2" of the unit tab, since it was overfilled in the first production building. Now everytime the main production building is constructed it also creates a small/invisible "Page 2" version so the player can switch between them. Now I need to know how I could make a trigger, that removes this second page building when the main building is destroyed or killed. Since I only want the Page 2 Building belonging to the respective production building which is destroyed instead of every page 2 building on the map to disappear I tried to work with range, which unfortunately didn't work.
  • Self Destruction Instructor
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Self Destruct (instructor)
    • Actions
      • Set VariableSet InstructorPage2_remove = (Units within 300.00 of (Position of (Casting unit)) matching (((Unit-type of (Triggering unit)) Equal to Instructor Page 2) and ((Owner of (Triggering unit)) Equal to (Owner of (Casting unit)))).)
      • Unit - Kill (Triggering unit)
      • Unit - Remove (Triggering unit) from the game
      • Unit Group - Pick every unit in InstructorPage2_remove and do (Unit - Remove (Picked unit) from the game)
      • Custom script: call DestroyGroup(udg_InstructorPage2_remove)
I know that the location of casting unit leaks, I wanted to fix it after the trigger starts to work properly^^

Thanks in advance.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Use a Unit Indexer or a Hashtable to link the Page 2 building to the primary building. So as long as you have access to the primary building you can also get it's Page 2 building.

Hashtables:

Unit Indexer:

A simple example of this method using a Unit Indexer (a few comments down, look for my post regarding Unit Indexing):
 
Level 7
Joined
May 30, 2018
Messages
290
Use a Unit Indexer or a Hashtable to link the Page 2 building to the primary building. So as long as you have access to the primary building you can also get it's Page 2 building.

Hashtables:

Unit Indexer:

A simple example of this method using a Unit Indexer (a few comments down, look for my post regarding Unit Indexing):
Hey man, I tried my best to get into the stuff you sent me....and it actually worked O: But I still think I set it up in a pretty terrible way, so maybe you can help me clean it up :)?

  • Cocreation
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Instructor
    • Actions
      • Unit - Create 1 Instructor Page 2 for (Owner of (Triggering unit)) at (Position of (Constructed structure)) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to I2_UnitGroup
      • Hashtable - Save Handle OfI2_UnitGroup as 1 of 1 in I2_Hash.

  • Self Destruction Instructor
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Self Destruct (instructor)
    • Actions
      • Unit - Kill (Triggering unit)
      • Unit - Remove (Triggering unit) from the game
      • Unit Group - Pick every unit in I2_UnitGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet I2_UnitGroup = (Load 1 of 1 in I2_Hash.)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
As I mentioned, it works :D So thats pretty cool.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
I see a lot of issues there.

But first I'll ask, will there be more than 2 buildings? If not, simply save the Page 2 building to the Hashtable instead of storing it in a group and saving the group.

For example here's how we save the Page 2 building and pair it to our Instructor building:
  • Actions:
  • Unit - Create 1 Instructor Page 2 for (Owner of (Triggering unit)) at (Position of (Constructed structure)) facing Default building facing degrees
  • Hashtable - Save Handle of (Last created unit) as Key(Constructed structure) of 0 in I2_Hash

Now when you want to remove Page 2:
  • Events:
  • Unit - A unit Begins casting an ability
  • Actions:
  • Set Variable Page2Unit = (Load Key(Triggering unit) of 0 in I2_Hash)
  • Unit - Remove Page2Unit from the game
  • OR to simplify it even more you can skip the variable entirely and just do this:
  • Unit - Remove (Load Key(Triggering unit) of 0 in I2_Hash) from the game
Triggering unit needs to be the Instructor. In this case Triggering unit is the same as Casting unit so this works.


So in my example I am saving the Page 2 Unit in the Hashtable under Key(Constructed structure). Key(Constructed structure) is the handle id of the Instructor building, which will be some randomly generated integer (like 12123565). No two units share the same handle id, so that guarantees that this will be MUI. Then when I want to load the Page 2 unit I simply Load our Instructor's handle (Key) from the Hashtable. Also note that this data is being stored at position 0 in the hashtable, which means that we can store other data at other positions like 1, 2, 3, etc... These different positions can come in handy if you want to use a single Hashtable to store many different things.
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
I see a lot of issues there.

But first I'll ask, will there be more than 2 buildings? If not, simply save the Page 2 building to the Hashtable instead of storing it in a group and saving the group.

For example here's how we save the Page 2 building and pair it to our Instructor building:
  • Unit - Create 1 Instructor Page 2 for (Owner of (Triggering unit)) at (Position of (Constructed structure)) facing Default building facing degrees
  • Hashtable - Save Handle of (Last created unit) as Key(Triggering unit) of 0 in I2_Hash

Now when you want to remove Page 2:
  • Set Variable Page2Unit = (Load Key(Triggering unit) of 0 in I2_Hash)
  • Unit - Remove Page2Unit from the game
  • ///
  • OR to simplify it even more you can just do this:
  • Unit - Remove (Load Key(Triggering unit) of 0 in I2_Hash) from the game
Triggering unit is the Instructor in this case since it's the unit casting the Self Destruct ability.


So in my example I am saving the Page 2 Unit in the Hashtable under Key(Triggering unit). Key(Triggering unit) is the handle id of the Instructor building, which will be some randomly generated integer (like 12123565). No two units share the same handle id, so that guarantees that this will be MUI. Then when I want to load the Page 2 unit I simply Load our Instructor's handle from the Hashtable. Also note that this data is being stored at position 0 in the hashtable, meaning we can store other data at other positions like 1, 2, 3, etc...
Ahhh now this makes a lot of sense! Ill try to improve on it. But this explanation of yours was very clear, thank you a lot :)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
I made some slight errors and edited my comment, so make sure your triggers looks like mine.

I recommend removing the Page 2 unit before you remove the Instructor. Sometimes things can go wrong if you try to interact with a Removed unit since it's information may be lost (can't interact with something that no longer exists).
 
Last edited:
Status
Not open for further replies.
Top