Author Topic: Levelling and getting unit info  (Read 2271 times)


  • Guest
Levelling and getting unit info
« on: 22 April 2013, 21:03:47 »

In GAE, levels are customisable but based solely on the number of kills a player has made. However, in gaming not all kills are equal: killing a weaker unit shouldn’t bring with it the same benefits as killing a powerful unit.
I've searched the forums and see levelling is a popular subject but I was wondering whether there’s any way to consider EP or max-HP when a unit is killed? Then based on that it qualifies as one kill, five kills, ten kills etc.
The Scenario XML's Lua scripting allows you to run code when a unit is killed, but is there any way of using Lua to interrogate the stats of the unit that was killed (e.g. get its current EP or its max HP) and which unit/player killed  them? That way you could perhaps use Lua to grant an appropriate upgrade to the killing player.
Thanks for all the help.


  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Levelling and getting unit info
« Reply #1 on: 23 April 2013, 01:14:54 »
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".
« Last Edit: 23 April 2013, 01:20:59 by Omega »
Edit the MegaGlest wiki:

My personal projects:


  • Ornithopter
  • *****
  • Posts: 433
    • View Profile
Re: Levelling and getting unit info
« Reply #2 on: 23 April 2013, 01:27:47 »
I didn't want to bring up GAE's activity or other engines but, since Omega already did it first, I implemented a system that meets most of the requirements of Omega's plan. On-hit and unit type based experience for levels as well as many other significant changes. Sadly its not back-compatible with GAE because I drastically modified the EnhancementType class that is used with levels. This will be available in the Provisional Release of Mandate.


  • Guest
Re: Levelling and getting unit info
« Reply #3 on: 23 April 2013, 18:24:34 »
Thanks so much to both of you for the replies. Omega, your suggestion of using kills to 'push' extra levels is exactly what I had in mind - I know it's probably not as elegant, but it's workable. I hadn't realised MegaGlest had those functions (specifically being able to get the killing unit and ability to 'assign' kills) - I've been working with GAE exclusively as it has several other features that I couldn't find implemented out of the box with MG. While searching the forums, I did happen upon your thread about implementing an enhanced levelling system and thought it was great but couldn't see whether anything became of the suggestions.

So now am caught in the nomansland between GAE and MG each having a set of features I need - I know, I'm not the first ;)


  • Airship
  • ********
  • Posts: 3,391
  • The MegaGlest Moder.
    • View Profile
Re: Levelling and getting unit info
« Reply #4 on: 7 May 2013, 14:03:15 »
Well if you want lots of people(any) to use whatever you are making, I think your path is obvious...
Get the Vbros': Packs 1, 2, 3, 4, and 5!