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

Units in units group check problem

Status
Not open for further replies.
Level 10
Joined
Mar 17, 2012
Messages
579
Hi guys! Here's a simple but annoying question to you. I have a trigger that periodically creates a unit on my position ONLY if there's not the same unit in 10 AoE. BUT it keeps creating those units ignoring my conditions :( Here's my trigger. Maybe I'm blind or inattentive... :ogre_icwydt:
  • Trail of Life loop
    • Events
      • Time - Every 0.33 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Trail_of_Life_Owner[(Integer A)] has buff Trail of Life ) Equal to True
            • Then - Actions
              • Set Trail_of_Life_Point[(Integer A)] = (Position of Trail_of_Life_Owner[(Integer A)])
              • Set Trail_of_Life_Cleanup_Group[(Integer A)] = (Units within 100.00 of Trail_of_Life_Point[(Integer A)] matching (((Unit-type of (Matching unit)) Equal to Trail of Life) and (((Matching unit) is alive) Equal to True)))
              • Unit Group - Pick every unit in Trail_of_Life_Cleanup_Group[(Integer A)] and do (Actions)
                • Loop - Actions
                  • Set Trail_of_Life_Cleanup_Check[(Integer A)] = (Trail_of_Life_Cleanup_Check[(Integer A)] + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Trail_of_Life_Cleanup_Check[(Integer A)] Greater than 0
                • Then - Actions
                  • Do nothing
                • Else - Actions
                  • Unit - Create 1 Trail of Life for (Owner of Trail_of_Life_Owner[(Integer A)]) at Trail_of_Life_Point[(Integer A)] facing Default building facing degrees
                  • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
                  • Set Trail_of_Life_Cleanup_Check[(Integer A)] = 0
              • Custom script: call DestroyGroup(udg_Trail_of_Life_Cleanup_Group[GetForLoopIndexA()])
              • Custom script: call RemoveLocation(udg_Trail_of_Life_Point[GetForLoopIndexA()])
            • Else - Actions
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
My guess is that because Trial_of_Life_Cleanup_Group[] is null, resulting in always having 0 units. When you leave the array size to 1 for unit groups, the game will only create empty groups for indexes 0 and 1. Everything else will just be null.

There are two easy ways to fix this:
  • Give the array a definite size in the variable editor. In your case, you would set it to 12 if you only want to use indexes 0-12.

  • Manually initialize the groups before using them:
    • Custom script: if udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()] == null then
    • Custom script: set udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()] = CreateGroup()
    • Custom script: endif

    Then when you are done using the group:
    • Custom script: call DestroyGroup(udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()])
    • Custom script: set udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()] = null

I prefer the second option since I dislike having to enter the variable editor and change the default sizes of variables. However, if neither of those work, my only guess is that because 100 AoE is really, really small. How close is the "Trial of Life" to the owner?

EDIT: Could you post where you cache data for Trial_of_Life_Owner[]?
 
Last edited:
Level 10
Joined
Mar 17, 2012
Messages
579
My guess is that because Trial_of_Life_Cleanup_Group[] is null, resulting in always having 0 units. When you leave the array size to 1 for unit groups, the game will only create empty groups for indexes 0 and 1. Everything else will just be null.

There are two easy ways to fix this:
  • Give the array a definite size in the variable editor. In your case, you would set it to 12 if you only want to use indexes 0-12.

  • Manually initialize the groups before using them:
    • Custom script: if udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()] == null then
    • Custom script: set udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()] = CreateGroup()
    • Custom script: endif

    Then when you are done using the group:
    • Custom script: call DestroyGroup(udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()])
    • Custom script: set udg_Trial_of_Life_Cleanup_Group[GetForLoopIndexA()] = null

I prefer the second option since I dislike having to enter the variable editor and change the default sizes of variables. However, if neither of those work, my only guess is that because 100 AoE is really, really small. How close is the "Trial of Life" to the owner?

EDIT: Could you post where you cache data for Trial_of_Life_Owner[]?

Okay, Look. This spell is based on "Immolation on/off". It has to create dummies if the owner has a buff. This spell has to create a trail of dummies and each of them has to heal allies that are near the dummy. But if dummies are created on one point - the amoun of heal grows, whitch I'm trying to avoid. So I need to make sure that there are not more that 1 dummy in the area.

Here's my initialisation trigger:

  • Trail of Life init
    • Events
      • Unit - A unit Learns a skill
    • Conditions
      • (Learned Hero Skill) Equal to Trail of Life
    • Actions
      • Set Player_Number_Int = (Player number of (Owner of (Learning Hero)))
      • Set Trail_of_Life_Owner[Player_Number_Int] = (Learning Hero)

