There's
no current way to replicate the effects of leveling up with Lua. I did make a
detailed proposal for improving the leveling system, but GAE is currently
inactive and may or may not be updated in the future. It is still possible that such a system would be implemented in MegaGlest in the future, but currently the leveling system works the same there.
Technically,
MegaGlest has some Lua functions that could be used to simulate leveling, but it would be complex and dirty. Running on the
<unitDied> event, when a unit is killed, use
lastDeadUnitCauseOfDeath() to verify they died from an attack. Now use
lastDeadUnitKiller() to find the unit who killed the dead unit. Based on the type of unit that was killed (found via
lastDeadUnitName()), you can assign "experience points" by giving them a number of kills via
giveKills(). In order for this to be of any use, you'd probably want levels to need a large number of kills (say, 20) and use
giveKills() to give an arbitrary number of kills based on the type of unit (a worker might be worth one kill and a dragon might be worth ten). So it's not treating them like "kills", but rather "experience points".
EDIT 01:19 UTC: also bear in mind that the killing unit defaultly gets one kill. So you should be giving
extra kills based on the unit type. A pig might not get any extra kills (so they're just worth the default 1), while an airship might get 19 extra kills (for a total of 20 kills). Again noting that "kills" is synonymous with "experience points".
This isn't flawless, namely with how your experience points are incorrectly named "kills" and that if the kills needed to level up is large, playing without the scenario will result in the leveling system being pretty much useless (so this system HAS to edit the unit XMLs). And as mentioned, this is MegaGlest only. The functions needed for this system cannot be replicated in GAE and based on the fact GAE hasn't had a release in over a year, I doubt it ever will be possible.
It's also
not possible to use a damage based experience system as I detailed in my previously linked proposal. To do that, we would need a way to get a unit's health, a unit's maximum health, and preferably a way to get the damage dealt by the last attack (although we could technically use an array for the health at the last function call and use basic mathematics to find how much damage was dealt, but that'd be less efficient). We could then use a similar system to the above described kill-experience system, but running on the
<unitAttacking> event. So when a unit is attacked, they're given experience based on the damage they dealt as a percentage of the total health and an assigned experience value (which is simply stored in the Lua script by checking the name of the last attacked unit with
lastAttackedUnitName()).
So there's technically only tiny hurdles preventing a versatile experience based system from being implemented (a way to get the unit's health, their maximum health, and optionally the damage dealt by the last attack). Granted, it's probably not that efficient. Not to mention it's a pain in the ass for modders, since they give unit's "experience values" in a Lua script instead of the unit XML (where it should be), not to mention the need to use a script for the system to be work (and the levels will be broken without using the script). Actually, it would be really awesome if modders could specify a Lua script to run with a faction *always*. But I'm rambling, now.
TL;DR: It is *not* currently possible to do what you described in GAE. MegaGlest has the tools to roughly replicate what you're asking for, though neither engine could quite do a leveling system based on damage instead of "lucky killing blow".