• 🏆 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!

How to check unit type in a group?

Level 2
Joined
May 14, 2024
Messages
6
Lets say in a unit group i have A B C and A
I only want to pick A B C and leaves A
For more detail, i want to upgrade my tower like in Gem TD
Thats mean i want destroy the component after i upgrade the tower but i ran into the issue of destroying unused or extra component i got left
Please help
Also i can only do it in GUI, i know nothing about Jass
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,703
I only want to pick A B C and leaves A
Hello, you're looking for the If Then Else Action which let's you ask questions anywhere in your Actions:

1715679072001.png


So when you're looping over your Unit Group you would ask the question, what type of unit is this?
  • Actions
    • Unit Group - Pick every unit in YOUR_UNIT_GROUP and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Picked unit)) Equal to Guard Tower
          • Then - Actions
            • Unit - Kill (Picked unit)
          • Else - Actions
^ That will kill all of the Guard Towers inside of the Unit Group.

This version will kill all of the Guard Towers and Cannon Towers by asking if it's one OR the other:
  • Actions
    • Unit Group - Pick every unit in YOUR_UNIT_GROUP and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Or - Any (Conditions) are true
              • Conditions
                • (Unit-type of (Picked unit)) Equal to Guard Tower
                • (Unit-type of (Picked unit)) Equal to Cannon Tower
          • Then - Actions
            • Unit - Kill (Picked unit)
          • Else - Actions
1715679189497.png
1715679256835.png
 
Last edited:
Level 2
Joined
May 14, 2024
Messages
6
Hello, you're looking for the If Then Else Action which let's you ask questions anywhere in your Actions:

View attachment 473047

So when you're looping over your Unit Group you would ask the question, what type of unit is this?
  • Actions
    • Unit Group - Pick every unit in YOUR_UNIT_GROUP and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Picked unit)) Equal to Guard Tower
          • Then - Actions
            • Unit - Kill (Picked unit)
          • Else - Actions
^ That will kill all of the Guard Towers inside of the Unit Group.

This version will kill all of the Guard Towers and Cannon Towers by asking if it's one OR the other:
  • Actions
    • Unit Group - Pick every unit in YOUR_UNIT_GROUP and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Or - Any (Conditions) are true
              • Conditions
                • (Unit-type of (Picked unit)) Equal to Guard Tower
                • (Unit-type of (Picked unit)) Equal to Cannon Tower
          • Then - Actions
            • Unit - Kill (Picked unit)
          • Else - Actions
View attachment 473048View attachment 473049
Hi thanks for replying so fast

If i understand correctly
Your version of trigger unfortunately will kill all the extra tower i have
For Example:
If i have "2 Guard Tower" and "2 Cannon Tower" i will kill all of them by upgrade my tower "1 times" instead of i can upgrade "2 times"
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,703
So how much of the trigger have you made already?
Or are you unsure of how to get started? Because I was under the impression that you already had the Unit Groups setup with the Units you needed.

Regardless, here's a trigger that COULD work:
  • Actions
    • Set VariableSet Tower_Group_1 = (Units owned by (Triggering player) of type Guard Tower)
    • Set VariableSet Tower_Group_2 = (Units owned by (Triggering player) of type Cannon Tower)
    • Unit - Kill (Random unit from Tower_Group_1)
    • Unit - Kill (Random unit from Tower_Group_2)
This will create two new Unit Groups, one containing all of your Guard Towers and another containing all of your Cannon Towers. It will then kill 1 from each group. Note that this assumes that the Player actually has at least 1 of each of these.

You can make sure that the groups aren't empty by doing this:
  • Actions
    • Set VariableSet Tower_Group_1 = (Units owned by (Triggering player) of type Guard Tower)
    • Set VariableSet Tower_Group_2 = (Units owned by (Triggering player) of type Cannon Tower)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Number of units in Tower_Group_1) Greater than 0
        • (Number of units in Tower_Group_2) Greater than 0
      • Then - Actions
        • Unit - Kill (Random unit from Tower_Group_1)
        • Unit - Kill (Random unit from Tower_Group_2)
        • -------- Do something special --------
      • Else - Actions
 
Level 2
Joined
May 14, 2024
Messages
6
So how much of the trigger have you made already?
Or are you unsure of how to get started? Because I was under the impression that you already had the Unit Groups setup with the Units you needed.

