1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Unit not adding in group?

Discussion in 'Triggers & Scripts' started by Krakenn99, Apr 4, 2019.

  1. Krakenn99

    Krakenn99

    Joined:
    Jun 26, 2014
    Messages:
    480
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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!?
     
  2. Aeryn

    Aeryn

    Joined:
    Apr 17, 2017
    Messages:
    266
    Resources:
    0
    Resources:
    0
    Unit groups with array should be created first iitc. Do this: Custom Script: set udg_tempGroup[0] = CreateGroup()
     
  3. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,024
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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: Apr 4, 2019