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

Unit Group Add Bug

Status
Not open for further replies.
Level 19
Joined
Feb 4, 2009
Messages
1,313
I just made a spell which I wanted to submit here later but it does not seem to work properly

There is a unit group which contains all units which were hit already (these units should not be hit again so I added them to a group that I can ask if there are still units in it) but it only works for the first cast for some reason and after that the enemy are killed nearly instantly

what did I forgot? (and any other things to improve)

  • Rhino Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • -------- Resets the counter variable which is used to shut down the trigger if there is no rhino to be moved --------
      • Set instances = 0
      • For each (Integer int) from 0 to rhino_max, do (Actions)
        • Loop - Actions
          • -------- If there still is a unit --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • rhino[int] Not equal to No unit
            • Then - Actions
              • -------- If the distance is not moved yet and and the caster is not dead and still there --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rhino_distance[int] Less than rhino_distance_max[int]
                  • rhino_caster[int] Not equal to No unit
                  • (rhino_caster[int] is alive) Equal to True
                • Then - Actions
                  • -------- Increases distance moved --------
                  • Set rhino_distance[int] = (rhino_distance[int] + rhino_speed[int])
                  • -------- Sets new coordinates --------
                  • Set rhino_x[int] = (rhino_x[int] + (rhino_speed[int] x (Cos((Facing of rhino_caster[int])))))
                  • Set rhino_y[int] = (rhino_y[int] + (rhino_speed[int] x (Sin((Facing of rhino_caster[int])))))
                  • -------- If the units run out of the playable map area they will be stopped --------
                  • Custom script: if RectContainsCoords(GetPlayableMapRect(), udg_rhino_x[udg_int], udg_rhino_y[udg_int]) then
                  • -------- Increases counter --------
                  • Set instances = (instances + 1)
                  • -------- Makes the rhinos fade out after 50% of distance traveled --------
                  • Animation - Change rhino[int]'s vertex coloring to (100.00%, 100.00%, 100.00%) with (-50.00 + (100.00 x (rhino_distance[int] / rhino_distance_max[int])))% transparency
                  • -------- Destroys trees if enabled --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • rhino_kill_trees[int] Equal to True
                    • Then - Actions
                      • Custom script: call KillTreesInRect( udg_rhino_aoe[udg_int], udg_rhino_x[udg_int], udg_rhino_y[udg_int] )
                    • Else - Actions
                  • -------- Damages units around --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • rhino_aoe[int] Greater than 0.00
                    • Then - Actions
                      • Set temppoint = (Point(rhino_x[int], rhino_y[int]))
                      • Set tempgroup = (Units within rhino_aoe[int] of temppoint matching ((((Owner of (Matching unit)) is an enemy of (Owner of rhino_caster[int])) Equal to True) and ((((Matching unit) is alive) Equal to True) and (((Matching unit) is in rhino_hit_units[int]) Equal to False))))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (tempgroup is empty) Equal to False
                        • Then - Actions
                          • Unit Group - Pick every unit in tempgroup and do (Actions)
                            • Loop - Actions
                              • Unit - Cause rhino_caster[int] to damage (Picked unit), dealing rhino_dmg[int] damage of attack type Spells and damage type Normal
                          • Unit Group - Add all units of tempgroup to rhino_hit_units[int]
                        • Else - Actions
                      • Custom script: call DestroyGroup( udg_tempgroup )
                      • Custom script: call RemoveLocation( udg_temppoint )
                    • Else - Actions
                  • -------- Moves the rhino to its coordinates --------
                  • Custom script: call SetUnitX(udg_rhino[udg_int],udg_rhino_x[udg_int])
                  • Custom script: call SetUnitY(udg_rhino[udg_int],udg_rhino_y[udg_int])
                  • -------- makes the unit face something --------
                  • Unit - Make rhino[int] face (Facing of rhino_caster[int]) over 0.00 seconds
                  • Custom script: else
                  • -------- Resetseverything --------
                  • Set rhino_hit_units[int] = (Random 0 units from rhino_hit_units[int])
                  • Unit - Remove rhino[int] from the game
                  • Set rhino[int] = No unit
                  • Set rhino_distance[int] = 0.00
                  • Custom script: endif
                • Else - Actions
                  • -------- Resetseverything --------
                  • Set rhino_hit_units[int] = (Random 0 units from rhino_hit_units[int])
                  • Unit - Remove rhino[int] from the game
                  • Set rhino[int] = No unit
                  • Set rhino_distance[int] = 0.00
            • Else - Actions
      • -------- Disabels trigger if there are no instances running --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • instances Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
I changed the spell and redid some stuff so that it works now but I still would like to know why this try didn't work (if anyone will read this :p )
 
Last edited:
Level 4
Joined
Mar 23, 2008
Messages
87
Custom script: call DestroyGroup( udg_tempgroup )
sounds very suspicious... I've never used it myself, and i have no idea what it does but it sounds like it removes the variable.
Use GroupClear() instead?
 
Custom script: call DestroyGroup( udg_tempgroup )
sounds very suspicious... I've never used it myself, and i have no idea what it does but it sounds like it removes the variable.
Use GroupClear() instead?

His solution will probably work, but the theory is wrong ^^

DestroyGroup( ) indeed destroys the group to prevent leaks, but since you're using a global variable it's not needed - actually, you must not do it. If you do, you have to create it again, while it's much better just to clear the group.

Once you destroy the variable and you don't recreate it, it won't work anymore :p
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
His solution will probably work, but the theory is wrong ^^

DestroyGroup( ) indeed destroys the group to prevent leaks, but since you're using a global variable it's not needed - actually, you must not do it. If you do, you have to create it again, while it's much better just to clear the group.

Once you destroy the variable and you don't recreate it, it won't work anymore :p

good to know....always thought it would be like RemoveLocation()
but right now I'm so f***ed up about wc3 and needing twice the time to remove leaks and fix bugs caused by leak fixing then I would need to make the trigger itself...

however thanks + rep
 
Status
Not open for further replies.
Top