• 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.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

[Trigger] Lose ability after X use (Same ability for several units)

Status
Not open for further replies.
Level 2
Joined
Aug 8, 2019
Messages
6
Hello there,

I am looking to make a trigger which count the amount of time an unit will use an ability, and after a certain amount of uses the unit loses his ability, my main problem, there are more than 1 type of this unit on the map and more can even be trained.

To make it clear : It's a dwarf unit which has an ability which is basically a Goblin Land Mine. I want theses dwarves to only be able to carry 2 mines, so after they dropped both of them on the ground, they lose the ability.

Making a single dwarf loses the ability isn't a problem, having an integer that count every dwarves on map and keeping in mind which one used 0, 1 or 2 times the Mine ability is.

For now my trigger is :
  • DworfMines
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Place Mine (Dworf)
    • Actions
      • Set VariableSet DworfMineCount = (DworfMineCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DworfMineCount Equal to 2
        • Then - Actions
          • Unit - Remove Place Mine (Dworf) from (Casting unit)
        • Else - Actions
          • Do nothing
So of course, making it run several times doesn't work if Dwarf A uses his mine, then Dwarf B uses his mine, Dwarf A and B both still have a mine but one of them would lose his ability.

I've been doing some tests, Adding all unit type of dwarves as an unit group, using an integer, but i still don't know how to read every dwarf.
The long way i could do it is making a single trigger for each dwarf on the map, but since it's a trainable unit from a barrack, this sould take for ever and will probly conflict in the end.

Help would be much appreciated :)
 
Level 25
Joined
Feb 9, 2009
Messages
1,798
Install Unit indexer, it will allow the trigger you posted to work with minor changes:
  • DworfMines
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Place Mine (Dworf)
    • Actions
      • Set VariableSet UnitIndex = (Custom value of Triggering unit)
      • Set VariableSet DworfMineCount[UnitIndex] = (DworfMineCount[UnitIndex] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DworfMineCount[UnitIndex] Equal to 2
        • Then - Actions
          • Unit - Remove Place Mine (Dworf) from (Triggering unit)
        • Else - Actions
          • Do nothing
 

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,761
Install Unit indexer, it will allow the trigger you posted to work with minor changes:
  • DworfMines
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Place Mine (Dworf)
    • Actions
      • Set VariableSet UnitIndex = (Custom value of Triggering unit)
      • Set VariableSet DworfMineCount[UnitIndex] = (DworfMineCount[UnitIndex] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DworfMineCount[UnitIndex] Equal to 2
        • Then - Actions
          • Unit - Remove Place Mine (Dworf) from (Triggering unit)
        • Else - Actions
          • Do nothing
Some additional things to note:

1) This is the Event you'll want to use in most cases for triggered spells:
  • Unit - A unit Starts the effect of an ability
This happens at the exact moment the ability executes and doesn't suffer from any exploits.

2) Unit Indexers, at least Bribes, will recycle unused Custom Values. This means that DworfMineCount[UnitIndex] could potentially get passed to a brand new Dwarf during the recycling process. As a result, whatever value the variable had before will be passed to the new Dwarf as well. You can fix this by setting DworfMineCount[] back to 0 when a Dwarf dies or during a De-Indexing Event.

3) "Do nothing" is a useless Action and is no different from a Comment.
 
Last edited:
Status
Not open for further replies.
Top