Regardless, here's a trigger that COULD work:
  • Actions
    • Set VariableSet Tower_Group_1 = (Units owned by (Triggering player) of type Guard Tower)
    • Set VariableSet Tower_Group_2 = (Units owned by (Triggering player) of type Cannon Tower)
    • Unit - Kill (Random unit from Tower_Group_1)
    • Unit - Kill (Random unit from Tower_Group_2)
This will create two new Unit Groups, one containing all of your Guard Towers and another containing all of your Cannon Towers. It will then kill 1 from each group. Note that this assumes that the Player actually has at least 1 of each of these.
Wow i think will work, i just want to find a way to kill each type of tower 1 times, thank you very much, you are so helpful
I will test it tonight
 
Level 2
Joined
May 14, 2024
Messages
6
  • Watch Tower
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Watch Tower
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Guard Tower TRIGSTR_095
        • Then - Actions
          • Unit Group - Add (Casting unit) to GuardTower
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Arcane Tower TRIGSTR_096
                • Then - Actions
                  • Unit Group - Add (Picked unit) to ArcaneTower
                • Else - Actions
                  • Do nothing
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Death Tower TRIGSTR_098
                • Then - Actions
                  • Unit Group - Add (Picked unit) to DeathTower
                • Else - Actions
                  • Do nothing
          • Unit - Replace (Random unit from GuardTower) with a Watch Tower using The new unit's max life and mana
          • Unit - Replace (Random unit from ArcaneTower) with a Mazing Rock using The new unit's max life and mana
          • Unit - Replace (Random unit from DeathTower) with a Mazing Rock using The new unit's max life and mana
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Arcane Tower TRIGSTR_096
        • Then - Actions
          • Unit Group - Add (Casting unit) to ArcaneTower
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Guard Tower TRIGSTR_095
                • Then - Actions
                  • Unit Group - Add (Picked unit) to GuardTower
                • Else - Actions
                  • Do nothing
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Death Tower TRIGSTR_098
                • Then - Actions
                  • Unit Group - Add (Picked unit) to DeathTower
                • Else - Actions
                  • Do nothing
          • Unit - Replace (Random unit from GuardTower) with a Mazing Rock using The new unit's max life and mana
          • Unit - Replace (Random unit from ArcaneTower) with a Watch Tower using The new unit's max life and mana
          • Unit - Replace (Random unit from DeathTower) with a Mazing Rock using The new unit's max life and mana
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Death Tower TRIGSTR_098
        • Then - Actions
          • Unit Group - Add (Casting unit) to DeathTower
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Guard Tower TRIGSTR_095
                • Then - Actions
                  • Unit Group - Add (Picked unit) to GuardTower
                • Else - Actions
                  • Do nothing
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Arcane Tower TRIGSTR_096
                • Then - Actions
                  • Unit Group - Add (Picked unit) to ArcaneTower
                • Else - Actions
                  • Do nothing
          • Unit - Replace (Random unit from GuardTower) with a Mazing Rock using The new unit's max life and mana
          • Unit - Replace (Random unit from ArcaneTower) with a Mazing Rock using The new unit's max life and mana
          • Unit - Replace (Random unit from DeathTower) with a Watch Tower using The new unit's max life and mana
        • Else - Actions
Hi, this is my trigger at the moment, not having any bug so far
 
