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

Trigger when Unit attacks

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
unit - unit is attacked....

are you sure you have the skills to be making a map? you really shouldnt jump into it too fast but make several smaller projects
 
Level 14
Joined
Jul 12, 2011
Messages
1,370
Here you are
  • Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Footman
    • Actions
There is no Attacked unit. You can do it only that way.:goblin_good_job:

Thers also this:
  • Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacked unit)) Equal to Footman
    • Actions
 
Level 9
Joined
Sep 15, 2012
Messages
311
... or do I use the "Unit is attacked" type of Event and then refer to the attacking unit?

... and if so will this check EVERY time the unit is attack or only the engage at the start of the combat?

Ah I was too slow it seems. :)
 
Last edited by a moderator:
Level 19
Joined
Aug 8, 2007
Messages
2,765
... or do I use the "Unit is attacked" type of Event and then refer to the attacking unit?

... and if so will this check EVERY time the unit is attack or only the engage at the start of the combat?

every time a missile is fired. and i dont get your first question at all
 
Level 9
Joined
Sep 15, 2012
Messages
311
Similar topic: I noticed that there is only Specific Unit - Takes damage trigger. Is there a way to ue the Take Damage event to Generic Unit?
Example: I want to create a trigger that heals a unit (not specific) when it takes damage and when it has a specific buff.
 
Level 4
Joined
Dec 12, 2012
Messages
96
So when the unit attacks, it has a chance to heal, right?

But you need to give more info abt this:

(1)How much probability/chances are we talking about here? Like 10%, 20% or 30%, etc.?
(2)How is it possible to the attacker to be healed? Does he have a skill that heals? Does he carry an item? Or by buff/effect?

If heal is by chance, here's a sample trigger:

1st Trigger - Set the Unit targeted of heal
  • Set autoheal unit
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set Autoheal_unit = Paladin 0000 <gen>
2nd Trigger - 10% chance to heal the Unit
  • Unit Attacks
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Autoheal_unit
    • Actions
      • Set Chance_to_Heal = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 1
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions

Or if let's say 30%

2nd Trigger


  • Unit Attacks Copy
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Autoheal_unit
    • Actions
      • Set Chance_to_Heal = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 1
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 2
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 3
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
So when the unit attacks, it has a chance to heal, right?

But you need to give more info abt this:

(1)How much probability/chances are we talking about here? Like 10%, 20% or 30%, etc.?
(2)How is it possible to the attacker to be healed? Does he have a skill that heals? Does he carry an item? Or by buff/effect?

If heal is by chance, here's a sample trigger:

1st Trigger - Set the Unit targeted of heal
  • Set autoheal unit
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set Autoheal_unit = Paladin 0000 <gen>
2nd Trigger - 10% chance to heal the Unit
  • Unit Attacks
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Autoheal_unit
    • Actions
      • Set Chance_to_Heal = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 1
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions

Or if let's say 30%

2nd Trigger


  • Unit Attacks Copy
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Autoheal_unit
    • Actions
      • Set Chance_to_Heal = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 1
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 2
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Equal to 3
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions

Random Int between 1 and 100 Less than or equal to (whatever % chance you want) would be the proper condition.
 
Level 4
Joined
Dec 12, 2012
Messages
96
Random Int between 1 and 100 Less than or equal to (whatever % chance you want) would be the proper condition.

You're right,

Simpler trigger with 30% chance of heal
  • Unit Attacks Copy
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Autoheal_unit
    • Actions
      • Set Chance_to_Heal = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Less than or equal to 3
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
You're right,

Simpler trigger with 30% chance of heal
  • Unit Attacks Copy
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Autoheal_unit
    • Actions
      • Set Chance_to_Heal = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance_to_Heal Less than or equal to 3
        • Then - Actions
          • Unit - Set life of Autoheal_unit to ((Life of Autoheal_unit) + 250.00)
        • Else - Actions

