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

[Solved] Damage failing inside unit group with loop for each integer from 1 to 10

Status
Not open for further replies.
Level 12
Joined
Feb 5, 2018
Messages
521
  • Wave of Ice
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Wave Of Ice (Text not done)
    • Actions
      • -------- >>>Locals<<< --------
      • Custom script: local unit udg_WOI_Caster
      • Custom script: local player udg_WOI_Player
      • Custom script: local integer udg_WOI_Level = 0
      • Custom script: local integer udg_WOI_Integer = 1
      • Custom script: local real udg_WOI_Angle = 0.00
      • Custom script: local real WOI_Offset = 0.00
      • -------- ----------- --------
      • Custom script: set udg_WOI_Caster = GetTriggerUnit()
      • Custom script: set udg_WOI_Player = GetOwningPlayer(udg_WOI_Caster)
      • Custom script: set udg_WOI_Level = GetUnitAbilityLevelSwapped('A01D', udg_WOI_Caster)
      • Set VariableSet WOI_Loc1 = (Position of WOI_Caster)
      • Set VariableSet WOI_Loc2 = (Target point of ability being cast)
      • Set VariableSet WOI_Angle = (Angle from WOI_Loc1 to WOI_Loc2)
      • For each (Integer WOI_Integer) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set VariableSet WOI_Offset = (WOI_Offset + 48.00)
          • Set VariableSet WOI_Loc3 = (WOI_Loc1 offset by (48.00 + WOI_Offset) towards WOI_Angle degrees.)
          • Special Effect - Create a special effect at WOI_Loc3 using Abilities\Spells\Undead\FrostNova\FrostNovaTarget.mdl
          • Set VariableSet WOI_SFX[WOI_Integer] = (Last created special effect)
          • Special Effect - Destroy WOI_SFX[WOI_Integer]
          • Custom script: set bj_wantDestroyGroup = true
          • Set VariableSet WOI_DamageGroup = (Units within 125.00 of WOI_Loc3 matching ((((Matching unit) is dead) Equal to False) and (((Matching unit) belongs to an enemy of WOI_Player.) Equal to True)).)
          • Unit Group - Pick every unit in WOI_DamageGroup and do (Actions)
            • Loop - Actions
              • Unit - Cause WOI_Caster to damage (Picked unit), dealing 75.00 damage of attack type Spells and damage type Magic
          • Custom script: call RemoveLocation (udg_WOI_Loc3)
      • Custom script: call RemoveLocation (udg_WOI_Loc1)
      • Custom script: call RemoveLocation (udg_WOI_Loc2)
      • Set VariableSet WOI_Offset = 0.00
 
Level 12
Joined
Dec 11, 2014
Messages
662
Did you try using
  • Set VariableSet WOI_DamageGroup = (Units within 125.00 of WOI_Loc3)
And then checking for dead/enemy in an if/then/else loop, instead of all of it being in
  • Set VariableSet WOI_DamageGroup = (Units within 125.00 of WOI_Loc3 matching ((((Matching unit) is dead) Equal to False) and (((Matching unit) belongs to an enemy of WOI_Player.) Equal to True)).)
 
Level 12
Joined
Feb 5, 2018
Messages
521
  • Set VariableSet WOI_DamageGroup = (Units within 125.00 of WOI_Loc3.)
  • Unit Group - Pick every unit in WOI_DamageGroup and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) is A structure) Equal to False
          • ((Picked unit) is Magic Immune) Equal to False
          • ((Picked unit) is dead) Equal to False
          • ((Picked unit) is Mechanical) Equal to False
          • ((Picked unit) belongs to an enemy of (Owner of WOI_Caster).) Equal to True
        • Then - Actions
          • Unit - Cause WOI_Caster to damage (Picked unit), dealing WOI_Damage damage of attack type Spells and damage type Magic
        • Else - Actions
Didn't work.
 
Local shadowing that is a powerful but dangerous technique.
The Actions inside the Group Loop can not reach the local udg_WOI_Caster cause that happens in another function. The same applies for the Filter used in the Group with WOI_Player aswell for conditions inside an if.
It will read the Global variable whatever it was set to before that trigger happens.

One can not see that in the GUI Trigger. If you wana see what I mean you have to look at the resulting jass code. Clone your trigger and convert it to custom text. Any code that that is outside of the TriggerAction-Function can not reach the locals.
 