And I modified the dummies creation trigger but still no effect:

  • Trail of Life loop
    • Events
      • Time - Every 0.33 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Trail_of_Life_Owner[(Integer A)] has buff Trail of Life ) Equal to True
            • Then - Actions
              • Set Trail_of_Life_Point[(Integer A)] = (Position of Trail_of_Life_Owner[(Integer A)])
              • Set Trail_of_Life_Cleanup_Group[(Integer A)] = (Units within 150.00 of Trail_of_Life_Point[(Integer A)] matching (((Unit-type of (Matching unit)) Equal to Trail of Life) and ((((Matching unit) belongs to an ally of (Owner of Trail_of_Life_Owner[(Integer A)])) Equal to True) and (((Matching unit) is alive)
              • Unit Group - Pick every unit in Trail_of_Life_Cleanup_Group[(Integer A)] and do (Actions)
                • Loop - Actions
                  • Unit - Kill (Picked unit)
              • Unit - Create 1 Trail of Life for (Owner of Trail_of_Life_Owner[(Integer A)]) at Trail_of_Life_Point[(Integer A)] facing Default building facing degrees
              • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
              • Custom script: call DestroyGroup(udg_Trail_of_Life_Cleanup_Group[GetForLoopIndexA()])
              • Custom script: call RemoveLocation(udg_Trail_of_Life_Point[GetForLoopIndexA()])
            • Else - Actions
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Off the top of my head, the only way I can see it being possible is to connect all the dummies that are created to the caster by using a unit group. When you create a trail, add it to the caster's unit group and check for the distance. When the caster is 100-150 units away from ALL the dummies, create another trail.
 
Level 10
Joined
Mar 17, 2012
Messages
579
Off the top of my head, the only way I can see it being possible is to connect all the dummies that are created to the caster by using a unit group. When you create a trail, add it to the caster's unit group and check for the distance. When the caster is 100-150 units away from ALL the dummies, create another trail.

I guess I'll make it easier... I'll just add the Immolation spell to the dummy that will deal 0 damage and affect allies. Then I'll check if the unit has a buff :ogre_hurrhurr:

I was thinking about it today and understood that it won't solve a problem. Today I removed a "Locust" spell and they still keep popping up at one point :(

If Trail of Life is a locust dummy, it won't be enumerated by the unit group loop.

By the way, you are wrong, because in this trigger all those Locust units are considered and are working:

  • Trail of Life heal
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set Trail_of_Life_Dummy_Group = (Units of type Trail of Life)
      • Unit Group - Pick every unit in Trail_of_Life_Dummy_Group and do (Actions)
        • Loop - Actions
          • For each (Integer A) from 1 to 12, do (Actions)
            • Loop - Actions
              • Set Trail_of_Life_Picked_Point[(Integer A)] = (Position of (Picked unit))
              • Set Trail_of_Life_Picked_Group[(Integer A)] = (Units within 25.00 of Trail_of_Life_Picked_Point[(Integer A)] matching ((((Matching unit) is A structure) Not equal to True) and ((((Matching unit) belongs to an ally of (Owner of (Picked unit))) Equal to True) and (((Matching unit) is alive) Equal to True))
              • Set Trail_of_Life_Heal[(Integer A)] = (((((Real((Level of Trail of Life for Trail_of_Life_Owner[(Integer A)]))) x 3.00) + 2.00) + ((Real((Intelligence of Trail_of_Life_Owner[(Integer A)] (Include bonuses)))) x (((Real((Level of Trail of Life for Trail_of_Life_Owner[(Integer A)]))) / 200.00) + 0
              • Unit Group - Pick every unit in Trail_of_Life_Picked_Group[(Integer A)] and do (Actions)
                • Loop - Actions
                  • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + Trail_of_Life_Heal[(Integer A)])
              • Custom script: call RemoveLocation(udg_Trail_of_Life_Picked_Point[GetForLoopIndexA()])
              • Custom script: call DestroyGroup(udg_Trail_of_Life_Picked_Group[GetForLoopIndexA()])
      • Custom script: call DestroyGroup(udg_Trail_of_Life_Dummy_Group)
 
Last edited:
Level 37
Joined
Jul 22, 2015
Messages
3,485
By the way, you are wrong, because in this trigger all those Locust units are considered and are working

Yeah because look what you're doing that's different:
  • Set Trail_of_Life_Dummy_Group = (Units of type Trail of Life)

Grouping them from a rect is different from in range like here:
  • Set Trail_of_Life_Cleanup_Group[(Integer A)] = (Units within 150.00 of Trail_of_Life_Point[(Integer A)] matching...

At least I'm certain that's what the issue is. Could you add a message that shows what value Trail_of_Life_Cleanup_Check[] is?

On a side note, using Unit Group - Units of Type isn't recommended. It has some irremovable leak that can't be removed via GUI.
 
Status
Not open for further replies.
Top