• 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.

Custom button to apply random buff to a random unit

Level 1
Joined
Sep 8, 2024
Messages
3
Ok so I am rather new to the world of the WC3 Editor tool, and maybe I have starting with something over-complicated for a noob like me , but basicaly I am trying to do something that when you are researching an ugrade in your base called "Random Buff" you get a Random Buff to a Random units , for now My Random Units are spawning well this is working, I figured out how to apply a Random Buff to a Random Unit but here is my problem , I can't find a way to put the Random Buff on an already spawned Units and I can't store the information so the next same-type of units spawning also have the buff , Can someone help me please ? I have tried so many things for 2 days and nothing is working like I want to !

Also these are my Variables :
1725825681471.png
 
Last edited:
Level 11
Joined
Nov 15, 2007
Messages
800
First off, your map has a LOT of leaks. Check out Things That Leak or the map will become laggy and nonfunctional over time.

As for why the random buff triggers don't work,
  • Upgrades Copy
    • Events
      • Game - Button for Research Random Buffs pressed.
    • Conditions
    • Actions
      • Set VariableSet UnitCount = (Number of units in (Units owned by Player 1 (Red).))
      • Set VariableSet DiceRoll = (Random integer number between 1 and 5)
      • Set VariableSet UnitRoll = (Random integer number between 1 and UnitCount)
      • Set VariableSet ChosenUnitType = RandomUnits[UnitRoll]
RandomUnits[UnitRoll] is going to return a totally nonsensical result because you set up RandomUnits in a specific way in another trigger where each number corresponds to a unit type. So if the player's only units are 5 tauren, it will roll a number between 1 and 5, but Tauren is RandomUnits[10] therefore the chosen type will never actually be tauren.

  • Set VariableSet ChosenAbility = RandomAbilities[DiceRoll]
  • Set VariableSet RandomAbilities[1] = Devotion Aura
  • Set VariableSet RandomAbilities[2] = Trueshot Aura
  • Set VariableSet RandomAbilities[3] = Endurance Aura
  • Set VariableSet RandomAbilities[4] = Brilliance Aura
  • Set VariableSet RandomAbilities[5] = Vampiric Aura
Here you're setting the chosen ability before the random ability variables have been set, so the first time this trigger runs it won't work. These random ability variables should be set at the start of the game instead.

  • Set VariableSet Part1 = Buff Applied :
  • Set VariableSet Part2 = (Name of ChosenAbility)
  • Set VariableSet Part3 = to unit :
  • Set VariableSet Part4 = (Unit: (Triggering unit)'s String Field: Proper Names ('upro'))
Here, there is no (Trigger unit) for the string to name.
  • Unit Group - Pick every unit in (Units owned by Player 1 (Red).) and do (Actions)
    • Loop - Actions
      • If ((Unit-type of (Picked unit)) Equal to ChosenUnitType) then do (Unit - Add ChosenAbility to (Picked unit)) else do (Do nothing)
      • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: ((Part1 + Part2) + (Part3 + Part4))
This will, more often than not, fail to work for the reasons outlined earlier - ChosenUnitType doesn't actually correspond to the unit type being selected.
  • Upgrade Register
    • Events
      • Unit - A unit enters Player1RegionCreep <gen>
    • Conditions
      • HasUpgrade[UnitRoll] Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Triggering unit)) Equal to Player 1 (Red)
        • Then - Actions
          • If ((Unit-type of (Triggering unit)) Equal to ChosenUnitType) then do (Unit - Add ChosenAbility to (Triggering unit)) else do (Do nothing)
          • Set VariableSet HasUpgrade[UnitRoll] = True
        • Else - Actions
          • Do nothing
HasUpgade[UnitRoll] is never set true anywhere but this trigger, and since it has to be true for this trigger to run, the trigger will never run.

Additionally ChosenUnitType and ChosenAbility will be overwritten whenever the random buff is researched, so even with the conditions fixed it will only work if the spawned unit is the most recently buffed unit type and will only buff it with the most recently chosen ability.

For what you want to do I think the most sensible way is to use hashtables rather than arrays. Here's a basic explanation of how they work Hashtables and MUI
 
Level 1
Joined
Sep 8, 2024
Messages
3
First off, your map has a LOT of leaks. Check out Things That Leak or the map will become laggy and nonfunctional over time.

As for why the random buff triggers don't work,
  • Upgrades Copy
    • Events
      • Game - Button for Research Random Buffs pressed.
    • Conditions
    • Actions
      • Set VariableSet UnitCount = (Number of units in (Units owned by Player 1 (Red).))
      • Set VariableSet DiceRoll = (Random integer number between 1 and 5)
      • Set VariableSet UnitRoll = (Random integer number between 1 and UnitCount)
      • Set VariableSet ChosenUnitType = RandomUnits[UnitRoll]
RandomUnits[UnitRoll] is going to return a totally nonsensical result because you set up RandomUnits in a specific way in another trigger where each number corresponds to a unit type. So if the player's only units are 5 tauren, it will roll a number between 1 and 5, but Tauren is RandomUnits[10] therefore the chosen type will never actually be tauren.

  • Set VariableSet ChosenAbility = RandomAbilities[DiceRoll]
  • Set VariableSet RandomAbilities[1] = Devotion Aura
  • Set VariableSet RandomAbilities[2] = Trueshot Aura
  • Set VariableSet RandomAbilities[3] = Endurance Aura
  • Set VariableSet RandomAbilities[4] = Brilliance Aura
  • Set VariableSet RandomAbilities[5] = Vampiric Aura
Here you're setting the chosen ability before the random ability variables have been set, so the first time this trigger runs it won't work. These random ability variables should be set at the start of the game instead.

  • Set VariableSet Part1 = Buff Applied :
  • Set VariableSet Part2 = (Name of ChosenAbility)
  • Set VariableSet Part3 = to unit :
  • Set VariableSet Part4 = (Unit: (Triggering unit)'s String Field: Proper Names ('upro'))
Here, there is no (Trigger unit) for the string to name.
  • Unit Group - Pick every unit in (Units owned by Player 1 (Red).) and do (Actions)
    • Loop - Actions
      • If ((Unit-type of (Picked unit)) Equal to ChosenUnitType) then do (Unit - Add ChosenAbility to (Picked unit)) else do (Do nothing)
      • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: ((Part1 + Part2) + (Part3 + Part4))
This will, more often than not, fail to work for the reasons outlined earlier - ChosenUnitType doesn't actually correspond to the unit type being selected.
  • Upgrade Register
    • Events
      • Unit - A unit enters Player1RegionCreep <gen>
    • Conditions
      • HasUpgrade[UnitRoll] Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Triggering unit)) Equal to Player 1 (Red)
        • Then - Actions
          • If ((Unit-type of (Triggering unit)) Equal to ChosenUnitType) then do (Unit - Add ChosenAbility to (Triggering unit)) else do (Do nothing)
          • Set VariableSet HasUpgrade[UnitRoll] = True
        • Else - Actions
          • Do nothing
HasUpgade[UnitRoll] is never set true anywhere but this trigger, and since it has to be true for this trigger to run, the trigger will never run.

Additionally ChosenUnitType and ChosenAbility will be overwritten whenever the random buff is researched, so even with the conditions fixed it will only work if the spawned unit is the most recently buffed unit type and will only buff it with the most recently chosen ability.

For what you want to do I think the most sensible way is to use hashtables rather than arrays. Here's a basic explanation of how they work Hashtables and MUI
Ok thanks I'll look forward to it !
 
Top