Finding the average level of heroes on map

mylemonblue

You can change this now in User CP.
Reaction score
7
What I am trying to accomplish is picking every individual hero on the map at game initialization (Not counting passive non-computer/player controled heroes). Now, every so often the game will get the average of their levels and then store it in a variable. At game start a bunch of level 1 creeps are on the map based off heroes and as the average level of the player controled heroes goes up, the creep hero's levels will go up.

Now, I was able to count the number of heroes

Trigger:
  • CountHeroes
    • Events
      • Time - Elapsed game time is 0.67 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Picked unit) is A Hero) Equal to (==) True) and ((Owner of (Picked unit)) Not equal to (!=) Neutral Hostile))) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to unitsGroup
      • Set avg = (Number of units in (Units in (Playable map area) matching (((Picked unit) is A Hero) Equal to (==) True)))


But the problem comes up when it comes time to average their levels. THere is currently three player owned heroes on the map. Right now they are pre-placed, but I want to try and figure out if, later, an additional player hero comes into the game. I figure I can add the preplaced ones into an array, but what about entering new ones? Something along the lines of this? ->

Trigger:
  • Untitled Trigger 002
    • Untitled Trigger 002
      • Events
        • Unit - A unit enters (Playable map area)
      • Conditions
        • ((Entering unit) is A Hero) Equal to (==) True
      • Actions
        • Set uHero[tmpInt] = (Entering unit)
        • Unit Group - Add uHero[tmpInt] to unitsGroup
        • Set tmpInt = ((Number of units in unitsGroup) + 1)



Whipped up in a moment of "Why didnt I think of that before posting this!?", but I still think there is a better way to go about this.
I'm confusing myself a little I guess.

When testing my original method which was more or less the same as the first trigger in the post except it was "avg = avg + 1", I would always get '0' when testing it with
Trigger:
  • TallyAverage Level
    • Events
      • Player - Player 1 (Red) types a chat message containing -avg as An exact match
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (String(avg))


The hero arena map Terminus Arena had a similar function which is what I am trying to recreate, but the map is protected (Thankfully. It is a great map.) and the author is no longer active and hasn't updated it in over a year it seems.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
There might be a better solution to this, as I just mixed something up quite fast here, but here's a version bound to work (Hopefully flawlessly, though not tested :D)

