| 07-17-2011, 10:56 PM | #2 |
A simple test shows that it is not possible to decrease a hero's experience directly. The native functions simply refuse to set a hero's experience to a new value if it is lower than the hero's current experience. The same is true for trying to set a hero's level, however the BJ function suggests there is a way: JASS:function SetHeroLevelBJ takes unit whichHero, integer newLevel, boolean showEyeCandy returns nothing local integer oldLevel = GetHeroLevel(whichHero) if (newLevel > oldLevel) then call SetHeroLevel(whichHero, newLevel, showEyeCandy) elseif (newLevel < oldLevel) then call UnitStripHeroLevel(whichHero, oldLevel - newLevel) else // No change in level - ignore the request. endif endfunction The UnitStripHeroLevel function lets you reduce a hero's level. You could use it to reduce the hero's level until his current experience is less than the target experience, then add the difference to reach the target. The problem is that UnitStripHeroLevel seems to have some unavoidable side effects. It will automatically unlearn abilities when the hero goes down a level. You can avoid this by adding a skill point to the hero before reducing his level, but in some cases an ability will still get unlearned so doing this is pointless. One case is if you already have all your abilities learned since in that case you can't add any more skill points to the hero. Another case is when the hero's level is reduced below the level skip requirements of an already learned ability. There's even a bug here that can cause your hero to loose skill points in some ability level requirements configurations. For example, if your hero can learn multiple abilities at level 1 that each have a 3 level skip requirement (WC3's default is 2), then if you save up your skill points you can get two abilities to level 2 once your hero hits level 4. If the level is decreased back to 3, both abilities will have their level decreased to 1, but the hero won't get one skill point back like he should (since he only went down one level, but had two skills deleveled). This is luckily not a problem with the default WC3 hero skill setup where you can't save up skill points in this way. So, the solution described earlier would need to save the ability levels of all hero skills on the hero (this means you'd need a database of all heroes and their skills). This is because the experience reduction we are aiming for will not necessarily take him down a level, so once we add the experience back to the hero to get the target reduction, the hero will gain the level back and get a skill point to spend. That'll look weird if you don't automatically spend it for him on the same ability that was lost when deleveling the hero, but to know which ability that was you need the database mentioned earlier. |
| 07-18-2011, 12:45 PM | #3 |
You can subtract experience, you just can't make a hero lose a level this way. Didn't read what Ani said but it's probably helpful, just wanted to add that. |
| 07-19-2011, 04:38 AM | #4 |
Well, it's at least as bad as I thought. I did figure out how exactly the experience required is calculated, but I'm not entirely sure it's worth the trouble to work all those calculations into a trigger. I do know that setting levels lower is possible, and I'm fairly familiar with it, since it exists in RP maps, which I used to play a fair amount of. If I remember right, a hero past the point of learning skills (i.e. a hero with 10 possible skill points at level 15) won't lose any skills as long as they don't level down past the last time they would have learned an ability (in this case, 10). I actually was okay with the hero unlearning spells when they leveled back down for the "Level Up" power, since those heroes are player-controlled and I figure any player should be able to remember or easily figure out what skill they would like to re-add when the power is reapplied or the hero naturally levels again. The big problem I haven't addressed at all (I wanted to work out the possibility/impossibility of the whole idea first) is that the enemy units are computer-controlled, so I would probably have to do the database thing if I really wanted them to relearn whatever abilities they had. To be honest, I'm not totally sure of the tactical usefulness of the Leveler hero to begin with, since literally all of this hero's skills are dedicated to leveling up/down other heroes. |
| 07-19-2011, 10:55 AM | #5 | ||||
Quote:
Quote:
Quote:
Quote:
|
| 07-19-2011, 01:13 PM | #6 |
I just tested AddHeroXP(someUnit, -100, false) and it worked. It even made the exp go below the required amount for level 2 (and below 0 too :o). SetHeroXP doesn't seem to be able to lower exp though. |
| 07-19-2011, 01:37 PM | #7 |
You're right, I only tested SetHeroXP. How foolish of me to expect some consistency out of Blizzard's natives. |
| 07-19-2011, 04:11 PM | #8 |
Subtracting hero XP is also pretty ugly as a consequence. I've used it before in my maps and it doesn't usually fit well. |
