Here is a very small galaxy library for messing around with experience and levels. I'll get around to GUIing and making an actual library and test map later.
// *Notes* // - You must create a dummy ability of type "Modify Unit" for these triggers to work.// - This assumes you have your veterancy ability using levels at xp amounts that can be defined by a formula (which you can change).// - It is possible to gain multiple levels at once using these triggers.// - If multiple levels are gained, triggers of type TriggerAddEventUnitGainLevel will only fire one time (not once per level)!// Change this to a defualt "Modify Unit" effectconststringc_xp_abil="AddXP";// Change this to match your xp leveling formula// This one generates the following values:// Level 1 - 100xp, Level 2 - 300xp, Level 3 - 600xp, Level 4 - 1000xp, Level 5 - 1500xp, etc.intGetXPNeededForLevel(intlevel){return(level*(level+1))*50;}voidHeroAddXP(unittarget,intamount){intplayer=UnitGetOwner(target);CatalogFieldValueSet(c_gameCatalogEffect,c_xp_abil,"XP",player,IntToString(amount));PlayerCreateEffectUnit(player,c_xp_abil,target);}intHeroGetRequiredXP(unittarget,intlevel){intcurXP=FixedToInt(UnitXPTotal(target));returnGetXPNeededForLevel(level)-curXP;}intHeroGetRequiredXPForNextLevel(unittarget){returnHeroGetRequiredXP(target,UnitLevel(target)+1);}voidHeroSetLevel(unittarget,intlevel){// Xp is applied 2 times to avoid interface bugsintxpNeeded=HeroGetRequiredXP(target,level-1);if(xpNeeded>0){HeroAddXP(target,xpNeeded);}HeroAddXP(target,HeroGetRequiredXP(target,level));}voidHeroLevelUp(unittarget,intnumLevels){HeroSetLevel(target,UnitLevel(target)+numLevels);}
I did it in GUI, with a couple bugs.
Your c_xp_abil variable seems to shift between an effect and a string. I don't think I can do that in GUI, so I used two variables, one string and one effect.
I couldn't find a UnitXPTotal function, just a Get Experience Level function. If it really doesn't exist, you'll have to set the curXP variable in HeroGetRequiredXP via custom script.
two switch between a string and an effect (game link) just do the following:
Create a new function definition, name it StringToEffect.
Create a Parameter and make it a String.
set the Return value to game link - effect (or whatever value is the correct one)
create 1 action: General - Return.
set the value at "General - Return" to (custom script bullet) lp_parameterName (replace parameterName with whatever text you see at the Parameter when you hit ctrl+d)
now you have a string to Effect converter.
you can do the same for the other direction. just alter the parameter type, and the return value type to match the correct data.
Here is a very small galaxy library for messing around with experience and levels. I'll get around to GUIing and making an actual library and test map later.
I did it in GUI, with a couple bugs. Your c_xp_abil variable seems to shift between an effect and a string. I don't think I can do that in GUI, so I used two variables, one string and one effect. I couldn't find a UnitXPTotal function, just a Get Experience Level function. If it really doesn't exist, you'll have to set the curXP variable in HeroGetRequiredXP via custom script.
@A52BcE: Go
two switch between a string and an effect (game link) just do the following:
now you have a string to Effect converter.
you can do the same for the other direction. just alter the parameter type, and the return value type to match the correct data.