Level 12
Joined
Feb 5, 2018
Messages
521
That's not needed here. Use
Custom script: call DestroyGroup(udg_WOI_DamageGroup)
after "Pick every unit in group" instead.

Ok i'll change that.

Local shadowing that is a powerful but dangerous technique.
The Actions inside the Group Loop can not reach the local udg_WOI_Caster cause that happens in another function. The same applies for the Filter used in the Group with WOI_Player aswell for conditions inside an if.
It will read the Global variable whatever it was set to before that trigger happens.

Really? You can't use local units in loop actions? Well, eh, since this trigger runs instantly and does not use timers or loops I guess I will switch them to globals, if it is the easiest way.

EDIT: What about a switcheroo making a global that reads the local inside the loop?
GlobalUnitVariable = WOI_Caster
 
Level 12
Joined
Feb 5, 2018
Messages
521
It is indeed the easiest way. In fact, you don't even need shadowing references here. Remove those locals then you're fine.

Yea did that. :) Now I still need to only damage the units once. Don't wanna deal the damage multiple times.

Wow, it actually runs a lot smoother with just some globals.

  • Wave of Ice
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Wave Of Ice (Text not done)
    • Actions
      • Custom script: set udg_WOI_Caster = GetTriggerUnit()
      • Custom script: set udg_WOI_Player = GetOwningPlayer(udg_WOI_Caster)
      • Custom script: set udg_WOI_Level = GetUnitAbilityLevelSwapped('A01D', udg_WOI_Caster)
      • Set VariableSet WOI_Loc1 = (Position of WOI_Caster)
      • Set VariableSet WOI_Loc2 = (Target point of ability being cast)
      • Set VariableSet WOI_Damage = ((Real(WOI_Level)) x (100.00 + ((Real((Intelligence of WOI_Caster (Include bonuses)))) x 0.25)))
      • Game - Display to (All players) the text: (String((Integer(WOI_Damage))))
      • Set VariableSet WOI_Angle = (Angle from WOI_Loc1 to WOI_Loc2)
      • For each (Integer WOI_Integer) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set VariableSet WOI_Offset = (WOI_Offset + 48.00)
          • Set VariableSet WOI_Loc3 = (WOI_Loc1 offset by (48.00 + WOI_Offset) towards WOI_Angle degrees.)
          • Special Effect - Create a special effect at WOI_Loc3 using Abilities\Spells\Undead\FrostNova\FrostNovaTarget.mdl
          • Set VariableSet WOI_SFX[WOI_Integer] = (Last created special effect)
          • Special Effect - Destroy WOI_SFX[WOI_Integer]
          • Set VariableSet WOI_DamageGroup = (Units within 125.00 of WOI_Loc3 matching ((((Matching unit) is dead) Equal to False) and ((((Matching unit) is in WOI_DamageGroup.) Equal to False) and (((Matching unit) belongs to an enemy of WOI_Player.) Equal to True))).)
          • Unit Group - Pick every unit in WOI_DamageGroup and do (Actions)
            • Loop - Actions
              • Set VariableSet WOI_Target = (Picked unit)
              • Unit - Cause WOI_Caster to damage WOI_Target, dealing WOI_Damage damage of attack type Spells and damage type Magic
          • Custom script: call RemoveLocation (udg_WOI_Loc3)
      • Custom script: call RemoveLocation (udg_WOI_Loc1)
      • Custom script: call RemoveLocation (udg_WOI_Loc2)
      • Custom script: call DestroyGroup (udg_WOI_DamageGroup)
      • Set VariableSet WOI_Offset = 0.00
EDIT: @Deserted @JAKEZINC how to damage the targets in the group only once?

I tried searching the forums and I've seen it somewhere, but could not find it. :)
 
Last edited:
Level 6
Joined
Dec 31, 2017
Messages
138
  • For each (Integer WOI_Integer) from 1 to 10, do (Actions)
    • Loop - Actions
      • ...
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Add (Units within 125.00 of Loc matching (Condition)) to WOI_DamageGrop
      • ...
  • Unit Group - Pick every unit in WOI_DamageGrop and Unit - Cause WOI_Caster to damage (Picked unit), dealing WOI_Damage damage of attack type Spells and damage type Magic
 
Status
Not open for further replies.
Top