Scripts:Custom experience to level formula
The OHRRPGCE does not yet support changing the amount of experience needed to level up. In the meantime, you can use this script to customise the formula! Since the player sees only the amount of experience left to level for each hero, this script works by manipulating a hero's current experience to change the amount left to go to level up, which is at a total amount fixed by the engine.
However, this script is not perfect: it's only suitable if you avoid multiple levelling in battles (see below)
This script was originally used in Gerania (and has therefore been tested to work).
If you are looking to learn advanced plotscripting, look elsewhere, even the author doesn't understand this script anymore.
First modify experience formula to customise the formula. The one below, used in Gerania, is slightly different to the default one.
When a new hero is added to the party, you should call correct xp to level with their id. Eg:
add hero (hero: Bob) correct xp to level (find hero (hero: Bob))
After an event in which a hero might level, either after a battle or after a set hero level or give experience command, check and correct xp should be called. Eg.
fight formation (34) check and correct xp
Things to watch out for
The script only sets the experience to next level. When a hero levels, the experience to the next level isn't corrected until the script runs again. So if a hero gains more than enough to level, they might gain several levels when they shouldn't, or don't gain as many as they should. In battle the gained levels and learnt spells would then be announced incorrectly.
For example, suppose your formula requires 10,000xp to level one, and a level zero hero has 9,000xp and gains 1,500xp. They'll gain a level plus 500xp to the next one. But according to the built in formula, 500xp past level one is enough to get you to level six! The opposite situation is also a problem.
The script WILL handle these cases, and sort out the correct level, experience and learnt spells correctly after the battle, but it is obviously massively confusing to players.
The total experience and experience to level commands will not work correctly. experience to next level, hero levelled and get hero level will work. set experience and give experience can be used if you call check and correct xp afterwards.
script, check and correct xp, begin variable (i) for (i, 0, 40) do ( if (hero by slot (i) <> -1) then ( if (hero levelled (i)) then (correct xp to level (i)) ) ) end script, correct xp to level, hero, begin variable (level, earned xp, levelled) # REAL number of levels gained levelled := hero levelled (hero) level := get hero level (hero) # xp earned on top of the (first) levelup earned xp := 0 if (levelled >> 0) then ( level := level -- levelled + 1 earned xp := total experience (hero) -- experience to level (level) set hero level (hero, level, true) ) give experience (hero, experience to next level (hero) -- experience formula (level + 1) + earned xp) if (hero levelled (hero)) then (correct xp to level (hero)) # just in case you want to use the herolevelled command, recursively set correct # levelled amount (undocumented stat tinkering!) if (levelled >> 0) then (set hero stat (hero, 12, hero levelled (hero) + 1, 1)) return (earned xp) end # this returns the experience to reach a level from the last one. (so call with a minimum level of 1) # customise this script. script, experience formula, level, begin # example formula: # amount to level 1 = 30 # amount to level x>1 = amount_to_last_level * 1.1 + 5 variable (i, exp) exp := 30 for (i, 2, level) do (exp += exp / 10 + 5) return (exp) end
Here's another example experience script (though hardly recommended):
script, experience formula, level, begin # example formula: level * (10 + level) return (level * (10 + level)) end