OK, this is a port of a merc snippet I discovered. I don't recall the author, but the original file is available here. It adds a new flag to crits, "level", which sets that crit as able to advance a player. It also changed the levelup command so that you can only use it at a leveler crit.
There are optional portions of the code to force a character to only be able to levelup at a level crit of the character's race, and one for restricting it to crits higher than the character's level.
To make it easier, especially since there were word wrap issues in the posting, I'm uploaded the snippet as a text file at http://lair.moonwolf.net/snippets/leveler.txt.