Level 2
Joined
May 14, 2024
Messages
6
Keep in mind that:
1) That will only work for one Player.
2) You're never removing units from the Unit Groups.
3) You're never checking if those groups actually have the units. (I edited my last post to account for this but I think you missed it)
4) This is extremely inefficient.
Hi again
There is no way im good enough to make a multiplayer map without a tons of bug so at the moment i need to work on single player map first
BTW, i redo my trigger into 3 different trigger, here is it
  • Filter
    • Events
      • Time - Every 0.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in GuardTower) Less than 1
        • Then - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Guard Tower
                • Then - Actions
                  • Unit Group - Add (Picked unit) to GuardTower
                • Else - Actions
                  • Do nothing
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in ArcaneTower) Less than 1
        • Then - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Arcane Tower
                • Then - Actions
                  • Unit Group - Add (Picked unit) to ArcaneTower
                • Else - Actions
                  • Do nothing
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in DeathTower) Less than 1
        • Then - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Death Tower
                • Then - Actions
                  • Unit Group - Add (Picked unit) to DeathTower
                • Else - Actions
                  • Do nothing
        • Else - Actions
  • Filter 2
    • Events
      • Time - Every 0.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in GuardTower) Greater than 1
        • Then - Actions
          • Unit Group - Remove (Random unit from GuardTower) from GuardTower.
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in ArcaneTower) Greater than 1
        • Then - Actions
          • Unit Group - Remove (Random unit from ArcaneTower) from ArcaneTower.
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in DeathTower) Greater than 1
        • Then - Actions
          • Unit Group - Remove (Random unit from DeathTower) from DeathTower.
        • Else - Actions
          • Do nothing
  • Watch Tower
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Watch Tower (Neutral Hostile)
      • (Number of units in GuardTower) Equal to 1
      • (Number of units in ArcaneTower) Equal to 1
      • (Number of units in DeathTower) Equal to 1
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Guard Tower
        • Then - Actions
          • Unit - Replace (Casting unit) with a Watch Tower using The old unit's relative life and mana
          • Unit - Replace (Random unit from ArcaneTower) with a Mazing Rock using The old unit's relative life and mana
          • Unit - Replace (Random unit from DeathTower) with a Mazing Rock using The old unit's relative life and mana
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Casting unit)) Equal to Arcane Tower
            • Then - Actions
              • Unit - Replace (Casting unit) with a Watch Tower using The old unit's relative life and mana
              • Unit - Replace (Random unit from GuardTower) with a Mazing Rock using The old unit's relative life and mana
              • Unit - Replace (Random unit from DeathTower) with a Mazing Rock using The old unit's relative life and mana
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Casting unit)) Equal to Death Tower
                • Then - Actions
                  • Unit - Replace (Casting unit) with a Watch Tower using The old unit's relative life and mana
                  • Unit - Replace (Random unit from ArcaneTower) with a Mazing Rock using The old unit's relative life and mana
                  • Unit - Replace (Random unit from GuardTower) with a Mazing Rock using The old unit's relative life and mana
                • Else - Actions
                  • Do nothing
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,703
So relying on Periodic triggers to keep track of things is one of the big "noob traps". What you want to do instead is track something the EXACT moment it's created or becomes "trackable". For example, with your structures you can keep start tracking them the exact moment that they come into existence:
  • Events
    • Unit - A unit Begins construction
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Guard Tower
      • Then - Actions
        • Set Variable Guard_Tower_Count = (Guard_Tower_Count + 1)
        • Unit Group - Add (Triggering unit) to Guard_Tower_Group
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Triggering unit)) Equal to Arcane Tower
          • Then - Actions
            • Set Variable Arcane_Tower_Count = (Arcane_Tower_Count + 1)
            • Unit Group - Add (Triggering unit) to Arcane_Tower_Group
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Unit-type of (Triggering unit)) Equal to Death Tower
              • Then - Actions
                • Set Variable Death_Tower_Count = (Death_Tower_Count + 1)
                • Unit Group - Add (Triggering unit) to Death_Tower_Group
              • Else - Actions
Then when a structure is destroyed you can stop tracking them:
  • Tower Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • -------- Track the dying unit if it's not tracked already --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Dying_Unit Equal to No unit
        • Then - Actions
          • Set Variable Dying_Unit = (Triggering unit)
        • Else - Actions
      • -------- Remove the dying unit from it's group --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of Dying_Unit) Equal to Guard Tower
        • Then - Actions
          • Set Variable Guard_Tower_Count = (Guard_Tower_Count - 1)
          • Unit Group - Remove Dying_Unit from Guard_Tower_Group
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of Dying_Unit) Equal to Arcane Tower
            • Then - Actions
              • Set Variable Arcane_Tower_Count = (Arcane_Tower_Count - 1)
              • Unit Group - Remove Dying_Unit from Arcane_Tower_Group
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of Dying_Unit) Equal to Death Tower
                • Then - Actions
                  • Set Variable Death_Tower_Count = (Death_Tower_Count - 1)
                  • Unit Group - Remove Dying_Unit from Death_Tower_Group
                • Else - Actions
      • -------- Reset the variable to allow the trigger to work again --------
      • Set Variable Dying_Unit = No unit
