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

[Trigger] Unit not adding in group?

Status
Not open for further replies.
Level 11
Joined
Jun 26, 2014
Messages
497
This is the whole trigger:
  • Necromancy Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer forEachNecromancy) from 1 to spNecromancyMui, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in spNecromancyDummies[forEachNecromancy]) Greater than 0
            • Then - Actions
              • Unit Group - Pick every unit in spNecromancyDummies[forEachNecromancy] and do (Actions)
                • Loop - Actions
                  • Set tempUnit = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (tempUnit is alive) Equal to True
                    • Then - Actions
                      • Set tempPoint[0] = (Position of tempUnit)
                      • Set tempPoint[1] = (tempPoint[0] offset by 26.00 towards (Facing of tempUnit) degrees)
                      • Unit - Move tempUnit instantly to tempPoint[1]
                      • For each (Integer forEachNecromancyD) from 1 to spNecromancyDMui, do (Actions)
                        • Loop - Actions
                          • Set tempGroup[0] = (Units within 75.00 of tempPoint[1] matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of spNecromancyCaster[forEachNecromancy])) Equal to True)))
                          • Unit Group - Pick every unit in tempGroup[0] and do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • ((Picked unit) is in spNecromancyDmgGroup[forEachNecromancyD]) Equal to False
                                • Then - Actions
                                  • Unit Group - Add all units of tempGroup[0] to spNecromancyDmgGroup[forEachNecromancyD]
                                  • Unit - Cause spNecromancyCaster[forEachNecromancy] to damage (Picked unit), dealing spNecromancyDamage[forEachNecromancy] damage of attack type Magic and damage type Normal
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • ((Picked unit) is A Hero) Equal to True
                                    • Then - Actions
                                      • Unit Group - Remove tempUnit from spNecromancyDummies[forEachNecromancy]
                                      • Unit - Kill tempUnit
                                    • Else - Actions
                                • Else - Actions
                          • Custom script: call DestroyGroup(udg_tempGroup[0])
                      • Custom script: call RemoveLocation(udg_tempPoint[0])
                      • Custom script: call RemoveLocation(udg_tempPoint[1])
                    • Else - Actions
                      • Unit Group - Remove tempUnit from spNecromancyDummies[forEachNecromancy]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • spNecromancyBool[forEachNecromancy] Equal to True
                • Then - Actions
                  • Set spNecromancyBool[forEachNecromancy] = False
                  • Set spNecromancyIndex = (spNecromancyIndex - 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • spNecromancyIndex Less than or equal to 0
                    • Then - Actions
                      • Set spNecromancyIndex = 0
                      • Set spNecromancyMui = 0
                      • Set spNecromancyDIndex = 0
                      • Set spNecromancyDMui = 0
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
                • Else - Actions

This is where it fails to add a unit into spNecromancyDmgGroup[forEachNecromancyD]
  • For each (Integer forEachNecromancyD) from 1 to spNecromancyDMui, do (Actions)
    • Loop - Actions
      • Set tempGroup[0] = (Units within 75.00 of tempPoint[1] matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of spNecromancyCaster[forEachNecromancy])) Equal to True)))
      • Unit Group - Pick every unit in tempGroup[0] and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is in spNecromancyDmgGroup[forEachNecromancyD]) Equal to False
            • Then - Actions
              • Unit Group - Add all units of tempGroup[0] to spNecromancyDmgGroup[forEachNecromancyD]
              • Unit - Cause spNecromancyCaster[forEachNecromancy] to damage (Picked unit), dealing spNecromancyDamage[forEachNecromancy] damage of attack type Magic and damage type Normal
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to True
                • Then - Actions
                  • Unit Group - Remove tempUnit from spNecromancyDummies[forEachNecromancy]
                  • Unit - Kill tempUnit
                • Else - Actions
            • Else - Actions
      • Custom script: call DestroyGroup(udg_tempGroup[0])

I first tried with Unit Group - Add Unit but that did not work either. Any suggestions. Damage is still dealt and unit is still picked, but they are not added to the group!?
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Aeryn is correct. This is why the variable editor asks for the size of array variables; some variable types need to be initialized before they can be used. In your case, however, since the used index is dependent on how many instances of the spell are active you can't use the variable editor to pre-allocate them and will have to do it on the fly when new instances are created. In addition, you will need to destroy them (like cleaning a regular group leak) when the spell instance is done. This also affects spNecromancyDummies[], which probably only has index [1] allocated as well (but appears to be working because you haven't cast the spell multiple times at once).

  • Custom script: set udg_spNecromancyDmgGroup[udg_forEachNecromancyD] = CreateGroup()
It seems to me this trigger could be better written without the reliance on group arrays, but it's not entirely clear to me how this Necromancy spell is supposed to work. Could you describe what it's supposed to do and perhaps someone can suggest an alternative solution?
 
Last edited:
Status
Not open for further replies.
Top