• 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.

Trying to right a code where I evenly distribute dmg

Status
Not open for further replies.
Level 5
Joined
Aug 8, 2008
Messages
113
How do I get between 1 - 30 units without adding 30 if then else then statements which that process usually doesnt work for me anyhow?

O let me explain what im trying to do... basically im trying to make an item that even distributes damage

  • Stat Aura
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Triggering unit) belongs to an ally of Player 1 (Red)) Equal to True
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • 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
              • (Number of units in (Units in (Playable map area))) Equal to 5
            • Then - Actions
              • Set DT = (Damage taken)
              • Set unts = (Number of units in (Units in (Playable map area)))
              • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
              • Special Effect - Destroy (Last created special effect)
              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 5.00))
            • Else - Actions
 
Level 5
Joined
Aug 8, 2008
Messages
113
Its suppose to keep you and your allies alive longer by lessening the damage on 1 unit and distributing it to all the others

so if 1 unit takes 500 damage I want the allies to receive 24% of that damage but spread it out so instead of each ally receiving 120 damage they all receive 24 and the original hero receives 380 damage.

edit:And its just nearby allies not all allies on the map
 
Level 5
Joined
Aug 8, 2008
Messages
113
So I was wondering why does the if then else then in jass put the conditions in seperate functions?
 
Also thought I should point out, that if you want to evenly distribute damage and there to be a recognised source you'll need to make the triggering unit deal damage to the units, with the formula

(DT*0.24)/Number of units

I say this, because with "setting life" it ignores armour of units, however also does not give a damage source, and thus no gold if you actually kill an enemy unit doing so, or EXP, or anything else you get if you normally kill a unit, don't know if that's what you -want- but I figure that's pretty important to note if you haven't already noted it.
 
Level 5
Joined
Aug 8, 2008
Messages
113
I want to point out that my code isn't working I've tried to things Pickeed unit and Triggering unit and also the special effects are not even starting up.
  • Distribution
    • Events
    • Conditions
      • ((Triggering unit) belongs to an ally of Player 1 (Red)) Equal to True
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) has buff Stat Aura ) Equal to True
        • Then - Actions
          • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / udg_unts ) ) )
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - ((DT x 0.24) / 1.00))
          • Custom script: call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) - ( ( udg_DT * 0.24 ) / udg_unts ) ) )
          • Set unts = ((Number of players in (All players matching (((Picked unit) has buff Stat Aura ) Equal to True))) - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • unts Equal to 0
            • Then - Actions
              • Set Variable = (Units currently selected by (Picked player))
              • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
              • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
            • Else - Actions
              • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
              • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
        • Else - Actions
          • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
          • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
      • 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
              • ((Triggering unit) has buff Stat Aura ) Equal to True
            • Then - Actions
              • Set unts = ((Number of units in (Units in (Playable map area))) - 1)
              • Set DT = (Damage taken)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • unts Equal to 0
                • Then - Actions
                  • Set Variable = (Units currently selected by (Picked player))
                  • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                  • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                  • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                  • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 1.00 ) ) )
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • unts Equal to 1
                    • Then - Actions
                      • Set Variable = (Units currently selected by (Picked player))
                      • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                      • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                      • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                      • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 1.00 ) ) )
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • unts Equal to 2
                        • Then - Actions
                          • Set Variable = (Units currently selected by (Picked player))
                          • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                          • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                          • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 2.00 ) ) )
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • unts Equal to 3
                            • Then - Actions
                              • Set Variable = (Units currently selected by (Picked player))
                              • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                              • Special Effect - Destroy (Last created special effect)
                              • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                              • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                              • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 3.00 ) ) )
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • unts Equal to 4
                                • Then - Actions
                                  • Set Variable = (Units currently selected by (Picked player))
                                  • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                  • Special Effect - Destroy (Last created special effect)
                                  • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                  • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                  • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                  • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 4.00 ) ) )
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • unts Equal to 5
                                    • Then - Actions
                                      • Set Variable = (Units currently selected by (Picked player))
                                      • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                      • Special Effect - Destroy (Last created special effect)
                                      • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                      • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                      • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                      • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 5.00 ) ) )
                                    • Else - Actions
                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        • If - Conditions
                                          • unts Equal to 6
                                        • Then - Actions
                                          • Set Variable = (Units currently selected by (Picked player))
                                          • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                          • Special Effect - Destroy (Last created special effect)
                                          • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                          • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                          • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 6.00 ) ) )
                                        • Else - Actions
                                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                            • If - Conditions
                                              • unts Equal to 7
                                            • Then - Actions
                                              • Set Variable = (Units currently selected by (Picked player))
                                              • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                              • Special Effect - Destroy (Last created special effect)
                                              • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                              • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                              • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 7.00 ) ) )
                                            • Else - Actions
                                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                • If - Conditions
                                                  • unts Equal to 8
                                                • Then - Actions
                                                  • Set Variable = (Units currently selected by (Picked player))
                                                  • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                                  • Special Effect - Destroy (Last created special effect)
                                                  • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                                  • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                                  • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                                  • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 8.00 ) ) )
                                                • Else - Actions
                                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                    • If - Conditions
                                                      • unts Equal to 9
                                                    • Then - Actions
                                                      • Set Variable = (Units currently selected by (Picked player))
                                                      • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                                      • Special Effect - Destroy (Last created special effect)
                                                      • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                                      • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                                      • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                                      • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 9.00 ) ) )
                                                    • Else - Actions
                                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                        • If - Conditions
                                                          • unts Equal to 10
                                                        • Then - Actions
                                                          • Set Variable = (Units currently selected by (Picked player))
                                                          • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Undead\CarrionSwarm\CarrionSwarmDamage.mdl
                                                          • Special Effect - Destroy (Last created special effect)
                                                          • Unit - Add Item Hero Stat Bonus (+2 All Stats) to (Picked unit)
                                                          • Unit - Add Item Hero Stat Bonus (+4 Intelligence) to (Picked unit)
                                                          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - ((DT x 0.24) / 1.00))
                                                          • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( udg_DT * 0.24 ) / 10.00 ) ) )
                                                        • Else - Actions
                                                          • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                                          • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                                                      • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                                      • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                                                  • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                                  • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                                              • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                              • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                                          • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                          • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                                      • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                      • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                                  • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                                  • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                              • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                              • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                          • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                          • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                      • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                      • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
                  • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
                  • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
            • Else - Actions
              • Unit - Remove Item Hero Stat Bonus (+4 Intelligence) from (Picked unit)
              • Unit - Remove Item Hero Stat Bonus (+2 All Stats) from (Picked unit)
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Trigger - Add to Distribution <gen> the event (Unit - (Picked unit) Takes damage)
  • Stat Aura
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Triggering unit) Equal to (Attacked unit)
      • ((Triggering unit) belongs to an ally of Player 1 (Red)) Equal to True
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has buff Stat Aura ) Equal to True
        • Then - Actions
          • Set DT = (Damage taken)
          • Custom script: call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) + ( ( udg_DT * 0.24 ) ) ) )
        • Else - Actions