Trigger:
  • Average Level Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Heroes = (Units in (Playable map area) matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • Set Levels = (Levels + (Hero level of (Picked unit)))


Trigger:
  • Average Level Update 1
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • ((Triggering unit) is alive) Equal to True
    • Actions
      • Unit Group - Add (Triggering unit) to Heroes
      • Set Levels = (Levels + (Hero level of (Triggering unit)))


Trigger:
  • Average Level Update 2
    • Events
      • Unit - A unit leaves (Playable map area)
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • ((Triggering unit) is alive) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from Heroes
      • Set Levels = (Levels - (Hero level of (Triggering unit)))


Trigger:
  • Average Level Update 3
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • ((Triggering unit) is alive) Equal to True
    • Actions
      • Set Levels = (Levels + 1)


Trigger:
  • Average Level Print
    • Events
      • Player - Player 1 (Red) types a chat message containing -avg as An exact match
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (Average level of heroes in-game: + (String((Levels / (Number of units in Heroes)))))
 

mylemonblue

You can change this now in User CP.
Reaction score
7
Drat it still returns 0 every time I type in the chat string...

This is what I have as my initialization.
There are three heroes on the map owned by a player/computer.
Two belonging to Player 6 who is in a force with Player 1 (User) but is controlled by a computer slot. Player 2 is allied with Neutral Hostile, and Neutral Hostile has 1 Hero. I have not yet gotten around to making every creep a "Hero" yet though.

Trigger:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Heroes = (Units in (Playable map area) matching ((((Picked unit) is A Hero) Equal to (==) True) and (((Picked unit) is alive) Equal to (==) True)))
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • Set Levels = (Levels + (Hero level of (Picked unit)))
      • Set tmpInteger = 0
      • Set DevourCount = 0
      • Set SpellsCast = 0
      • Set SpellsCast = 0
        • Do Multiple ActionsFor each (Integer A) from 0 to 11, do (Actions)
          • Loop - Actions
            • Set Kill_Count[(Integer A)] = 0
            • Set losses[(Integer A)] = 0
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
        • Loop - Actions
          • Set GraveyardPoints[tmpInteger] = (Position of (Picked unit))
          • Set GraveyardUnits[tmpInteger] = (Unit-type of (Picked unit))
          • Unit - Set the custom value of (Picked unit) to tmpInteger
          • Set tmpInteger = (tmpInteger + 1)
      • -------- Define pre-placed heroes --------
      • Set cpuHero[0] = Kodo Rider 0066 <gen>
      • Set cpuHero[1] = Troll Shadow Priest 0149 <gen>
      • Set cpuHero[2] = Paladin 0006 <gen>
      • -------- Setup colors for multiboard --------
      • Set Player_Colors[1] = |c00ff0000
      • Set Player_Colors[2] = |c000000ff
      • Set Player_Colors[3] = |c0000ffff
      • Set Player_Colors[4] = |c00800080
      • Set Player_Colors[5] = |c00ffff00
      • Set Player_Colors[6] = |c00ff8000
      • Set Player_Colors[7] = |c0000ff00
      • Set Player_Colors[8] = |c00ff00ff
      • AI - Start melee AI script for Player 6 (Orange): war3mapImported\cityscapeKotoTest.wai
      • Melee Game - Use melee time of day (for all players)
      • Player - Make Player 2 (Blue) treat Neutral Hostile as an Ally with shared vision
      • Player - Make Neutral Hostile treat Player 2 (Blue) as an Ally with shared vision
      • Player - Make Player 8 (Pink) treat Neutral Hostile as an Ally with shared vision
      • Player - Make Player 8 (Pink) treat Player 1 (Red) as an Enemy with shared vision
      • Player - Make Player 8 (Pink) treat Player 2 (Blue) as an Enemy with shared vision
      • Player - Set Player 1 (Red) Current gold to 75
      • Player - Set the current research level of Fragmentation Shards to 1 for Player 2 (Blue)
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Visibility across (Playable map area)
      • Visibility - Create an initially Enabled visibility modifier for Player 6 (Orange) emitting Visibility across (Playable map area)
      • Visibility - Create an initially Enabled visibility modifier for Player 8 (Pink) emitting Visibility across (Playable map area)
      • Wait 2.00 seconds
      • Trigger - Run guardtower train <gen> (ignoring conditions)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Code:
Set Heroes = (Units in (Playable map area) matching ((([COLOR="Red"](Picked unit)[/COLOR] is A Hero) Equal to (==) True) and (([COLOR="Red"](Picked unit)[/COLOR] is alive) Equal to (==) True)))

I think you need to take a look at my trigger again ;)
 

mylemonblue

You can change this now in User CP.
Reaction score
7
Durrr! I feel a little awkward now :p

I forgot I wasn't working with adding units to a Unit Group xD

Thanks, it works now. It's still taking into consideration the level 60 hero belonging to Neutral Hostile, but a quick boolean check should fix that.

+rep
\
Minor note, when I first type -avg it shows 0 and then on a new line the actual average. Dunno why, though.

Hmm... On the subject of hero levels... Recreating Zodiark's Level 3 Break, Level 4 Immobilize and Zelera's Prime Level Death? :p

(Break turns a unit to stone. Immobilize makes it so they can act but not move. Death does just that.)

Level 3 Break takes every unit in range of the target location and calculates if that unit's level is a multiple of 3. If it is, it's a 100% Stone effect. If not, theyre immune.

Level 4 Disable is the same, but for the disable effect.

Prime Level Death is tricky. Might not be possible in WC3 short of adding each number in by hand. It calculates whether or not if the unit's level is a prime number. If so, the unit dies. No questions asked. Immunities ignored. Undead or otherwise. If not, then they are immune.

Zodiark and Zelera are from FF XII and was the first game I have played that had level based spells (AND WHERE BEING AT 99 IS A BAD THING WHEN FIGHTING A BOSS)
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top