• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[General] 2 units share 1 life

Status
Not open for further replies.
Level 15
Joined
Sep 11, 2013
Messages
557
Greetings!
In my problem I have 2 units (buildings) one in top of another preplaced in the map and I wish to make an optimized trigger that can manages to make the life of one unit dependent on the life of the other unit.

Example:
Unit 1 = 1000 hp
Unit 2 = 1000 hp

Unit 1 is attacked by a random unit and now has 900 hp -> Unit 2 must have also 900 hp
Unit 2 is attacked by a random unit and now has 800 hp -> Unit 1 must have also 800 hp

I've made this trigger and works well, but I think is not optimized.
  • Events
    • Unit - A unit Takes damage
  • Conditions
    • (Damage Target) Equal to Unit 1
  • Actions
    • Wait 0.01 seconds
    • Unit - Set life of Unit 2 <gen> to (Life of (Damage Target))
  • Events
    • Unit - A unit Takes damage
  • Conditions
    • (Damage Target) Equal to Unit 2 <gen>
  • Actions
    • Wait 0.01 seconds
    • Unit - Set life of Unit 1 <gen> to (Life of (Damage Target))
If someone know a better solution, the help will be appreciated!




 
Hello Ativ! How you doing? I made another solution that deals damage instead of setting life.
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Unit[1] = Farm 0000 <gen>
      • Unit - Add Animate Dead to Unit[1]
      • Unit - Set level of Animate Dead for Unit[1] to 2
      • Set VariableSet Unit[2] = Farm 0001 <gen>
      • Unit - Add Animate Dead to Unit[2]
  • Untitled Trigger 002
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Level of Animate Dead for (Damage Target)) Greater than 0
    • Actions
      • Trigger - Turn off (This trigger)
      • Unit - Cause (Damage source) to damage Unit[(Level of Animate Dead for (Damage Target))], dealing (Damage taken) damage of attack type Chaos and damage type Universal
      • Trigger - Turn on (This trigger)
-A unique ability is used for the triggers condition and its level is used as an index to deal damage to the other one
-Trigger is turned off/on to prevent an infinite loop while dealing more damage
-Chaos usually deals 100% to all types while Universal ignores armor damage reduction



The reason you need a small wait in your solution is because the damage is applied a small instant after the damage event. An instant can be achieved by starting a timer at 0.00 seconds and doing actions when the timer expires. Your solution is probably a bit safer than to deal damage because of altercations that can occur with the damage amount, so heres how you can do that.
  • Untitled Trigger 002
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Level of Animate Dead for (Damage Target)) Greater than 0
    • Actions
      • Unit Group - Add (Damage Target) to Group
      • Countdown Timer - Start Timer as a One-shot timer that will expire in 0.00 seconds
  • Untitled Trigger 003
    • Events
      • Time - Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Group and do (Actions)
        • Loop - Actions
          • Unit - Set life of Unit[(Level of Animate Dead for (Picked unit))] to (Life of (Picked unit))
          • Unit Group - Remove (Picked unit) from Group.
EDIT: I ran some damage tests and it appears that the instant part causes issues with a lot of damage events. So dealing damage does seem better unless theres another solution. On dealing damage I dealt 10k damage to two 10k units whilst with the set life I dealt 12k damage to two 10k units.
 
Last edited:
Hello Ativ! How you doing? I made another solution that deals damage instead of setting life.
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Unit[1] = Farm 0000 <gen>
      • Unit - Add Animate Dead to Unit[1]
      • Unit - Set level of Animate Dead for Unit[1] to 2
      • Set VariableSet Unit[2] = Farm 0001 <gen>
      • Unit - Add Animate Dead to Unit[2]
  • Untitled Trigger 002
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Level of Animate Dead for (Damage Target)) Greater than 0
    • Actions
      • Trigger - Turn off (This trigger)
      • Unit - Cause (Damage source) to damage Unit[(Level of Animate Dead for (Damage Target))], dealing (Damage taken) damage of attack type Chaos and damage type Universal
      • Trigger - Turn on (This trigger)
-A unique ability is used for the triggers condition and its level is used as an index to deal damage to the other one
-Trigger is turned off/on to prevent an infinite loop while dealing more damage
-Chaos usually deals 100% to all types while Universal ignores armor damage reduction



The reason you need a small wait in your solution is because the damage is applied a small instant after the damage event. An instant can be achieved by starting a timer at 0.00 seconds and doing actions when the timer expires. Your solution is probably a bit safer than to deal damage because of altercations that can occur with the damage amount, so heres how you can do that.
  • Untitled Trigger 002
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Level of Animate Dead for (Damage Target)) Greater than 0
    • Actions
      • Unit Group - Add (Damage Target) to Group
      • Countdown Timer - Start Timer as a One-shot timer that will expire in 0.00 seconds
  • Untitled Trigger 003
    • Events
      • Time - Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Group and do (Actions)
        • Loop - Actions
          • Unit - Set life of Unit[(Level of Animate Dead for (Picked unit))] to (Life of (Picked unit))
          • Unit Group - Remove (Picked unit) from Group.
EDIT: I ran some damage tests and it appears that the instant part causes issues with a lot of damage events. So dealing damage does seem better unless theres another solution. On dealing damage I dealt 10k damage to two 10k units whilst with the set life I dealt 12k damage to two 10k units.
Hello Duck! I am doing fine, working on a new map! I hope you're doing great as well!
Thank you for your help, but I think there was a misunderstand because of my bad english.
I tried your suggestion, but work with only 1 building.. I want to work even in reverse. Right now works only if I attack farm 2.
In my example I've made 2 triggers for unit 1 and for unit 2, but i don't know how to adapt your trigger in order to work for both units.
Also, why you use this "Unit - Set level of Animate Dead for Unit[1] to 2" just for unit 1?
 
Hello Duck! I am doing fine, working on a new map! I hope you're doing great as well!
Thank you for your help, but I think there was a misunderstand because of my bad english.
I tried your suggestion, but work with only 1 building.. I want to work even in reverse. Right now works only if I attack farm 2.
In my example I've made 2 triggers for unit 1 and for unit 2, but i don't know how to adapt your trigger in order to work for both units.
Also, why you use this "Unit - Set level of Animate Dead for Unit[1] to 2" just for unit 1?
This condition, (Level of Animate Dead for (Damage Target)) Greater than 0, checks if the (Damage Target) has the ability Animate Dead. A level of 0 means that the unit doesnt have the ability and a level greater than 0 means that the unit has the ability. Unit[1] has the ability at level 2 and Unit[2] has the ability at level 1. We can therefore also use the Level of Animate Dead for (Damage Target) to reference the other unit. See the example below.

Unit[(Level of Animate Dead for (Unit[1]))] = Unit[2]
Unit[(Level of Animate Dead for (Unit[2]))] = Unit[1]
  • Unit - Cause (Damage source) to damage Unit[(Level of Animate Dead for (Damage Target))], dealing (Damage taken) damage of attack type Chaos and damage type Universal
The problem that happened for you is probably because the example ability Animate Dead that i chose usually only has 1 level so it cant be set to level 2. I would create a custom version of Item Armor Bonus (+1), set the Defense Bonus to 0 and set Levels to 2 and use that ability instead. The reason I would use that ability is because its not active and it doesnt show an interface icon when added to the units.
 
You were right. The problem disappears if I set the "animate dead" spell in the ability editor to level 3 for example.
Thank you!

Edit: Now I understand.. Unit[(Level of Animate Dead for (Damage Target))] is actually an integer Unit[1 or 2].
 
Last edited:
Status
Not open for further replies.
Back
Top