Promotion for Units created with <UniqueNames>

isenchine

Empress
Joined
Oct 18, 2010
Messages
1,774
Location
Brussels, Belgium
Would it be possible in Python to automatically add a specific promotion to a newly created unit who has a <UniqueName>?

Could someone indicate to me how to proceed (I know very little in Python but I can modify a file)?

Thanks in advance!
 
If, like The_J said, only GPs have unique names in your mod, you can just use onGreatPersonBorn(), else use onUnitCreated()

Check length of getNameNoDesc().
If it is > 0, it has a unique name.
Add the promotion then.
 
@ The_J: We are in a "Creation & Customization" section, no? ;) I have added many names to many units!

@ Platyping: thank you for the tip! But so far it does not seem to work. That's what I have done to onUnitCreated in CvEventManager:

Code:
	def onUnitCreated(self, argsList):
		'Unit Completed'
		unit = argsList[0]
		player = PyPlayer(unit.getOwner())
		
		if unit.getNameNoDesc() > 0:
			unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_LEADERSHIP"), True)
		
		if (not self.__LOG_UNITBUILD):
			return

I got no error message (they are enabled).

And what's the difference with onUnitBuilt?
 
Now it seems to work!

I have inserted the same code in onUnitBuilt (where there was already added stuff from Baldyr and The_J's Warriors of God!) and it works!

Thank you very much for your help, Platyping :goodjob:.

But still, what is the difference between onUnitCreated and onUnitBuilt?

Edit: onUnitBuilt looks like it implies a City. Does it mean that onUnitCreated implies Units created outside a City? Barbarians?
 
I was too optimistic: it gives the promotion to all Units built in the City (not to Great Persons born in the City)... :sad:
 
Changed the code to

Code:
		if unit.getNameNoDesc() != "":
			unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_LEADERSHIP"), True)

and now it works!

Thanks again for pointing me in the right direction!
 
But still, what is the difference between onUnitCreated and onUnitBuilt?

Edit: onUnitBuilt looks like it implies a City. Does it mean that onUnitCreated implies Units created outside a City? Barbarians?

To answer a bit my own question, I had a Warrior created outside the City when I reached a Goody Hut for example. He had a Unique Name but did not get the Promotion, since he was created outside the City (code moved to onUnitBuilt).
 
1) You have to activate python callback to use onUnitCreated
2) if unit.getNameNoDesc() > 0: didn't work because that will give you a string.
You then have to use "len" to get the length of that string, to see if THAT is > 0.
3) onUnitBuilt only affects units BUILT in cities
onUnitCreated affects more than that.
Eg:
Drafted units
Great People
Captured Workers
Events
Python Created Units
 
Good to know!

For 1 & 3) now I understand. But onUnitBuilt is enough for me, I will not activate python callback for those cases.

For 2) I thought something was missing... but I guess now the result is the same.

Thank you.
 
Back
Top Bottom