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 haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  4. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. 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] Removing picked units doesn't work

Discussion in 'Triggers & Scripts' started by Unelith, Oct 26, 2013.

  1. Unelith

    Unelith

    Joined:
    Aug 15, 2012
    Messages:
    135
    Resources:
    0
    Resources:
    0
    My trigger looks like this:
    Trigger
    • Events
      • Time - Every 0.03 seconds of game-time
    • Conditions
    • Actions
      • For Each Integer B from 1 to USBFX_BuffCount, do Actions
        • Loop - Actions
          • Unit Group - Pick every unit in BuffedUnitsGroup[(Integer B)] and do (Actions)
            • Loop - Actions
              • Set USBFX_PerOldPickedUnitHandle = (Key (Picked unit))
              • Set USBFX_PerRemainingTime = (Load 0 of (Key (Picked unit)) from USBFX_Hashtable)
              • Set USBFX_PerDummyUG = (Load 2 of (Key (Picked unit)) from USBFX_Hashtable)
              • If (All Conditions Are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • USBFX_PerRemainingTime Greater than 0.00
                • Then - Actions
                  • Hashtable - Save (USBFX_PerRemainingTime - 0.03) as 0 of (Key (Picked unit)) in USBFX_Hashtable
                  • If (All Conditions Are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in (Load 2 of (Key (Picked unit))) in USBFX_Hashtable)) Not equal to (Load 3 of (Key (Picked unit)) in USBFX_Hashtable)
                    • Then - Actions
                      • Game - Display to (All players) the text: ============
                      • Unit Group - Pick every unit in (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) and do (Actions)
                        • Loop - Actions
                          • -------- THESE ACTIONS DONT WORK! --------
                          • Game - Display to (All players) the text: (Name of (Picked unit)
                          • Unit - Remove (Picked unit) from the game
                      • Game - Display to (All players) the text: ============
                      • Unit Group - Remove all units of (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) from (Load 2 of (Key (Picked unit)) in USBFX_Hashtable)
                      • Hashtable - Save 0.00 as 4 of (Key (Picked unit)) in USBFX_Hashtable
                      • For each (USBFX_PerIntegerC) from 1 to (Load 3 of (Key (Picked unit)) in USBFX_Hashtable), do (Actions)
                        • Loop - Actions
                          • Unit - Create 1 USBFX Dummy Unit for (Owner of (Picked unit)) at ALocationItDoesntMatterHere, facing X degrees
                          • Unit Group - Add (Last created unit) to (Load 2 of (Key (Picked unit)) in USBFX_Hashtable)
                          • Special Effect - Create a special effect attached to, etc...
                    • Else - Actions
                      • -------- It doesn't really matter what is there, it has nothing to do with the problem --------
                • Else - Actions
                  • Game - Display to (All players) the text: TIME OUT!!!
                  • Game - Display to (All players) the text: !!!!!!!!!!!!!!!!
                  • Unit Group - Pick every unit in (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) and do (Actions)
                    • Loop - Actions
                      • -------- AND THESE ACTIONS WORK! WTF --------
                      • Game - Display to (All players) the text: (Name of (Picked unit)
                      • Unit - Remove (Picked unit) from the game
                      • Unit Group - Remove all units of (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) from (Load 2 of (Key (Picked unit)) in USBFX_Hashtable)
                      • Unit Group - Remove (Picked unit) from USBFX_UnitGroups[(Integer B)]
                      • Hashtable - Clear all chlid hashtables of child (Key (Picked unit)) in USBFX_Hashtable


    As you can see, i used the same actions two times.
    • Unit Group - Pick every unit in (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) and do (Actions)
      • Loop - Actions
        • Game - Display to (All players) the text: (Name of (Picked unit)
        • Unit - Remove (Picked unit) from the game


    First time it was under a condition. But i think there is nothing wrong with the condition. Other actions in this condition work properly. It should display something like this in game (assuming there were 3 units in the unit group at time):
    Code (Text):
    ===========
    USBFX Dummy Unit
    USBFX Dummy Unit
    USBFX Dummy Unit
    ===========
    USBFX Dummy Unit is name of unit in the unit group, that i stored in a hashtable. But, that appears instead:
    Code (Text):
    ===========
    ===========
    Actions under the condition, and under that unit group loop DON'T WORK.
    But, in the second use, that should clean the unit group and hashtable after the RemainingTime hits 0.00 (buff ends), it shows this:
    Code (Text):
    TIMEOUT!!!
    !!!!!!!!!!!!!!
    USBFX Dummy Unit
    USBFX Dummy Unit
    USBFX Dummy Unit
    !!!!!!!!!!!!!!
    That means it works correctly. I also tried moving the first unit group actions, the ones that DONT work, out of the condition, and they worked. But i need it to be *under* condition. I don't want it to apply every 0.03 if the buff is on. I have tried something like:
    • If (All Conditions Are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Number of units in (Load 2 of (Key (Picked unit))) in USBFX_Hashtable)) Not equal to (Load 3 of (Key (Picked unit)) in USBFX_Hashtable)
      • Then - Actions
        • Set UBSFX_RemoveGroup = TRUE
      • Else - Actions
        • Set UBSFX_RemoveGroup = FALSE
    • Trigger - Run USBFX Clean Unit Group <gen> (ignoring conditions)


    And in seperate trigger:
    • If (UBSFX_RemoveGroup = FALSE) then do (Skip remaining actions) else do (Do nothing)
    • Unit Group - Pick every unit in (Load 2 of USBFX_PerOldPickedUnitHandle in USBFX_Hashtable) and do (Actions)
      • Loop - Actions
        • Game - Display to (All players) the text: (Name of (Picked unit))
        • Unit - Remove (Picked unit) from the game


    IT DIDN'T WORK. Other thing i have tried is:

    • Set USBFX_PerCount = 0
    • Unit Group - Pick every unit in (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) and do (Actions)
      • Loop - Actions
        • Set USBFX_PerCount = (USBFX_PerCount + 1)
        • Set USBFX_PerDummyUnits[USBFX_PerCount] = (Picked unit)
    • If (All Conditions Are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Number of units in (Load 2 of (Key (Picked unit))) in USBFX_Hashtable)) Not equal to (Load 3 of (Key (Picked unit)) in USBFX_Hashtable)
      • Then - Actions
        • For each (USBFX_PerIntegerD) from 1 to USBFX_PerCount do (Actions)
          • Loop - Actions
            • Game - Display to (All players) the text: (Name of USBFX_PerDummyUnits[USBFX_PerIntegerD])
            • Unit - Remove USBFX_PerDummyUnits[USBFX_PerIntegerD] from the game


    IT DIDN'T WORK EITHER.

    Does anyone know what should i do to make this sh*t run properly?
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,261
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Pick every unit in ..key from picked unit..
    --> remove picked unit

    Seems a bit messy, try always to put picked unit into a variable, so you always can define whats picked unit now and whats not ( you use 'pick unit' in another 'pick unit')
     
  3. Unelith

    Unelith

    Joined:
    Aug 15, 2012
    Messages:
    135
    Resources:
    0
    Resources:
    0
    But look, i used double Picked unit later, and it worked. This is not the problem.
    Double picked unit works fine as long as i don't want to refer to picked unit from the first group (BuffedUnitsGroup[]). This isn't it. It must be something different.
     
  4. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,702
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Is this under a Unit Group actions?

    • Unit Group - Pick every unit in (Load 2 of (Key (Picked unit)) in USBFX_Hashtable) and do (Actions)


    Because you're using (Key (Picked unit)), and I don't see it inside a unit group block (though maybe you didn't include it in the trigger posted).
     
  5. Unelith

    Unelith

    Joined:
    Aug 15, 2012
    Messages:
    135
    Resources:
    0
    Resources:
    0
    Yes, it is, the first unit group block is at the very beginning of the trigger, just under For Each Integer B loop. There are 2 units group used here. BuffedUnitsGroup[], and the one from hashtable. Picked unit in the line you are talking about is the one from BuffedUnitsGroup[].
    I have also tried using
    • Set USBFX_PerOldPickedUnitHandle = (Key (Picked unit))

    Variable, instead of Key (Picked unit), but it didn't change anything, like i have expected.
     
  6. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,181
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    You should post a test map. I doubt it takes more than five minutes to solve the issue with proper debugging.
     
  7. Unelith

    Unelith

    Joined:
    Aug 15, 2012
    Messages:
    135
    Resources:
    0
    Resources:
    0
    http://www.hiveworkshop.com/forums/pastebin_data/16g0z0/_files/UnelithStackingBuffVFX01.w3x

    I just changed some variables' names since then, now every variable begins with USBFX so it doesn't accidently collide with other systems. The trigger that i have posted is called USBFX Periodic.


    If you want to test it in game - just order the Lich to cast Chain Lightning at Dummy who looks like Mal'Ganis, and buff will gain 1 stack. Then cast it again - buff will gain another stack, but some visual effects will stay in one place and these are ones who i cannot remove. Visual effects are based on dummy units (USBFX Dummy Unit). Dummy units are stored in one group, which is saved to a hashtable. The condition:
    • (Number of units in (Load 2 of (Key (Picked unit))) in USBFX_Hashtable)) Not equal to (Load 3 of (Key (Picked unit)) in USBFX_Hashtable)

    Checks if number of dummy units (visible visual effects) is equal to current stacks of the buff on specific unit.
    So everytime stacks are increased, i want to remove all units from dummy unit group, and create as much as there are stacks. But only the second thing works. Surprising thing is that after buff expires (6 seconds from last application), the dummy unit group cleans properly.

    And you may se something like this, for example:
    Load (2+(5x(Integer B-1)))
    That's because i changed it so multiple buffs can be applied to one unit depending on buff's id.
    For example: Buff #1 is stored in 0-4 keys in hashtable. Buff #2 in 5-9 etc.
     
  8. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,181
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    There are no units in the group at that point so there are no names to display. After that part, you add units into the group and then "Number of units in USBFX_PerDummyUG) Not equal to ..." is always equal so it goes to the else part.
     
  9. Unelith

    Unelith

    Joined:
    Aug 15, 2012
    Messages:
    135
    Resources:
    0
    Resources:
    0
    But after i apply the buff for 2nd time, current stacks value is set to 2, and number of units in unit group is equal to 1. 2 != 1 so it does activate the "Then - Actions" part, but still the unit group isn't cleaned. Atleast i think so.
     
  10. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,181
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    The number of units is still 0. When the spell is cast on a target, you create a group and save it. You overwrite the previous group.
     
  11. Unelith

    Unelith

    Joined:
    Aug 15, 2012
    Messages:
    135
    Resources:
    0
    Resources:
    0
    I think i understand! The problem is in the trigger which applies the buff?

    EDIT: I did this:
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • USBFX_AppCurrentStacks Lesser than 1
      • Then - Actions
        • Set USBFX_TempIntegerP = (2 + (5 x (USBFX_Apply_ID - 1)))
        • Set USBFX_TempIntegerC = (Key (Target unit of ability being cast))
        • Custom script: call SaveGroupHandleBJ(CreateGroup(), udg_USBFX_TempIntegerP, udg_USBFX_TempIntegerC, udg_USBFX_Hashtable)

    And it works now. Thanks!