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

[General] Pick Units + Loop

Status
Not open for further replies.

sentrywiz

S

sentrywiz

Can I pick units and then somehow add them to array vars?

I guess I just don't understand how picking units work.
Is it like a loop, picking each unit at a time? Or its picking
all units at the same time? I want to implement both because
I need to fill array vars with the unit's position, face angle and type.

So at the start of the game, I want to pick all neutral hostile units
then assign three array variables to each, but I'm confused cuz idk
what to put in the array space. Its not player number of owner of picked unit
or Integer A/B. So what do I put there?

If you're wondering - I'm making my own creep revival system.
Because I have multiple unit types, I want them to revive at
certain periods rather than each every X seconds.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Picking every unit does loop through them.

For the index, I recommend a unit index system (uses unit custom value) as it makes things very easy.

If for some reason you can't use custom values, you could manually index them:
Pick every unit and do:
- Set IndexMax = IndexMax + 1
- Set Creep[IndexMax] = picked unit
- Set OtherData[IndexMax] = etc

When e.g. a creep dies and you want to know which one it was, you loop from 1 to IndexMax and compare Creep[Loop] to dying unit.
 

sentrywiz

S

sentrywiz

Picking every unit does loop through them.

For the index, I recommend a unit index system (uses unit custom value) as it makes things very easy.

If for some reason you can't use custom values, you could manually index them:
Pick every unit and do:
- Set IndexMax = IndexMax + 1
- Set Creep[IndexMax] = picked unit
- Set OtherData[IndexMax] = etc

When e.g. a creep dies and you want to know which one it was, you loop from 1 to IndexMax and compare Creep[Loop] to dying unit.

So pick units is a loop and I can use an incremental integer?
Okay, I'll give that a try.

EDIT:

Will this work?
  • SetNeutralCamps
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set tempGroup = (Units owned by Neutral Hostile)
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Set CREEP_Index = (CREEP_Index + 1)
          • Set CREEP_Unit[CREEP_Index] = (Picked unit)
          • Set CREEP_Loc[CREEP_Index] = (Position of (Picked unit))
          • Set CREEP_Angle[CREEP_Index] = (Facing of (Picked unit))
          • Set CREEP_Timer[CREEP_Index] = (Expiring timer)
      • Custom script: call DestroyGroup ( udg_tempGroup )
 
Yes, that's the correct idea.

If you can't ensure "CREEP_Index" was used before I would set it to "1" before the enumeration.

Creating your timer won't work. You will need a custom script for it:
set udg_CREEP_Timer[udg_CREEP_Index] = CreateTimer()
Though for index "0" and "1" the timer does alread exist.
But you can compare the index or compare if timer exists for not overriding existing timers.
 

sentrywiz

S

sentrywiz

Yes, that's the correct idea.

If you can't ensure "CREEP_Index" was used before I would set it to "1" before the enumeration.

Creating your timer won't work. You will need a custom script for it:
set udg_CREEP_Timer[udg_CREEP_Index] = CreateTimer()
Though for index "0" and "1" the timer does alread exist.
But you can compare the index or compare if timer exists for not overriding existing timers.

Okay.

The timer isn't important in the loop. I can start it when a unit dies.
 

sentrywiz

S

sentrywiz

If you set the initial value to "20" in variable editor it will probably work, too.
So it will create timers until the index "20".

But if you want it more dynamic you can create them via custom script as shown above.
Because I guess you don't always want to count all hostile creep units each time you make changes. :)

That's true. I was lucky enough to a degree to know my number of creeps.

But say I didn't. And there were around idk 50+. Since I would need to specify the timer expired in the event "Timer[1], Timer[2]...". Is there a better way to outlay the timers expired in the event other than manually put them in?
 
Status
Not open for further replies.
Top