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 Groups - Second cast time problems

Discussion in 'Triggers & Scripts' started by Nudl9, Nov 2, 2019.

  1. Nudl9

    Nudl9

    Joined:
    Nov 9, 2006
    Messages:
    2,203
    Resources:
    28
    Icons:
    11
    Skins:
    1
    Maps:
    16
    Resources:
    28
    Hey, so i have this channeling spell where a few target units will slowly walk towards the casters. It's similar to DOTA2 Lich's Sinister Gaze except it has more targets. Adding 2/3/4 of the closest units to the spell as well. The problem i've got is that the spell doesn't work on the same units the second time i'm casting it.

    Part 1: Casting the spell, adding units to group and adding buff
    • Mesmerize2 Start Cast
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Mesmerize
      • Actions
        • Game - Display to (All players) the text: Start Casting
        • Unit Group - Add (Triggering unit) to Spell_SongofSiren_Group
        • Unit Group - Remove all units from Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]
        • -------- --------
        • Unit Group - Add (Target unit of ability being cast) to Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]
        • -------- --------
        • Game - Display to (All players) the text: (String((Number of units in Spell_SongofSiren_HitGroup[Integer1])))
        • Set Spell_Mesmerize_TempPoint[1] = (Position of (Target unit of ability being cast))
        • For each (Integer Integer3) from 1 to ((Level of (Ability being cast) for (Triggering unit)) + 1), do (Actions)
          • Loop - Actions
            • Set Spell_Mesmerize_TempUnit = No unit
            • Set Real1 = 400.01
            • Set Spell_Mesmerize_TempGroup[1] = (Units within 400.00 of Spell_Mesmerize_TempPoint[1] matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is Mechanical) Equal to False) and ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is Magic Immune) Equal)
            • -------- --------
            • Unit Group - Pick every unit in Spell_Mesmerize_TempGroup[1] and do (Actions)
              • Loop - Actions
                • Set Spell_Mesmerize_TempPoint[2] = (Position of (Picked unit))
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Distance between Spell_Mesmerize_TempPoint[1] and Spell_Mesmerize_TempPoint[2]) Less than Real1
                    • ((Picked unit) is in Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]) Equal to False
                  • Then - Actions
                    • Set Real1 = (Distance between Spell_Mesmerize_TempPoint[1] and Spell_Mesmerize_TempPoint[2])
                    • Set Spell_Mesmerize_TempUnit = (Picked unit)
                  • Else - Actions
                • Custom script: call RemoveLocation(udg_Spell_Mesmerize_TempPoint[2])
            • Custom script: call DestroyGroup(udg_Spell_Mesmerize_TempGroup[1])
            • -------- --------
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Spell_Mesmerize_TempUnit Not equal to No unit
              • Then - Actions
                • -------- --------
                • Unit Group - Add Spell_Mesmerize_TempUnit to Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]
              • Else - Actions
            • Set Spell_Mesmerize_TempUnit = No unit
        • Custom script: call RemoveLocation(udg_Spell_Mesmerize_TempPoint[1])
        • -------- Apply Slow --------
        • Unit Group - Pick every unit in Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))] and do (Actions)
          • Loop - Actions
            • Set Spell_Mesmerize_TempPoint[2] = (Position of (Picked unit))
            • Unit - Create 1 Dummy Unit for (Owner of (Triggering unit)) at Spell_Mesmerize_TempPoint[2] facing Default building facing degrees
            • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
            • Unit - Add Effect: Mesmerize: Cast Slow to (Last created unit)
            • Unit - Set level of Effect: Mesmerize: Cast Slow for (Last created unit) to (Level of (Ability being cast) for (Triggering unit))
            • Unit - Order (Last created unit) to Human Sorceress - Slow Spell_Mesmerize_TempUnit
            • Custom script: call RemoveLocation(udg_Spell_Mesmerize_TempPoint[2])
        • -------- Loop --------
        • Trigger - Turn on Mesmerize2 Loop <gen>


    Part 2: The loop which causes units to move towards caster. 0 units show up in debug message on second casting.
    • Mesmerize2 Loop
      • Events
        • Time - Every 0.05 seconds of game time
      • Conditions
      • Actions
        • Unit Group - Pick every unit in Spell_SongofSiren_Group and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Number of units in Spell_SongofSiren_Group) Greater than 0
              • Then - Actions
                • Set Spell_Mesmerize_TempUnit = (Picked unit)
                • Set Integer1 = (Player number of (Owner of Spell_Mesmerize_TempUnit))
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Number of units in Spell_SongofSiren_HitGroup[Integer1]) Greater than 0
                  • Then - Actions
                    • Game - Display to (All players) the text: (String((Number of units in Spell_SongofSiren_HitGroup[Integer1])))
                    • Set Spell_Mesmerize_TempPoint[1] = (Position of Spell_Mesmerize_TempUnit)
                    • Unit Group - Pick every unit in Spell_SongofSiren_HitGroup[Integer1] and do (Actions)
                      • Loop - Actions
                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • ((Picked unit) has buff #Mesmerize ) Equal to True
                          • Then - Actions
                            • Game - Display to (All players) the text: Has buff
                            • Set Spell_Mesmerize_TempPoint[2] = (Position of (Picked unit))
                            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • If - Conditions
                                • (Distance between Spell_Mesmerize_TempPoint[1] and Spell_Mesmerize_TempPoint[2]) Greater than or equal to 128.00
                              • Then - Actions
                                • Set Spell_Mesmerize_TempPoint[3] = (Spell_Mesmerize_TempPoint[1] offset by 90.00 towards (Angle from Spell_Mesmerize_TempPoint[1] to Spell_Mesmerize_TempPoint[2]) degrees)
                                • Unit - Order (Picked unit) to Move To Spell_Mesmerize_TempPoint[3]
                                • Unit - Cause Spell_Mesmerize_TempUnit to damage (Picked unit), dealing 0.01 damage of attack type Spells and damage type Universal
                                • Custom script: call RemoveLocation(udg_Spell_Mesmerize_TempPoint[3])
                              • Else - Actions
                                • Unit - Order (Picked unit) to Stop
                            • Custom script: call RemoveLocation(udg_Spell_Mesmerize_TempPoint[2])
                          • Else - Actions
                            • Game - Display to (All players) the text: (Removed + (Name of (Picked unit)))
                            • Unit - Order (Picked unit) to Stop
                            • Unit Group - Remove (Picked unit) from Spell_SongofSiren_HitGroup[Integer1]
                    • Custom script: call RemoveLocation(udg_Spell_Mesmerize_TempPoint[1])
                  • Else - Actions
                    • Game - Display to (All players) the text: (String((Number of units in Spell_SongofSiren_HitGroup[Integer1])))
                    • Unit - Order Spell_Mesmerize_TempUnit to Stop
                • Set Spell_Mesmerize_TempUnit = No unit
              • Else - Actions
                • Trigger - Turn off (This trigger)


    Part 3: I tried 3 different methods of removing said units from the group and none of them work..
    • Mesmerize2 Stop Cast
      • Events
        • Unit - A unit Stops casting an ability
      • Conditions
        • (Ability being cast) Equal to Mesmerize
      • Actions
        • Game - Display to (All players) the text: Stop Casting
        • Unit Group - Remove (Triggering unit) from Spell_SongofSiren_Group
        • Unit Group - Remove all units from Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]
        • Unit Group - Pick every unit in Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))] and do (Actions)
          • Loop - Actions
            • Unit - Remove Effect: Mesmerize: Slow from (Picked unit)
            • Unit - Order (Picked unit) to Stop
            • Unit Group - Remove (Picked unit) from Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]
        • Custom script: call DestroyGroup(udg_Spell_SongofSiren_HitGroup[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit() ) ) ] )


    So the 3rd trigger is essentially where the problem lies. There is appearently no way of removing units from the unit groups of affected units.
     
  2. FeelsGoodMan

    FeelsGoodMan

    Joined:
    Dec 13, 2018
    Messages:
    574
    Resources:
    2
    Maps:
    2
    Resources:
    2
    I haven't thoroughly read through it but in the third trigger you destroy a non-dynamic unit group, so after that trigger having executed one time that group will not exist anymore, and you will therefore not be able to add or remove any units from it.

    The problem might lie elsewhere, but that's my guess.
     
  3. Nudl9

    Nudl9

    Joined:
    Nov 9, 2006
    Messages:
    2,203
    Resources:
    28
    Icons:
    11
    Skins:
    1
    Maps:
    16
    Resources:
    28
    I tried removing the units first, that didn't work.
    I tried removing all the units, that doesn't work either.
    So i tried destroying the group and that doesn't work either.
    I've tried all options separately and it just doesn't make sense.
     
  4. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,056
    Resources:
    1
    Spells:
    1
    Resources:
    1
    • You're not filtering to only find enemy targets in the cast trigger, btw. It will pick the three closest non-mechanical, non-magic immune, non-structures, regardless of them being allies or enemies.
    • The check for "number of units in Spell_SongofSiren_Group" in the periodic trigger will never evaluate to false. If there are no units in the group no code inside the Pick Actions will be evaluated, so it will never be checked when there are no units in the group. Instead you need to put this check before picking units in the group. You also should have logic in the cast trigger to turn on the periodic trigger when it's presently off, rather than always turning it on.
    • You don't need to set unit variables to null when you're done using them (I realize it has a purpose in the cast trigger, but it doesn't in the periodic). Globals usually never have to be nulled. Nulling locals is a JASS thing or when using locally shadowed globals in GUI.
    • Re-ordering the move every 0.05 seconds might cause it not to actually perform the move order. Food for thought. I realize the period is so low to prevent its owner from ordering it to do something else.
    • Why are you periodically dealing 0.01 damage to the mesmerized units?
    FeelsGoodMan is correct that the issue is destroying the group. Whatever you did, Nudl9, you did it wrong. The third trigger you've posted above removes all units from the group and then immediately after attempts to pick everything in the group to remove the buff. That's obviously not going to work because the group is empty!
    • Mesmerize2 Stop Cast
      • Events
        • Unit - A unit Stops casting an ability
      • Conditions
        • (Ability being cast) Equal to Mesmerize
      • Actions
        • Game - Display to (All players) the text: Stop Casting
        • Unit Group - Remove (Triggering unit) from Spell_SongofSiren_Group
        • Unit Group - Pick every unit in Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))] and do (Actions)
          • Loop - Actions
            • Unit - Remove Effect: Mesmerize: Slow from (Picked unit)
            • Unit - Order (Picked unit) to Stop
        • -------- don't destroy, just clear --------
        • Unit Group - Remove all units from Spell_SongofSiren_HitGroup[(Player number of (Owner of (Triggering unit)))]