Now when it comes time to cast your ability you have all of the information you need readily available and it's much more efficient:
  • Watch Tower
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Watch Tower (Neutral Hostile)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Guard Tower
          • Arcane_Tower_Count Greater than 0
          • Death_Tower_Count Greater than 0
        • Then - Actions
          • -------- Replace the casting tower --------
          • Set Variable Dying_Tower = (Triggering unit)
          • Trigger - Run Tower Dies (ignoring conditions)
          • Unit - Replace Dying_Tower with a Watch Tower using The old unit's relative life and mana
          • -------- Replace the 1st of the other towers --------
          • Set Variable Dying_Tower = (Random unit from Arcane_Tower_Group)
          • Trigger - Run Tower Dies (ignoring conditions)
          • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
          • -------- Replace the 2nd of the other towers --------
          • Set Variable Dying_Tower = (Random unit from Death_Tower_Group)
          • Trigger - Run Tower Dies (ignoring conditions)
          • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Casting unit)) Equal to Arcane Tower
              • Guard_Tower_Count Greater than 0
              • Death_Tower_Count Greater than 0
            • Then - Actions
              • -------- Replace the casting tower --------
              • Set Variable Dying_Tower = (Triggering unit)
              • Trigger - Run Tower Dies (ignoring conditions)
              • Unit - Replace Dying_Tower with a Watch Tower using The old unit's relative life and mana
              • -------- Replace the 1st of the other towers --------
              • Set Variable Dying_Tower = (Random unit from Guard_Tower_Group)
              • Trigger - Run Tower Dies (ignoring conditions)
              • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
              • -------- Replace the 2nd of the other towers --------
              • Set Variable Dying_Tower = (Random unit from Death_Tower_Group)
              • Trigger - Run Tower Dies (ignoring conditions)
              • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Casting unit)) Equal to Death Tower
                  • Arcane_Tower_Count Greater than 0
                  • Guard_Tower_Count Greater than 0
                • Then - Actions
                  • -------- Replace the casting tower --------
                  • Set Variable Dying_Tower = (Triggering unit)
                  • Trigger - Run Tower Dies (ignoring conditions)
                  • Unit - Replace Dying_Tower with a Watch Tower using The old unit's relative life and mana
                  • -------- Replace the 1st of the other towers --------
                  • Set Variable Dying_Tower = (Random unit from Arcane_Tower_Group)
                  • Trigger - Run Tower Dies (ignoring conditions)
                  • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
                  • -------- Replace the 2nd of the other towers --------
                  • Set Variable Dying_Tower = (Random unit from Guard_Tower_Group)
                  • Trigger - Run Tower Dies (ignoring conditions)
                  • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
                • Else - Actions
Notes:
1) I'm using Integer variables to keep track of the number of units in your Unit Groups. This is because it's more efficient than using the (Number of units in group) function, which has to Loop over the entire group to count all of them. This is an optional optimization.

2) I need that funky Set Dying_Tower + Run Tower Dies stuff because the Replace Unit action doesn't actually Kill units, it REMOVES them. Unfortunately, there's no Event like "A unit Is removed from the game" or this would be an easy fix.

In other words, our Tower Dies trigger doesn't run when a Tower gets replaced which is why I'm manually forcing the trigger to run. You could definitely optimize this setup so that you don't need to do any of that, you just need to find a way to detect when a unit is Removed from the game. Here's one system that offers a custom Event for detecting that: GUI Unit Event.
 
Last edited:
Level 2
Joined
May 14, 2024
Messages
6
So relying on Periodic triggers to keep track of things is one of the big "noob traps". What you want to do instead is track something the EXACT moment it's created or becomes "trackable". For example, with your structures you can keep start tracking them the exact moment that they come into existence:
  • Events
    • Unit - A unit Begins construction
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Guard Tower
      • Then - Actions
        • Set Variable Guard_Tower_Count = (Guard_Tower_Count + 1)
        • Unit Group - Add (Triggering unit) to Guard_Tower_Group
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Triggering unit)) Equal to Arcane Tower
          • Then - Actions
            • Set Variable Arcane_Tower_Count = (Arcane_Tower_Count + 1)
            • Unit Group - Add (Triggering unit) to Arcane_Tower_Group
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Unit-type of (Triggering unit)) Equal to Death Tower
              • Then - Actions
                • Set Variable Death_Tower_Count = (Death_Tower_Count + 1)
                • Unit Group - Add (Triggering unit) to Death_Tower_Group
              • Else - Actions
