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

[Solved] Remove Special Effect from 2 Units From a Unit Group Every X Seconds

Level 21
Joined
Dec 3, 2020
Messages
519
@Uncle I need you :'(

So for 1 of the maps I'm doing there are 30 villagers, after each one is captured I add him to VillagerArray[VillagerCount] (unit group array and integer) and then attach a special effect on that villager. I add 1 to the integer variable VillagerCount when the unit event happens (a hero casts a spell on him to entrap him) and also add him VillagerArray[VillagerCount] unit group and also a separate VillagerFinalGroup unit group.
I also store the special effect in a special effect array variable: VillagerNetSpecialEffect[VillagerCount]
I know how to remove all nets at once but my question is... I want to have 2 villagers have their special effect remove every 15 seconds, how do I do that?
Right now to remove all 30 nets I use:

  • Event
    • Time - Every 15.00 seconds of game time
  • Conditions (none)
  • Actions
    • For each (Integer A) from 0 to VillagerCount, do (Actions)
      • Loop - Actions
        • Special Effect - Destroy VillagerNetSpecialEffect[IntegerA]
        • Special Effect - Destroy VillagerNetSpecialEffect[VillagerCount]
I don't know which action to use exactly so I use both at the same time.
Any help is appreciated!!!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,557
I don't know which action to use exactly
Import a Unit Indexer into your map and attach the Special Effect to the Villagers like so:
  • Set Variable CV = (Custom value of Villager)
  • Special Effect - Create a Special Effect...
  • Set Variable VillagerNetSpecialEffect[CV] = (Last created effect)
Then when you want to destroy a Villager's special effect:
  • Set Variable CV = (Custom value of Villager)
  • Special Effect - Destroy VillagerNetSpecialEffect[CV]
Replace Villager with the specific unit that you want to reference. This could be (Triggering unit) or whatever, it'll change based on the Events of the trigger.

CV is an Integer variable, it's optional. I use it as a shortcut which is useful when you reference (Custom value of...) multiple times in a row.

The 2 Villagers which are "special" can be tracked in a unique Unit Group variable. Then you can Destroy their Special Effects like so:
  • Events
    • Time - Every 15.00 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in TwoVillagersGroup and do (Actions)
      • Loop - Actions
        • Set Variable CV = (Custom value of (Picked unit))
        • Special Effect - Destroy VillagerNetSpecialEffect[CV]
        • Unit Group - Remove (Picked unit) from TwoVillagersGroup
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,557
Hmm I see but is there something I'm missing? Because there are supposed to be 30 villagers and I need 15 groups of 2.
I'm okay with making 15 unit group variables etc...
Perhaps I shall do that...
I'm not too sure what you're trying to do here.

But I think I understand what you mean now. Here's how you can remove two Special Effects at random every 15 seconds:
  • Events
    • Time - Every 15.00 seconds of game time
  • Conditions
  • Actions
    • Set Variable Villager = (Random unit from VillagersGroup)
    • Set Variable CV = (Custom value of Villager)
    • Special Effect - Destroy VillagerNetSpecialEffect[CV]
    • Unit Group - Remove Villager from VillagersGroup
    • Set Variable Villager = (Random unit from VillagersGroup)
    • Set Variable CV = (Custom value of Villager)
    • Special Effect - Destroy VillagerNetSpecialEffect[CV]
    • Unit Group - Remove Villager from VillagersGroup
VillagersGroup would contain all of your Villagers. Add them when they become entrapped. You can also use a For Loop to run these Actions twice.

Or do you want it so that each Villager loses their Special Effect 15 seconds after being entrapped?

If yes, then you can use a basic Unit Indexing design where you have a Periodic trigger which loops through all of the Villagers and tracks their "net duration" using a Real array variable. Subtract from this Real each interval until it reaches 0 in which case you Destroy that unit's Special Effect.
 
Last edited:
Level 21
Joined
Dec 3, 2020
Messages
519
I'm not too sure what you're trying to do here.

But I think I understand what you mean now. Here's how you can remove two Special Effects at random every 15 seconds:
  • Events
    • Time - Every 15.00 seconds of game time
  • Conditions
  • Actions
    • Set Variable Villager = (Random unit from VillagersGroup)
    • Set Variable CV = (Custom value of Villager)
    • Special Effect - Destroy VillagerNetSpecialEffect[CV]
    • Unit Group - Remove Villager from VillagersGroup
    • Set Variable Villager = (Random unit from VillagersGroup)
    • Set Variable CV = (Custom value of Villager)
    • Special Effect - Destroy VillagerNetSpecialEffect[CV]
    • Unit Group - Remove Villager from VillagersGroup
VillagersGroup would contain all of your Villagers. Add them when they become entrapped. You can also use a For Loop to run these Actions twice.

Or do you want it so that each Villager loses their Special Effect 15 seconds after being entrapped?

If yes, then you can use a basic Unit Indexing design where you have a Periodic trigger which loops through all of the Villagers and tracks their "net duration" using a Real array variable. Subtract from this Real each interval until it reaches 0 in which case you Destroy that unit's Special Effect.
This is it! Thank you! I will test it later but looks like it's gonna work.
 
Top