• 🏆 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!

[JASS] Get Hero EXP %?

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
Hello everybody, I'm working on the UI of my map and my goal is to create a StatusBar that displays hp/mana/exp
so I far I successfully made it work like this:
hp-bar-numbers-jpg.328422


After that I made a third bar to show the exp of the unit.

My problem is that I want to make the exp bar show the percentage(%) of the hero's exp, not integers.
HeroEXPBar.jpg

The Picture above is how I want the bar to be, the 50% value was manually entered.

But I can't find any lines that can fetch that. For Health/Mana you just use:
JASS:
GetUnitLifePercent
GetUnitManaPercent
Another Idea I had was to get current exp and exp needed for level up and do the math to find the % but that still doesn't work because:
JASS:
GetHeroXP

Is the only hero exp line I could find..
For Health/Mana you have these:
JASS:
BlzGetUnitMaxHP
BlzGetUnitMaxMana
But AGAIN nothing for Hero EXP...It might just be me because I'm barely beginning to understand coding but I even searched GUI for hero % exp triggers and found nothing...

So yeah eventually I got annoyed and gave up so I came here in hope that somebody knows something and can help with my problem >_>

+rep to anybody that can help :thumbs_up:
 
Level 8
Joined
May 21, 2019
Messages
435
@The_Silent @Tasyen but that's a hassle >_< I will have to get hero lvl everytime and store all the exp in arrays =/

well anyway thanks for the help!
No? You can generate an array with a loop, since the hero exp increments follow a formula. Then use this array as a reference. This thing can be done fairly quickly.
 
If you have the hero selected and you don't need the exp% value in a mp sync manner. You could copy the value of the default exp bar which is a value form 0 to 1. That value can be read with BlzFrameGetValue(BlzGetFrameByName("SimpleHeroLevelBar", 0)).

If one hasn't the hero selected or Needs it mp save then one should have an array with the exp values for each Level. That Array can either be filled using math or by having a hero Level up from level 1 to max Level and saving current exp into an Array index is the current level.
Then one has the exp values.

For the current % of levelup one has to convert the total exp values in values that are about the difference of the current Level and the next Level. The old level is 0% and the next Level is 100%.
 
Level 20
Joined
Jul 12, 2010
Messages
1,717
well actually I have thought of a different way to do it.
HeroConstants.jpg
Since I am using this type of exp system in my map it's a lot easier.
Every hero level now requires 100 exp, creep kills give 2-5 exp depending on lvl difference.
Basically this way every 1 exp means 1%

and I used this:
JASS:
   local integer exp1 = GetHeroXP(u)
   local integer exp2 = (GetHeroLevel(u) * 100 )
   local string expm = I2S(exp1-exp2+100)
Now it works the way I want it to.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
One should be able to detect the experience per level via blackbox testing. Create any hero for any player, set the hero level to the desired level and then get the experience the hero has. These values can be cached in an array/table for faster access. The experience between levels can be calculated as the difference in total experience between the two levels.

I am aware algorithmic calculation of the experience would be faster and is what I personally recommend. However this is another obscure way one can do it.
 
Status
Not open for further replies.
Top