[Edit]All stats are for another suggestion I never took them out I just disabled them [edit]

Also thought I should point out, that if you want to evenly distribute damage and there to be a recognised source you'll need to make the triggering unit deal damage to the units, with the formula

(DT*0.24)/Number of units

I say this, because with "setting life" it ignores armour of units, however also does not give a damage source, and thus no gold if you actually kill an enemy unit doing so, or EXP, or anything else you get if you normally kill a unit, don't know if that's what you -want- but I figure that's pretty important to note if you haven't already noted it.
I really dont know what im doing how would I even do that? Thanks for the suggestion
 
Level 5
Joined
Aug 8, 2008
Messages
113
new script not workin
  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • 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
              • (Owner of (Attacking unit)) Equal to Player 2 (Blue)
              • ((Attacked unit) belongs to an ally of (Owner of Cloak of the Sisterhood 0004 <gen>)) Equal to True
            • Then - Actions
              • Set unit = (Attacking unit)
              • Set unit3 = (Attacked unit)
            • Else - Actions
  • Untitled Trigger 001 Copy 2
    • Events
      • Unit - A unit owned by Player 1 (Red) Is attacked
    • Conditions
    • 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
              • (Owner of (Attacking unit)) Equal to Player 2 (Blue)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (unit3 is in (Units in (Playable map area))) Equal to True
                • Then - Actions
                  • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Custom script: call UnitDamagePointLoc( udg_unit, 0.01, 900.00, GetRectCenter(GetPlayableMapRect()), ( ( udg_DT * 0.24 ) / udg_unts ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
                  • Unit - Cause unit to damage circular area after 0.01 seconds of radius 900.00 at (Center of (Playable map area)), dealing ((DT x 0.24) / 3.00) damage of attack type Spells and damage type Normal
                • Else - Actions
            • Else - Actions
  • Untitled Trigger 001 Copy
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • 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
              • ((Picked unit) has buff Stat Aura ) Equal to True
            • Then - Actions
              • Set unts = ((Number of players in (All players matching (((Picked unit) has buff Stat Aura ) Equal to True))) - 1)
              • Set unit2 = (Units in (Playable map area) owned by Player 1 (Red))
              • Set DT = (Damage taken)
            • Else - Actions
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
You're using the wrong event. Unit - Unit is Attacked triggers when a unit begins an attack (as animation starts), so the Event Response - Damage Taken variable isn't set, and is thus 0.

If you're using WEU, there is an event that captures units taking damage.

If you're a pleb like me, you need another trigger to add the events; make a trigger that picks every unit at the start of the map, and adds an event to the other trigger: Unit (specific event) - Picked unit takes damage.

Also, have you considered using Spirit Link (the in-game ability for Spirit Walkers) instead of triggers?
 
Status
Not open for further replies.
Top