• 🏆 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] Assigning Custom Value in Loop

Level 12
Joined
May 7, 2008
Messages
334
EDIT: Seems that this Custom Value for Units loop is working for now, but I'd still like if someone could check it out please.

Hero_Loop is set to 3 cause that's the number of heroes in the map at the moment :I



  • Init Heroes
  • Set VariableSet Hero_Type[1] = Peewee
  • Set VariableSet Hero_Type[2] = Forest Sentinel
  • Set VariableSet Hero_Type[3] = Zandalari Troll
  • Pick a Hero Dota Style
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to Hero Tavern
    • Actions
      • -------- Setting up basic Variables --------
      • Set VariableSet Hero_Picker = (Buying unit)
      • Set VariableSet Temp_Player = (Owner of Hero_Picker)
      • Set VariableSet Player_Number = (Player number of Temp_Player)
      • Set VariableSet Hero = (Sold unit)
      • -------- --------
      • -------- Set Custom Values for Each Hero --------
      • -------- --------
      • Set VariableSet Hero_Loop = 3
  • For each (Integer A) from 1 to Hero_Loop, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of Hero) Equal to Hero_Type[(Integer A)]
        • Then - Actions
          • Set VariableSet Hero_Unit_ID[(Custom value of Hero)] = (Integer A)
          • Game - Display to (All players) the text: (String((Integer A)))
        • Else - Actions
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,567
When you say Custom Value everyone is going to assume you mean this:
  • Unit - Set custom value of (some unit) to X
The already built-in function.

But yes, you're correctly assigning a "custom value" to your purchased hero based on it's Unit-Type. You're doing so using the Unit Indexing method, which relies on the aforementioned Custom Value property, which in this case will be automatically assigned by a Unit Indexing system that you have imported into your map.

Also, careful with relying on (Integer A), it should be alright but generally you want to use your own Integer variable. Additionally, I would put Hero_Loop in the Init trigger and name it something more appropriate like Total_Hero_Types or Hero_Total_Types. That way whenever you add a new Hero to the Init trigger you can also increase the "total" by 1 in that very same trigger. The end goal being a seamless process where changes in your Init triggers automatically update all of the other triggers that rely on them.
 
Last edited:
Top