• 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.

Add unit to the Unit Group other unit is in

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Title says it.

I have a hero in Wood[0], when the hero dies I want to create a shade in it's position, and add the shade to the same group the hero is in. Just like if the shade was the hero.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Then you just call the native to add a unit to a group passing it the arguments of the shade unit and the group the hero is in. As you added the hero to the group earlier you already know what group the hero is in so you can just specify that.

If what you meant to ask was:-
How can I get a list of groups that a specific unit is in?
Then there is no direct way. You can however script a system (using dynamic storage like arrays and hashtables) so as to map a list of groups to a unit and control this mapping using custom adapters to the add to and remove from group natives.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
OK. A bit more info. Sorry for that. I manage combat with Group arrays, using 5 values.

Wood[0] Is for the Heroes in the 'World Map' <- These units have a change to engage combat.
Wood[1] Are the alive Creeps. <- Used to Count the Alive Creeps left to kill in the combat.
Wood[2] Are the heroes in the region where heroes fight with creeps
Wood[3] Are the heroes in the Circle of Power where they have to stand to restore their original positions in the World Map, and be added to Wood[0] again.
Wood[4] Are all the Neutral Hostile creeps are (Alive and dead) that are removed when all the heroes leaves the region.

When hero engages combat, I remove it from Wood[0] and add it to Wood[2]. When the hero leaves the combat region, I remove it from Wood[2] and add it to Wood[0] again.

When all the heroes in combat stand in the exit, their positions are restored using this condition:
  • (Number of units in Wood[2]) Equal to (Number of units in Wood[3])
The same happens with other regions (Beach, Swamp, City, Dungeon, etc.)

The thing is that when the hero dies, it's removed from all these groups. If I create a shade where the hero died, I need to add the shade to the same group the hero was in, so it can leave the combat region and go to a town to revive.

@Spinnaker: That's the problem :)
@Troll-Brain: No, i'm not =/
@Dr Super Good: You are too Super Good for me to understand what you said xD But thanks :D


While I was writing this I came with the idea of just reviving the hero just where it died, change it's transparency to 50%, disable all spells, attacks, items, etc., so it would me some kind of 'Dummy' hero, and restore all those values when the hero 'revives' (in town, with skill, or with item), and change it's model to the shade.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
You could alternativly just add the shade logic steps into the group removal logic. You can test which group the hero is in before removing it from the group and then create the shade and add it to that group. After that you can remove it from the group as the shade will be in the group already.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I'm a bit ashamed, but, I think that I was drowning in a water drop... There are several ways to do something similar in a more easy and efficient way.
 
Level 9
Joined
Apr 26, 2011
Messages
403
Trigger:
Event -- when unit is dies
Condition -- dying unit is Hero (or your own rules)
Action --
replace dying unit with unit type of Shade for player(owner of dying unit)
remove dying unit to Wood[0]
add last replaced unit to Wood[0]

finish !!

PS: when unit dies, it still in game as "corpse" for next few second, so you can still call "replace dying unit with unit type of Shade"
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Trigger:
Event -- when unit is dies
Condition -- dying unit is Hero (or your own rules)
Action --
replace dying unit with unit type of Shade for player(owner of dying unit)
remove dying unit to Wood[0]
add last replaced unit to Wood[0]

finish !!

PS: when unit dies, it still in game as "corpse" for next few second, so you can still call "replace dying unit with unit type of Shade"

What if the unit is not in wood[0] but in Beach[2], or Swamp[0], or Castle[2], etc...?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
What if the unit is not in wood[0] but in Beach[2], or Swamp[0], or Castle[2], etc...?
What "Beach", "Swamp" or "Castle"? You have not mentioned those before so how are we meant to know about them.

You just need to hard code the group logic for the various cases. Although this can result in a lot of code parallelisim (procedural coupling which is bad scripting practice) but should still work perfectly fine.

A more efficient system might be possible with a single array and assigning various map areas (which I assume by the names is what you want) to certain ranges in this array (like an offset).
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hehe... well.. right now I went deep, deep, deeep to the basics... Just revived instantly, casted a two hour duration Ethereal over the unit, and disabled all skills.

Unit cant cast, cant attack, can't... pretty much anything... and I found a good secondary effect: using 'dead' buff I can make interesting things.. Thanks everyone for trying to help.

@DrSuperGood:
Spartipilo said:
The same happens with other regions (Beach, Swamp, City, Dungeon, etc.)
Post #5, under the trigger example. :)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Post #5, under the trigger example. :)
Hmm must have overlooked that line....

Hehe... well.. right now I went deep, deep, deeep to the basics... Just revived instantly, casted a two hour duration Ethereal over the unit, and disabled all skills.
Sometimes setting duration to 0 will make the buff last infinitly for a certain ability. A common example is a duration of 0 on any move that stuns will permantly stun a unit. This (or trigger logic to recast the buff if this does not work on banish) is required inorder to prevent bugs (whereby people do wait a stupid length of time like 2 hours).
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I'll test with the 0 duration :). If someone wants to wait 2 hours... first he/she has to know the dead effect lasts two hours :) And, certainly deserves it xD Thanks for the suggstion.

EDIT: People can now wait two hours to revive, since it lasts forever (Used 0 duration. Thanks)
 
Status
Not open for further replies.
Top