rada is right, but its still nicer API to do 1-100 because its not a 3% chance its a 30% chance
 
Level 9
Joined
Sep 15, 2012
Messages
311
Thnx for the replies. I should have given more info.
I planned an ability called Sadism: When active, the unit will heal for 75% of the damage recieved.
I created an ability that does nothing and only gives a buff.
So I want to make it that when that buff is active and the unit is damaged it heals a portion of the damage recieved.
I don't want to make the unit heal when it's attacked. I want it to heal when it gets damaged. The only Event reffering to this is "Specific Unit Event" but this means the unit has to be in the map from the beggining.
If I use "Generic Unit Event - Unit is attacked" and in the Actions put "Set Unit life to Current Unit Life + (0.75 x Damage taken)", will it work? Or is this working only for "Unit takes Damage" Event?
 
Level 4
Joined
Dec 12, 2012
Messages
96
I don't want to make the unit heal when it's attacked. I want it to heal when it gets damaged. The only Event reffering to this is "Specific Unit Event" but this means the unit has to be in the map from the beggining.
If I use "Generic Unit Event - Unit is attacked" and in the Actions put "Set Unit life to Current Unit Life + (0.75 x Damage taken)", will it work? Or is this working only for "Unit takes Damage" Event?

Though the trigger will activate because of Unit is Attacked, the action Set Unit Life however won't work. It hasn't verified that the unit has received the attack, because Unit is Attacked activates when only the unit starts the animation and hasn't hit the target yet. So therefore, the damage taken is not read.

Based from the description of your skill, I made you a sample trigger and a test map. Here, the attacked unit has 75% chance of heal when he has the buff Inner Fire.


  • set unit
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set Sadism_Hero = Paladin 0000 <gen>
  • Activate Sadism
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Trigger - Add to Sadism <gen> the event (Unit - (Attacked unit) Takes damage)

  • Sadism
    • Events
    • Conditions
      • (Attacked unit) Equal to Sadism_Hero
      • (Sadism_Hero has buff Inner Fire) Equal to True
    • Actions
      • Set Damage_Inflicted = (Damage taken)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 75
        • Then - Actions
          • Unit - Set life of Sadism_Hero to ((Life of Sadism_Hero) + (Damage_Inflicted + 15.00))
          • Special Effect - Create a special effect attached to the overhead of Sadism_Hero using Abilities\Spells\Human\Heal\HealTarget.mdl
        • Else - Actions
 

Attachments

  • Sadism.w3x
    17.3 KB · Views: 42
Level 19
Joined
Aug 8, 2007
Messages
2,765
Though the trigger will activate because of Unit is Attacked, the action Set Unit Life however won't work. It hasn't verified that the unit has received the attack, because Unit is Attacked activates when only the unit starts the animation and hasn't hit the target yet. So therefore, the damage taken is not read.

Based from the description of your skill, I made you a sample trigger and a test map. Here, the attacked unit has 75% chance of heal when he has the buff Inner Fire.


  • set unit
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set Sadism_Hero = Paladin 0000 <gen>
  • Activate Sadism
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Trigger - Add to Sadism <gen> the event (Unit - (Attacked unit) Takes damage)

  • Sadism
    • Events
    • Conditions
      • (Attacked unit) Equal to Sadism_Hero
      • (Sadism_Hero has buff Inner Fire) Equal to True
    • Actions
      • Set Damage_Inflicted = (Damage taken)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 75
        • Then - Actions
          • Unit - Set life of Sadism_Hero to ((Life of Sadism_Hero) + (Damage_Inflicted + 15.00))
          • Special Effect - Create a special effect attached to the overhead of Sadism_Hero using Abilities\Spells\Human\Heal\HealTarget.mdl
        • Else - Actions

leave this to people that know what theyre doing, thanks. this leaks THOUSANDS of times... one for every unit on the map and another for every time a unit takes damage and again every time a unit attacks. use the link i posted -_-
 
