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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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