Python event: unit creation after losing a battle?

I tested the following and it works:

Code:
		pLPlayer = gc.getPlayer(pLoser.getOwner())
		iDiseased = gc.getInfoTypeForString('PROMOTION_DISEASED')
		iPlagued = gc.getInfoTypeForString('PROMOTION_PLAGUED')
		iDiseasedCorpse = gc.getInfoTypeForString('UNIT_DISEASED_CORPSE')

		if (pLPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_COMPASSION')) == gc.getInfoTypeForString('CIVIC_SACRIFICE_THE_WEAK')):
			if pLoser.isHasPromotion(iDiseased) or pLoser.isHasPromotion(iPlagued):
				if (pLoser.getUnitType() != iDiseasedCorpse):
					if CyGame().getSorenRandNum(100, "Maniac") <= 33:
						pPlot = cf.FFHFindClearPlot(pLoser, -1)
						if pPlot != -1:
							newUnit = pLPlayer.initUnit(iDiseasedCorpse, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI)
							CyInterface().addMessage(pWinner.getOwner(),True,25,'A Diseased Corpse arises from our slain enemies.','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Units/Diseasedcorpse.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
							CyInterface().addMessage(pLoser.getOwner(),True,25,'A Diseased Corpse arises from the battlefield.','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Units/Diseasedcorpse.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
							newUnit.finishMoves()

The big change was that that before the unit was being init'ed on PlayerY instead of pLPlayer.
 
Kael said:
I tested the following and it works:

You actually got a Diseased Corpse created in-game? For with me still nothing happens.
bawling.gif
bawling.gif
bawling.gif
bawling.gif
 
M@ni@c said:
You actually got a Diseased Corpse created in-game? For with me still nothing happens.
bawling.gif
bawling.gif
bawling.gif
bawling.gif

Yeap, it worked perfectly.

Did you change something in the customfunctions file?
 
I got it working! Don't know if that could be it, but before I pasted the event into the eventmanager as the last of the def onCombatResult series. Now I made it the penultimate event, before

Code:
		if (not self.__LOG_COMBAT):
			return
		if playerX and playerX and unitX and playerY:
			CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s' 
				%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(), 
				playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))

Thanks for all your time. :) I learned some great stuff about python during this event taking shape.:goodjob:
 
M@ni@c said:
I got it working! Don't know if that could be it, but before I pasted the event into the eventmanager as the last of the def onCombatResult series. Now I made it the penultimate event, before

Code:
		[B]if (not self.__LOG_COMBAT):[/B]
			return
		if playerX and playerX and unitX and playerY:
			CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s' 
				%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(), 
				playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))

Thanks for all your time. :) I learned some great stuff about python during this event taking shape.:goodjob:

Ah. That was probably the problem.

What the line I emboldened does is check if a small variable (self.__LOG_COMBAT) is flagged to true (by default it's false). If so, it continues on, doing the next line, which is really just there to help debugging. However, since it was probably default to false, the function stopped executing by calling that "return" statement, thus all the code after that (including yours) was never run.
 
Back
Top Bottom