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

Status
Not open for further replies.
Level 24
Joined
Nov 9, 2006
Messages
2,558
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.
 
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.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
  • 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)))]
 
Status
Not open for further replies.
Top