Then when a structure is destroyed you can stop tracking them:
  • Tower Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • -------- Track the dying unit if it's not tracked already --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Dying_Unit Equal to No unit
        • Then - Actions
          • Set Variable Dying_Unit = (Triggering unit)
        • Else - Actions
      • -------- Remove the dying unit from it's group --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of Dying_Unit) Equal to Guard Tower
        • Then - Actions
          • Set Variable Guard_Tower_Count = (Guard_Tower_Count - 1)
          • Unit Group - Remove Dying_Unit from Guard_Tower_Group
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of Dying_Unit) Equal to Arcane Tower
            • Then - Actions
              • Set Variable Arcane_Tower_Count = (Arcane_Tower_Count - 1)
              • Unit Group - Remove Dying_Unit from Arcane_Tower_Group
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of Dying_Unit) Equal to Death Tower
                • Then - Actions
                  • Set Variable Death_Tower_Count = (Death_Tower_Count - 1)
                  • Unit Group - Remove Dying_Unit from Death_Tower_Group
                • Else - Actions
      • -------- Reset the variable to allow the trigger to work again --------
      • Set Variable Dying_Unit = No unit
Now when it comes time to cast your ability you have all of the information you need readily available and it's much more efficient:
  • Watch Tower
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Watch Tower (Neutral Hostile)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to Guard Tower
          • Arcane_Tower_Count Greater than 0
          • Death_Tower_Count Greater than 0
        • Then - Actions
          • -------- Replace the casting tower --------
          • Set Variable Dying_Tower = (Triggering unit)
          • Trigger - Run Tower Dies (ignoring conditions)
          • Unit - Replace Dying_Tower with a Watch Tower using The old unit's relative life and mana
          • -------- Replace the 1st of the other towers --------
          • Set Variable Dying_Tower = (Random unit from Arcane_Tower_Group)
          • Trigger - Run Tower Dies (ignoring conditions)
          • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
          • -------- Replace the 2nd of the other towers --------
          • Set Variable Dying_Tower = (Random unit from Death_Tower_Group)
          • Trigger - Run Tower Dies (ignoring conditions)
          • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Casting unit)) Equal to Arcane Tower
              • Guard_Tower_Count Greater than 0
              • Death_Tower_Count Greater than 0
            • Then - Actions
              • -------- Replace the casting tower --------
              • Set Variable Dying_Tower = (Triggering unit)
              • Trigger - Run Tower Dies (ignoring conditions)
              • Unit - Replace Dying_Tower with a Watch Tower using The old unit's relative life and mana
              • -------- Replace the 1st of the other towers --------
              • Set Variable Dying_Tower = (Random unit from Guard_Tower_Group)
              • Trigger - Run Tower Dies (ignoring conditions)
              • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
              • -------- Replace the 2nd of the other towers --------
              • Set Variable Dying_Tower = (Random unit from Death_Tower_Group)
              • Trigger - Run Tower Dies (ignoring conditions)
              • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Casting unit)) Equal to Death Tower
                  • Arcane_Tower_Count Greater than 0
                  • Guard_Tower_Count Greater than 0
                • Then - Actions
                  • -------- Replace the casting tower --------
                  • Set Variable Dying_Tower = (Triggering unit)
                  • Trigger - Run Tower Dies (ignoring conditions)
                  • Unit - Replace Dying_Tower with a Watch Tower using The old unit's relative life and mana
                  • -------- Replace the 1st of the other towers --------
                  • Set Variable Dying_Tower = (Random unit from Arcane_Tower_Group)
                  • Trigger - Run Tower Dies (ignoring conditions)
                  • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
                  • -------- Replace the 2nd of the other towers --------
                  • Set Variable Dying_Tower = (Random unit from Guard_Tower_Group)
                  • Trigger - Run Tower Dies (ignoring conditions)
                  • Unit - Replace Dying_Tower with a Mazing Rock using The old unit's relative life and mana
                • Else - Actions
Notes:
1) I'm using Integer variables to keep track of the number of units in your Unit Groups. This is because it's more efficient than using the (Number of units in group) function, which has to Loop over the entire group to count all of them. This is an optional optimization.

2) I need that funky Set Dying_Tower + Run Tower Dies stuff because the Replace Unit action doesn't actually Kill units, it REMOVES them. Unfortunately, there's no Event like "A unit Is removed from the game" or this would be an easy fix.

In other words, our Tower Dies trigger doesn't run when a Tower gets replaced which is why I'm manually forcing the trigger to run. You could definitely optimize this setup so that you don't need to do any of that, you just need to find a way to detect when a unit is Removed from the game. Here's one system that offers a custom Event for detecting that: GUI Unit Event.
Hi again, here is my current map
i like GEM TD play style so i tried to make it look like it as much as possible
 

Attachments

  • Replica Gem Td.w3m
    974.9 KB · Views: 3
Top