How to get average of all player levels?

Rakaesa

Member
Reaction score
5
So just as the title reads. How do I get the average level of all available player heroes?

EDIT: In case you needed to know, this is to spawn units around the map based on that average.
 

SerraAvenger

Cuz I can
Reaction score
234
Remember all heroes in an array. Whenever you need it, go through the array and add the level to some variable. Afterwards, divide the value of the variable by the number of heroes in the array.
 

Rakaesa

Member
Reaction score
5
Er, what exactly is an "Array"? It isn't in the list of variable types nor is it in events, conditions or actions. Or, that I can find that is. Also, i'm not even sure how to use an array either. Or what the script is to get the # of heroes in the game.

EDIT: Nevermind, i'm blind, I found the Array thing. But I still dont understand how to get it to know how many players are in the game.
 

inevit4ble

Well-Known Member
Reaction score
38
Ok well firstly you don't need to set the size of the array, it can be 1 but you can continually add to it. Point to note is that an array's increments start from 0 ie. array[0] is the first value of the array.

So what you can do is this
Trigger:
  • Actions
    • Set MyPlayerGroup = (All players controlled by a User player)
    • Player Group - Pick every player in MyPlayerGroup and do (Actions)
      • Loop - Actions
        • Set MyUnitGroup = (Units owned by (Picked player) matching (((Matching unit) is A Hero) Equal to True))
        • Unit Group - Pick every unit in MyUnitGroup and do (Actions)
          • Loop - Actions
            • Set HeroArray[(Player number of (Picked player))] = (Picked unit)
        • Custom script: call DestroyGroup(udg_MyUnitGroup)
    • Custom script: call DestroyForce(udg_MyPlayerGroup)

This will basical take all the units that each player, that is playing, owns and cycle through them set the HeroArray = to that unit. If each player only has one unit (their hero) then it will set that hero to the value in the array.

Then at any point you can access the hero by using the array. Array[0] value will = nothing but then 1 - X will equal the respective player's hero. So to access their levels you would make a loop running the amount of times equal to the number of players and do what was said above.
Trigger:
  • Actions
    • Set MyPlayerGroup = (All players controlled by a User player)
    • For each (Integer A) from 1 to (Number of players in MyPlayerGroup), do (Actions)
      • Loop - Actions
        • Set TempLevelTotal = (TempLevelTotal + (Level of HeroArray[(Integer A)]))
    • Set TempLevelAverage = (TempLevelTotal / (Number of players in MyPlayerGroup))
    • Custom script: call DestroyForce(udg_MyPlayerGroup)


Hope this helps :D
 

Rakaesa

Member
Reaction score
5
Bleh, still don't quite understand how that'll let the game know what the average level is, or how many variables I need.
 

huanAk

New Member
Reaction score
4
Global Variable : Hero_Group // keep all hero in this group
Global variable: Average_level // you can access average_level at anywhere of game :)
Global variable: Temp_integer

Trigger:
  • Actions
    • Set Temp_integer =0
    • Unit Group - Pick every unit in Hero_Group and do (Actions)
      • Loop - Actions
        • Set Temp_integer = Temp_integer + Level of (Picked unit)
    • Set Average_level = Temp_integer/ (number of unit in Hero_Group)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
Er, what exactly is an "Array"? It isn't in the list of variable types nor is it in events, conditions or actions. Or, that I can find that is. Also, i'm not even sure how to use an array either. Or what the script is to get the # of heroes in the game.

an array is a number used by a variable to store multiple data entries, the variable has a name and if array is checked in variable manager the array is the index of the variable
IE:
Trigger:
  • events
    • A unit enters playable map area
    • conditions
      • Triggering unit is a Hero is true (boolean condition)
    • actions
      • Set temp_group = units in playable map area
      • Unit Group - Pick every unit in temp_group matching condition, picked unit is a hero equal to true and Owner of picked unit is a player equal to true (conditions are in this order: And, Boolean, Boolean), and do actions.
        • Actions:
          • Set Heroes[index: player number of owner of picked unit] (unit variable with an index) = picked unit
      • Custom Script: Call destroyunitgroup(temp_group)

this is just an example of one way you can save every hero owned by a player in the map (if you want it to be every hero the index must be changed to something else, the custom script is to prevent leaks

then this trigger can find the average of their levels
Trigger:
  • events
    • your event where you need to find the average
    • conditions
    • actions
      • set real (real variable) = 0.00
      • set Division_Count (real variable) = 0.00
      • For Integer A from 1 to 12 (for player only) or (max ammount of heroes in the map), do actions.
        • Loop Actions
          • set real = real + Real(Level of unit for Heroes[integer A]) (integer to real conversion)
          • If then else
            • If
              • Heroes[integer A] is equal to no unit is false (boolean)
            • Then
              • Set Division_Count = Division_Count + 1.00
            • Else
      • Set real = real/Division_Count

and wah lah, the variable: real now is your hero level average and can be used right then, this will update with the heroes if it is triggered to work off multiple events
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top