Level 4
Joined
Dec 12, 2012
Messages
96
I'm just SHARING my idea, i'm not telling anyone to CHOOSE mine. It does leak with the special effects, it keeps adding up. But would you care to tell me why does this leak? I had set the specific unit into variable and i think my conditions are precise but since you say it's leaking, I don't have any idea how and why.
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
I'm just SHARING my idea, i'm not telling anyone to CHOOSE mine. It does leak with the special effects, it keeps adding up. But would you care to tell me why does this leak? I had set the specific unit into variable and i think my conditions are precise but since you say it's leaking, I don't have any idea how and why.

this
  • Unit - A unit Is attacked
will be applied to all units on the map. everytime they get attacked, another event will be created
  • Trigger - Add to Sadism <gen> the event (Unit - (Attacked unit) Takes damage)
which will leaks when the unit dies.

and (Attacked unit) = (Triggering unit) for faster process.
----------------------------------------------------------------------------------------------------
@Valenvai
here is a test map.

it checks whenever the damaged unit has a buff of Sadism, therefore, 75 % of damage inflicted will be healed.
 

Attachments

  • Sadism.w3x
    28.8 KB · Views: 62
Last edited:
Level 4
Joined
Dec 12, 2012
Messages
96
this
  • Unit - A unit Is attacked
will be applied to all units on the map. everytime they get attacked, another event will be created
  • Trigger - Add to Sadism <gen> the event (Unit - (Attacked unit) Takes damage)
which will leaks when the unit dies.

and (Attacked unit) = (Triggering unit) for faster process.

Shouldn't the condition "attacked unit" clears up the leaks? I kinda feel the need to understand how these leaks occur so I can create more appropriate triggers.
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
Shouldn't the condition "attacked unit" clears up the leaks? I kinda feel the need to understand how these leaks occur so I can create more appropriate triggers.

as Arhowk told you, the most appropriate triggers are using Damage Engine.

  • Sadism
    • Events
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Conditions
      • (Attacked unit) Equal to Sadism_Hero
      • (Sadism_Hero has buff Inner Fire) Equal to True
    • Actions
      • Set Damage_Inflicted = (Damage taken)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 75
        • Then - Actions
          • Unit - Set life of Sadism_Hero to ((Life of Sadism_Hero) + (Damage_Inflicted + 15.00))
          • Special Effect - Create a special effect attached to the overhead of Sadism_Hero using Abilities\Spells\Human\Heal\HealTarget.mdl
        • Else - Actions
you see how much events you will add everytime a unit is attacked. and it keeps repeating the whole time until the game ends.
 
Level 4
Joined
Dec 12, 2012
Messages
96
as Arhowk told you, the most appropriate triggers are using Damage Engine.

Yes, I know it fits well to any type of damage system. It's just that leaks puzzle me. If I know how they can occur, I might be able to fix and improve my map. :) Thanks anyway.


  • Sadism
    • Events
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Unit - Attacked unit takes damage
    • Conditions
      • (Attacked unit) Equal to Sadism_Hero
      • (Sadism_Hero has buff Inner Fire) Equal to True
    • Actions
      • Set Damage_Inflicted = (Damage taken)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 75
        • Then - Actions
          • Unit - Set life of Sadism_Hero to ((Life of Sadism_Hero) + (Damage_Inflicted + 15.00))
          • Special Effect - Create a special effect attached to the overhead of Sadism_Hero using Abilities\Spells\Human\Heal\HealTarget.mdl
        • Else - Actions
you see how much events you will add everytime a unit is attacked. and it keeps repeating the whole time until the game ends.

Aaah, so that's why some functions like special effects keep on adding up whenever the attack occurs. What can you suggest to make the event happen only once? Sry for lot of questions
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
this is very abusable because this event fires as soon as you start your attack animation
if I had 1% life and just spam right click on unit, stop I would heal to full in no time
you should rather use DDS which arhowk posted
 
Status
Not open for further replies.
Top