.

Lord Olleus said:
I am trying to make a mod where a unit looses a ceratain promotion when it is upgraded. I know that the onUnitCreated() function is called on unit upgrade but i can't find a method which removes promotion. I tried isSetPromotion() with the second argument being False but it doesn't work. Does anyone know how to do this?
I guess that i could always add a second promotion that cancells the affect of the first one but that would just clutter the screen and doesn't seem like a very good way of doing this.

isHasPromtion just asks if the unit has it, you have to use setHasPromotion to give or remove promotions. This following code removes the Blessed promotion from pWinner:

Code:
		if pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BLESSED')):
			pWinner.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BLESSED'), False)
 
Lord Olleus said:
it seems that using false as the last argument does nothing. I changed the false to true and it added promotions to units when they where upgraded or built. However using false did absolutely nothing. Is it a bug?

Probably not a bug. The game probably just adds promotions defined in the Unit file after the onUnitcreated kicks. Instead of adding the promotion in the unit file and stripping it in onUnitCreate why don't you leave it out of the unit file and just add it when needed in onUnitCreate?
 
Lord Olleus said:
it seems that using false as the last argument does nothing. I changed the false to true and it added promotions to units when they where upgraded or built. However using false did absolutely nothing. Is it a bug?

It does work, I use this same method to add and remove promotions from units in the mercenaries mod. Are you sure you have the correct promotion string?
 
I just tried an experiment, I added:
Code:
if(unit.isHasPromotion(gc.getInfoTypeForString("PROMOTION_MEDIC1"))):
[TAB]unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_MEDIC1"), false)
else:
[TAB]unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_MEDIC1"),true)
to the onUnitSelected method in the CvEventManager.py file and it works fine for me. I checked over your code and I don't see anything wrong with your code.
 
The problem is this.

The unit being upgraded gets...
1) Created
-->Your onUnitCreated script runs
2) Promotions from old unit copied

So removing it in onUnitCreated does nothing. You can verify this by sweeping the existant promotions on the unit. However...

3) onUnitLost is triggered with old unit.
-->If you remove the promotions here, it should work.

You just have to tag and eliminate extraneous connections and store the id between calls in scriptdata of some object. Remember, when a unit is built, both unitCreate and unitBuilt are called. Promotion only triggers one. Similarly, units lost in battle trigger combatResults before unitLost. If you init units on your own, or barbarian units will trigger create without built, similarly, units destroyed by hand trigger lost without combat, so due diligence is required. You can test that the unit lost can upgrade to the unit created to verify that this was a result of an upgrade, and clear your tracking if any other create/built, etc. event triggers. That should be reliable in 99% of your cases, and probably won't cause any problems in your situation, even when it's wrong.

Alternatively, you can replace the upgrade button with a custom upgrade function, but then you have to decide when to upgrade for the computer.
 
Back
Top Bottom