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

[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 24
Joined
Feb 9, 2009
Messages
1,787
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 64
Joined
Aug 10, 2018
Messages
6,534
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