• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to associate two units with each other?

Status
Not open for further replies.
Level 8
Joined
Mar 12, 2008
Messages
437
How to associate a unit group with another unit?

Hey, I have a thing where one unit attacks another unit. After the attack, the unit is 'infected' forever.

What I want is for the infecting unit to die, when the infected one does. How can this be done? I thought about using the 'wait for condition' action, but iirc the information gets lost during the wait. Does it require hashtables?

Specifically, one infector is only mapped to one victim. One victim may have multiple infectors, which all die when the victim dies.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
I suggest you use a unit indexer.

Create an array unit group Infectors[], which will keep track of all the units that have infected a given unit.

For some victim with custom value UnitId, all units that infected this unit are stored in the unit group Infectors[UnitId]. When the victim dies, killing the infectors is a simple case of picking all units in Infectors[UnitId].

Just note that for unit group arrays to work properly, you need to set an array size in the variable editor (a few thousand is usually enough)
 
Level 8
Joined
Mar 12, 2008
Messages
437
I suggest you use a unit indexer.

Create an array unit group Infectors[], which will keep track of all the units that have infected a given unit.

For some victim with custom value UnitId, all units that infected this unit are stored in the unit group Infectors[UnitId]. When the victim dies, killing the infectors is a simple case of picking all units in Infectors[UnitId].

Just note that for unit group arrays to work properly, you need to set an array size in the variable editor (a few thousand is usually enough)

Thanks!
 
Don't do ruler's way. That's bad, do everything up until he tells you to use a few thousand in the unit group array size. You should use set udg_unitgroup[udg_tempinteger] = CreateGroup() instead. That way you can call DestroyGroup(udg_unitgroup[udg_tempinteger]) later and then set udg_unitgroup[udg_tempinteger] = null however remember that by default unitgroup[0] and unitgroup[1] are automatically made. tempinteger is a GUI integer variable where you set it to the units custom value to go with ruler's method. That way you can clean up the groups after they're no longer being used.

Ruler's way still works but you risk hitting the thread limit for WC3 which stops the current trigger and prevents it from running anything further beyond its limit/OP limit. however you shouldn't cost your players extra memory usage. It's unofficial however memory continues to build up so your RAM constantly increases until about 2GB then wc3 will just fatal on you or close. I haven't bothered trying to prove it however its easy enough to do so if your interested. Edit3: This may be just limited to leaks however I doubt it. Whatever is used continually adds up I am pretty sure. Otherwise WC3 RAM usage wouldn't be above a GB.

Edit: udg_unitgroup is a GUI unitgroup array variable.
Edit2: Crossed out my funny typo.
 
Last edited:
What does OP limit have to do with memory usage?

Yes, setting a large array size uses more memory than needed (an insignificant amount), but how can that possibly affect the OP limit?

:xxd: Sorry, tired. Still he shouldn't set it that way because he loses a lot of control over it then and may create many un-needed extra groups. A map shouldn't create extra left-over memory.
 
Level 8
Joined
Mar 12, 2008
Messages
437
Don't do ruler's way. That's bad, do everything up until he tells you to use a few thousand in the unit group array size. You should use set udg_unitgroup[udg_tempinteger] = CreateGroup() instead. That way you can call DestroyGroup(udg_unitgroup[udg_tempinteger]) later and then set udg_unitgroup[udg_tempinteger] = null however remember that by default unitgroup[0] and unitgroup[1] are automatically made. tempinteger is a GUI integer variable where you set it to the units custom value to go with ruler's method. That way you can clean up the groups after they're no longer being used.

Which value(s) does tempinteger take? I assume it starts at 0, increases every time a new group is created, and takes a new value whenever a lower one is available?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
You use a relationship table, a type of middle object in an object to object relationship which maps units to units. You then impose the appropriate cardinality restrictions (1 unit to 1 unit?). Since searching through such a table to find relationships can be resource intensive, you might want to use a hashtable to index elements of the table to the appropriate units.
 
Status
Not open for further replies.
Top