• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to set base damage back to normal

Status
Not open for further replies.
Level 7
Joined
Feb 23, 2020
Messages
253
Hello, i have an ability based of "War Club", with these triggers
  • Pick up Tree
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Pick up Tree
    • Actions
      • Unit - Set Base Damage of (Triggering unit) to (Integer(((Real((Base Damage of (Triggering unit) for weapon index 0))) + (Armor of (Triggering unit))))) for weapon index: 0
The spell works just fine, but its supposed to only last for X attacks, I.E Level 1: 5, level 2: 6. etc.

My question is, how do i set the units base damage back to its ordinary base damage
 
Level 5
Joined
Jun 12, 2018
Messages
148
You have to set a real variable when the spell is casted for the first time and an integer variable that will count the number of attacks done by your unit.

Once you've reached the X max attacks for your spell, just revert the base damage to the original value saved in your real variable.

I'd suggest you to create a unit group and add the units after they casted the spell, then use "Unit - Is attacked" event to iterate over your unit group and do your actions. Unit has to be removed from this group when it has used his last buffed attack.

If this spell is MUI (which means it can be casted by several units at the same time), I'd recommend to use a unit indexer library (like this one). You could then use then something like this :
  • Unit - Set Base Damage of MY_UNIT to ORIGINAL_BASE_DAMAGE[(Custom value of (MY_UNIT)] for weapon index: 0
ORIGINAL_BASE_DAMAGE is the real array I'd use to store units base damage just before they use your "Pick up tree" spell.
 
Level 7
Joined
Feb 23, 2020
Messages
253
You have to set a real variable when the spell is casted for the first time and an integer variable that will count the number of attacks done by your unit.

Once you've reached the X max attacks for your spell, just revert the base damage to the original value saved in your real variable.

I'd suggest you to create a unit group and add the units after they casted the spell, then use "Unit - Is attacked" event to iterate over your unit group and do your actions. Unit has to be removed from this group when it has used his last buffed attack.

If this spell is MUI (which means it can be casted by several units at the same time), I'd recommend to use a unit indexer library (like this one). You could then use then something like this :
  • Unit - Set Base Damage of MY_UNIT to ORIGINAL_BASE_DAMAGE[(Custom value of (MY_UNIT)] for weapon index: 0
ORIGINAL_BASE_DAMAGE is the real array I'd use to store units base damage just before they use your "Pick up tree" spell.

This sounds about correct i guess, but i'm kind of a rookie at triggers, still learning it. How do i make these triggers the easiest way possible? Difficult for me to understand every part of your explaination :p
 
Level 5
Joined
Jun 12, 2018
Messages
148
I did something very simple with 4 global variables for you to understand the logic behind. There are 2 triggers needed : one will be executed when a unit casts the spell and the other when the caster attacks.

Unit ability cast trigger
  • Unit cast ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Pick up tree
    • Actions
      • -------- Initiates the variables to keep a track of the values we need when all attacks are consumed --------
      • Set VariableSet Caster = (Triggering unit)
      • Set VariableSet OriginalCasterDamage = (Base Damage of (Triggering unit) for weapon index 0)
      • Set VariableSet AttacksCount = 0
      • Set VariableSet MaxAttacks = ((Level of Pick up tree for (Triggering unit)) x 2)
      • -------- Increases caster base damage --------
      • Unit - Set Base Damage of (Triggering unit) to ((Base Damage of (Triggering unit) for weapon index 0) + (Integer((Armor of (Triggering unit))))) for weapon index: 0
      • -------- Turn on the trigger which is off by default to count the number of attacks our caster will do --------
      • Trigger - Turn on Unit attacks count <gen>
Unit attacks count trigger
  • Unit attacks count
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Caster
    • Actions
      • Set VariableSet AttacksCount = (AttacksCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AttacksCount Greater than or equal to MaxAttacks
        • Then - Actions
          • -------- All our attacks have been done we can revert caster's base damage to original --------
          • Unit - Set Base Damage of Caster to OriginalCasterDamage for weapon index: 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
Note that this will work for only one unit at once, what if another unit uses the same spell while our first caster has not used all his buffed attacks ? A mess.

That's why I recommended you to use a unit indexer if you got multiple instances for the spell running at the same time or for other future spells you will develop. You just have to import it, change your variables to array type (check screenshot provided) and get/set your values like shown :
  • Set VariableSet AttacksCount[(Custom value of (Triggering unit))] = 0
 

Attachments

  • SwitchToMUI.png
    SwitchToMUI.png
    11.5 KB · Views: 26

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,195
It is important that you store the difference in base damage and not the actual base damage. This is because other sources could modify the base damage while the ability is active which could result in the unit being reverted to the incorrect base damage value. Storing the delta means you can subtract the delta from the current base damage to get the correct base damage irrespective of what else modified it.
 
Level 7
Joined
Feb 23, 2020
Messages
253
I did something very simple with 4 global variables for you to understand the logic behind. There are 2 triggers needed : one will be executed when a unit casts the spell and the other when the caster attacks.

Unit ability cast trigger
  • Unit cast ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Pick up tree
    • Actions
      • -------- Initiates the variables to keep a track of the values we need when all attacks are consumed --------
      • Set VariableSet Caster = (Triggering unit)
      • Set VariableSet OriginalCasterDamage = (Base Damage of (Triggering unit) for weapon index 0)
      • Set VariableSet AttacksCount = 0
      • Set VariableSet MaxAttacks = ((Level of Pick up tree for (Triggering unit)) x 2)
      • -------- Increases caster base damage --------
      • Unit - Set Base Damage of (Triggering unit) to ((Base Damage of (Triggering unit) for weapon index 0) + (Integer((Armor of (Triggering unit))))) for weapon index: 0
      • -------- Turn on the trigger which is off by default to count the number of attacks our caster will do --------
      • Trigger - Turn on Unit attacks count <gen>
Unit attacks count trigger
  • Unit attacks count
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Caster
    • Actions
      • Set VariableSet AttacksCount = (AttacksCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AttacksCount Greater than or equal to MaxAttacks
        • Then - Actions
          • -------- All our attacks have been done we can revert caster's base damage to original --------
          • Unit - Set Base Damage of Caster to OriginalCasterDamage for weapon index: 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
Note that this will work for only one unit at once, what if another unit uses the same spell while our first caster has not used all his buffed attacks ? A mess.

That's why I recommended you to use a unit indexer if you got multiple instances for the spell running at the same time or for other future spells you will develop. You just have to import it, change your variables to array type (check screenshot provided) and get/set your values like shown :
  • Set VariableSet AttacksCount[(Custom value of (Triggering unit))] = 0

So it should look something like this? (Included the MUI)
  • Unit cast ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Pick up Tree
    • Actions
      • Set VariableSet Golem_Caster = (Triggering unit)
      • Set VariableSet Golem_OriginalBase = (Base Damage of (Triggering unit) for weapon index 0)
      • Set VariableSet AttacksCount[(Custom value of (Triggering unit))] = 0
      • Set VariableSet Golem_MaxAttacks = ((Level of Pick up Tree for (Triggering unit)) x 2)
      • Unit - Set Base Damage of (Triggering unit) to (Integer(((Real((Base Damage of (Triggering unit) for weapon index 0))) + (Armor of (Triggering unit))))) for weapon index: 0
      • Trigger - Turn on Unit attacks count <gen>
  • Unit attacks count
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Attacking unit) Equal to Golem_Caster
    • Actions
      • Set VariableSet AttacksCount[(Custom value of (Triggering unit))] = (AttacksCount[(Custom value of (Triggering unit))] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AttacksCount[(Custom value of (Triggering unit))] Greater than or equal to Golem_MaxAttacks
        • Then - Actions
          • Unit - Set Base Damage of Golem_Caster to Golem_OriginalBase for weapon index: 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
It works properly the first time of use, but the second use its like the ability forgets how many attacks is allowed before it sets back to its original base. Works only for one auto attack. Thanks a lot for the help! :)

Note: The ability is supposed to have 5-13(from level 1-9) attacks before getting back to its normal base.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
A unit is attacked is a crappy Event as well. It suffers the same issues as "begins casting an ability".

You want to use a Damage Engine or use the new Damage Events. I recommend Bribe's Damage Engine as it's GUI friendly and all of the work is already done for you.

So with the Damage Engine the trigger would only ever run when damage is taken.

And for the 5-13 math, some simple arithmetic.
  • Set Variable AttacksCount = (4 + (1 x (Level of (Ability being cast) for (Triggering unit))))
Also, to debug it, display a text message in each trigger after adjusting AttacksCount:
  • Game - Display to (All players) for 30.00 seconds the text: (String(AttacksCount))
^ Convert Integer to String
 
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
A unit is attacked is a crappy Event as well. It suffers the same issues as "begins casting an ability".

You want to use a Damage Engine or use the new Damage Events. I recommend Bribe's Damage Engine as it's GUI friendly and all of the work is already done for you.

So with the Damage Engine the trigger would only ever run when damage is taken.

And for the 5-13 math, some simple arithmetic.
  • Set Variable AttacksCount = (4 + (1 x (Level of (Ability being cast) for (Triggering unit))))
Also, to debug it, display a text message in each trigger after adjusting AttacksCount:
  • Game - Display to (All players) for 30.00 seconds the text: (String(AttacksCount))
^ Convert Integer to String

The math and debug thing worked pretty nice, thank you! Seems like the attackcounter doesnt reset. Cant seem to find the problem to fix that :/

EDIT: I managed to find and fix the issue. :) Thank you all for the help!
 
Status
Not open for further replies.
Top