Help with onUnitBuild

SaibotLieh

Emperor
Joined
Sep 25, 2009
Messages
1,576
Im toying a bit with python at the moment and now want to give certain units a x% chance for a promotion when they are build. For this I have implied the following test code:

Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())
#Changes Start
		iUnitCombatType = gc.getUnitInfo(unit.getUnitCombatType())
		if iUnitCombatType == gc.getInfoTypeForString('UNITCOMBAT_MELEE'):
			unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_COMBAT1"),1)
		else:
			unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_COMBAT2"),1)
				
#Changes End		
		
		CvAdvisorUtils.unitBuiltFeats(city, unit)
	
		if (not self.__LOG_UNITBUILD):
			return
		CvUtil.pyPrint('%s was finished by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))

Problem is, that the Melee (and each other) unit I build gets the "Combat2" promotion, so I guess the iUnitCombatType variable must be somehow flawed, but I just can't see in which way.
 
Or just iUnitCombatType = gc.getUnitInfo(unit).getUnitCombatType(). The bracket is in the wrong place in the original code.
 
iUnitCombatType = gc.getUnitInfo(unit).getUnitCombatType() gives an error, but iUnitCombatType = unit.getUnitCombatType() works just fine, thanks!
 
Or just iUnitCombatType = gc.getUnitInfo(unit).getUnitCombatType(). The bracket is in the wrong place in the original code.

argslist[1] is a CyUnit, not a UnitTypes value, so you cannot pass it to getUnitInfo().
 
Top Bottom