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

Unit groups problem

Status
Not open for further replies.
Level 29
Joined
Jul 29, 2007
Messages
5,174
Any idea why this doesn't work ?

  • Projectile
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) has buff BUFF) Equal to True)) and do (Actions)
        • Loop - Actions
          • Set Integer = (Integer + 1)
          • Set Point[Integer] = (Position of (Picked unit))
          • Unit Group - Pick every unit in (Units within 40.00 of Point[Integer] matching ((Unit-type of (Matching unit)) Equal to UNIT)) and do (Actions)
            • Loop - Actions
              • Unit - Cause (Picked unit) to damage circular area after 0.00 seconds of radius 80.00 at Point[Integer], dealing 10.00 damage of attack type Spells and damage type Normal
              • Custom script: call RemoveLocation(udg_Point[udg_Integer])
              • Unit - Kill (Picked unit)

[Edit] ops, I have 2 browsers of the hive opened and put this on the wrong one >.<
Oh well :p
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
First possible problem (not sure though): you destroy the group "units in playable map". I'm not sure if you're allowed to, as this might be one of those variables you shouldn't destroy if you want to use them.

Second problem: you loop through multiple units, destroying the same location for each unit again. This means that if you have 2 units within 40 of (point), you destroy your point variable twice, which leads to a double free of location. Anyway, in this case I highly doubt you need an arrayed point variable in the first place.

Third problem: you never "reset" Integer. This means that after 0,05 seconds if you have 100 units on the map, Integer will reach 100. After 0,10 seconds, integer will be 200, and perhaps after a few minutes, integer reaches the maximum value possible...
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Problem 2 explained:

  • Unit Group - Pick every unit in (Units within 40.00 of Point[Integer] matching ((Unit-type of (Matching unit)) Equal to UNIT)) and do (Actions)
    • Loop - Actions
      • Unit - Cause (Picked unit) to damage circular area after 0.00 seconds of radius 80.00 at Point[Integer], dealing 10.00 damage of attack type Spells and damage type Normal
      • Custom script: call RemoveLocation(udg_Point[udg_Integer])
      • Unit - Kill (Picked unit)

Let's say there are 2 units in the Unit Group (units within 40 of point).
What happens?
Unit - cause (the first unit) to damage circular area after 0 seconds at point[X]
call removelocation: Destroy the point, the point is resetted to center of playable map area
Kill (the first unit)
The loop has iterated one time. There's still a 2nd unit in the unit group, so we have to iterate the actions again.

Unit - cause (the second picked unit) to damage circular area after 0 seconds at... Point[X] which now is center of playable map area, as it was destroyed.
call removelocation: destroy the point that already was destroyed.
Kill (second unit)


I don't know if this causes the trigger to fail, but it's certainly a potential bug.

What exactly do you want to do? perhaps there's an easier or a less bugy alternative?
 
Status
Not open for further replies.
Top