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

When unit in unit group dies, remove from that group, with arrays

Status
Not open for further replies.
Level 3
Joined
Sep 5, 2019
Messages
33
There has got to be an easier way. I want to remove units from their unit group when they die, and set a number variable to one less (keeping track of how many are in the group, because a condition in another trigger cant take unit groups).

I am spawning creeps in 30 places across the map, and am using a single unit group array. (The actual spawning is in a different trigger, its working smoothly). I want to respawn the creep group once that creep group is all killed, and I cant find an easier way to check if a creep in [respective] unit group has died. Checking every time any creep dies, and running through this loop every single time just to remove a single unit from only one of the thirty groups seems horribly inefficient.

CreepRemoveIndexNum1 - Index number for the Unit Group array, and Real Number array counting units in said unit group
CreepNumberUnitG1 - Unit Group array for each creep group, its filled as the creeps are spawned
CreepNumberReal1 - Real Number array keeping track of alive units in unit group
Screenshot (66).png


Thank you for the help!
 
You can bind a unit's group to its unique index, using a code/system called UnitIndexer.

Pseudocode:

UnitGroup[UnitIndex] = Group_xy

and so you can load it later

GroupOfDyingUnit = UnitGroup[IndexOf(DyingUnit)]
Group - RemoveFromGroup(GroupOfDyingUnit, DyingUnit)

In GUI there exists a built-in function to count units in a unit group, an extra counter variable might not be needed.
 
Level 3
Joined
Sep 5, 2019
Messages
33
You can bind a unit's group to its unique index, using a code/system called UnitIndexer.

Pseudocode:

UnitGroup[UnitIndex] = Group_xy

and so you can load it later

GroupOfDyingUnit = UnitGroup[IndexOf(DyingUnit)]
Group - RemoveFromGroup(GroupOfDyingUnit, DyingUnit)

In GUI there exists a built-in function to count units in a unit group, an extra counter variable might not be needed.
Looks like I have some learning to do! UnitIndexer sounds perfect, thank you!

Dead units are eventually removed from unit groups, but they stay while the corpse decays (and maybe even longer, I'm not exactly sure when they're finally removed) and I want to know as soon as they die. I couldn't find a way to only count alive units in a unit group, so I tried making my own.

Thank you so much for the help, hopefully my map runs smoother with this haha
 
Status
Not open for further replies.
Top