• 📚 A new project from the admin: Check out PictureBooks.io, an AI storyteller that lets you create personalized picture books for kids in seconds. Give it a try and let me know what you think!

Upgrade unit via python?

Lutefisk Mafia

Inscrutable Enforcer
Joined
Jun 15, 2007
Messages
544
Location
Minnesota
I actually asked this same question last year, and got an answer on how to do this in C++, but I am wondering if it is possible to force a unit to upgrade to a certain type via a python command.

I tried a:

pUnit.upgrade(gc.getInfoTypeForString('UNIT_CHAMPION'))

but nothing happened. Interestingly, it did not cause a python error, though.

Am I missing steps or do I need to use a different syntax? I would really like to avoid doing this the hard way: read out all of the experience and promos for the old unit, create a new unit, give all the same promos and experience, then kill the old unit.

Any advice?

PS - the code block above is showing a gap in the word "Champion" that doesn't really exist.
 
I think your problem is that it isn't a valid upgrade type. The first thing that happens in the DLL is it checks if the unit can upgrade to whatever you asked it to upgrade to, and if it cannot, it stops processing it. If you want to change a unit into a new unit which it cannot upgrade to normally, spawn a "blank" of the new unit type, then use pNewUnit.convert(pUnit)
 
So you could do a:

pUnit = [the unit I am trying to change]

pNewUnit = initUnit.[blah blah blah - forgot the syntax on this, but I've used it before]

pNewUnit.convert(pUnit)

If I am understanding correctly, this will transfer all of the experience, promos, and name over to the newly created "blank" unit?
 
Correct. And kill the old unit

I've been using the above method for some time now without killing the old unit and I don't appear to be having any problems. The old unit disappears and everything works. Should I be killing the old unit for some unseen reason like freeing memory?
 
Thanks, guys, this works great!

And, yes, the convert function does automatically kill the old unit.
 
Back
Top Bottom