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

Hashtable Unitgroup

Status
Not open for further replies.
Level 3
Joined
Apr 6, 2015
Messages
44
So was I looking at some Hashtable Tutorials, and couldn't find one about unit groups, so could anyone help me with something like that. It's not too complicated, fairly simple (Or so im hoping)

My idea was to create a unit that drops bombs as it travels in a straight line, and when it's done, all the bombs will explode. I can do that with just one unit dropping bombs, but I'm trying to make it MUI, and when I tried it, the bombs from multiple different cast's all exploded at the same time.

So all I really want to do is add each set of bombs to their own unit group, so they don't affect any other bomb sets. Any help is dearly appreciated.
 

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,266
Making bombs that explodes after a few sec individually would be much simpler to make MUI vise, but if you insist that all bombs explodes after a set duration, you can do following:

You can make a integer, a unit group array, and a dummy ability with 50 levels on triggering unit for trigger checking (Triggering Unit is viable).

  1. udg_BombArrayCount = INTEGER
  2. udg_BombGroup[50] = UNIT GROUP
  3. Any dummy ability that is invisible for the player (phoenix fire with 0 range, 50 levels, attacks nothing for example)

You can add a dummy ability with 50 levels on the caster when starting the spell, then using wait x seconds for the duration of the spell and then check the triggering unit which level of dummy ability triggering unit have then retrieve the level of that ability and then terminate all bombs in BombGroup[3] for example if the spell has been casted 2 times earlier and then remove the dummy ability from the caster. For every cast set BombArrayCount to BombArrayCount + 1. You can use this to set the dummy ability to that level and the array in the unit group is using for that unit. When it reach 50 set it to 0 again. You can set the value higher if more than 50 units in your map is doing that.

This isn't MUI in pure definition, but its crude and easy way of making it work.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I got a pretty neat solution to your spell. Provided that you got the bomb spawning and the movement working. I can do it for you if you have not come that far.

1. make the dummy unit move in a straight line.
2. spawn a bomb on top of the dummy unit
3. add a genetic expiration timer to the bombs.
4. make another trigger wtih the event a unit dies and check if the dying unit is a bomb
5. if it is a bomb deal damage to all units around it.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Add a group member to a normal ability instancing system. Remember to create groups upon instantiation and destroy them when done.

Start laying bombs cast -> create an instance
Periodically -> for all instances add a new bomb at the caster's current location
Stop laying bombs cast / maximum bombs reached -> explode them all and destroy instance.

I would recommend 3 members for the instances.
Unit Group "bombs" -> holds all bomb units
Unit "layer" -> holds the unit laying the bombs
Integer "number laid" -> keeps track of the number of units in "bombs" to avoid O(n) complexity counting.

You will also need an integer to keep track of the number of active instances (used to turn on/off the periodic trigger).

Unless you plan for hundreds of units to lay bombs all the time then no static references are required as you can use an O(n) linear search to locate the instance corresponding to the unit stop laying bombs event. Otherwise you will either need a separate integer array to create a "free list" or you could use the "number laid" integer array as a free list when an instance is freed (saves an array) and then you can use a hashtable to map units to their instances.

Any GUI instancing system should work, even ones which use custom values (not recommended).

Just remember that GUI unit group arrays start with index 0 to count filled with empty groups while indexes after that up to 8191 will be null so be careful not to leak groups from the array that are initially allocated and to allocate groups from new instances that need them. This can be as simple as testing if the allocated instance has their unit group member null or not. If null then set it to a new empty group. Otherwise if not then use the existing group. When you free/destroy the instance you can destroy the group and null the unit group member.
 

EdgeOfChaos

E

EdgeOfChaos

If you know the duration that the plane or whatever will fly, you can do it with expiration timers - the duration would be (endTime - curTime)
 
Status
Not open for further replies.
Top