HELP!!! Python Code Not Working Correctly!

The Capo

godless Heathen
Joined
Jan 29, 2001
Messages
9,302
Location
Washington, DC
Hey everyone. I have two python features in my mod, one is a wonder (the Flavian Amphitheatre) that gives the player a 20% chance to build a rival civ's UU when building a unit of the same class, and the other is a feature where a player (while using the slavery civic) can capture slaves from combat, this is also supposed to be a 20% chance.

The problem is that one works perfectly fine (Flavian Amphitheatre) and other (obviously slavery) does not. I have tested the Flavian Amphitheatre button, and just as advertised it pops out a rival UU at about a 20% rate. But when running slavery you seem to capture a slave unit after every combat victory, which is not the intention. I was wondering if anyone can identify why this could be case. Here is the code I use for the capture slave from combat function:

Code:
	def onCombatResult(self, argsList):
		'Combat Result'
		pWinner,pLoser = argsList
		playerX = PyPlayer(pWinner.getOwner())
		unitX = PyInfo.UnitInfo(pWinner.getUnitType())
		playerY = PyPlayer(pLoser.getOwner())
		unitY = PyInfo.UnitInfo(pLoser.getUnitType())

# Animal bonus start
		player = pWinner.getOwner()
		winnerOwner = gc.getPlayer(player)
		team = winnerOwner.getTeam()
		winnerTeam = gc.getTeam(team)
		pLoserType = pLoser.getUnitType()

		if (pLoserType == gc.getInfoTypeForString('UNIT_ELEPHANT')):
			if winnerTeam.isHasTech(gc.getInfoTypeForString('TECH_ANIMAL_HUSBANDRY')):
				pLoser.plot().setBonusType(gc.getInfoTypeForString('BONUS_IVORY'))

		if (pLoserType == gc.getInfoTypeForString('UNIT_HORSE')):
			if winnerTeam.isHasTech(gc.getInfoTypeForString('TECH_ANIMAL_HUSBANDRY')):
				pLoser.plot().setBonusType(gc.getInfoTypeForString('BONUS_HORSE'))

		if (pLoserType == gc.getInfoTypeForString('UNIT_DEER')):
			if winnerTeam.isHasTech(gc.getInfoTypeForString('TECH_ANIMAL_HUSBANDRY')):
				pLoser.plot().setBonusType(gc.getInfoTypeForString('BONUS_DEER'))
# Animal bonus end 

[COLOR="Red"]#slave mod#
		if (pWinner.isMadeAttack()):
			iAttacker = pWinner.getOwner()
			attacker = PyPlayer(iAttacker)
			if gc.getPlayer(iAttacker).isCivic(CvUtil.findInfoTypeNum(gc.getCivicInfo,gc.getNumCivicInfos(),'CIVIC_SLAVERY')):
				if ((pLoser.plot()).isCity() == 0):
					if (pLoser.isAnimal() == 0):
						if (pLoser.getCaptureUnitType((gc.getPlayer(pLoser.getOwner())).getCivilizationType()) == -1):
							# you can change the chance of getting slaves with this between 0-99, 0 means 0% and 99 100%
							iChance = 1

							iRandNum = CyGame().getSorenRandNum(99, "Slave")
							if iChance < iRandNum:
								attacker.initUnit(gc.getCivilizationInfo(gc.getPlayer(iAttacker).getCivilizationType()).getCivilizationUnits(CvUtil.findInfoTypeNum(gc.getUnitClassInfo, gc.getNumUnitClassInfos(), 'UNITCLASS_SLAVE')), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI)
#slave mod#[/COLOR]

I colored the slavery part in red. As you can see I set the chance to 1 (according to the coder setting this made the liklihood of capturing a slave 1%, even when doing this a slave was captured everytime.

Could anyone help me out with this?
 
If you really haven't changed anything, I don't understand how I screwed it that badly. :blush: Sorry, it should be like
Code:
#slave mod#
		if (pWinner.isMadeAttack()):
			iAttacker = pWinner.getOwner()
			attacker = PyPlayer(iAttacker)
			if gc.getPlayer(iAttacker).isCivic(CvUtil.findInfoTypeNum(gc.getCivicInfo,gc.getNumCivicInfos(),'CIVIC_SLAVERY')):
				if ((pLoser.plot()).isCity() == 0):
					if (pLoser.isAnimal() == 0):
						if (pLoser.getCaptureUnitType((gc.getPlayer(pLoser.getOwner())).getCivilizationType()) == -1):
							# you can change the chance of getting slaves with this between 0-99, 0 means 0% and 99 100%
							iChance = 1

							iRandNum = CyGame().getSorenRandNum(99, "Slave")
							if iChance [COLOR="red"]>[/COLOR] iRandNum:
								attacker.initUnit(gc.getCivilizationInfo(gc.getPlayer(iAttacker).getCivilizationType()).getCivilizationUnits(CvUtil.findInfoTypeNum(gc.getUnitClassInfo, gc.getNumUnitClassInfos(), 'UNITCLASS_SLAVE')), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI)
#slave mod#
 
So if I changed it to that, and then set the 1 to a 25 it should/will produce slaves from 25% of combat victories?

Yes, that's how I designed it.

EDIT: BTW the info text is wrong. # you can change the chance of getting slaves with this between 0-100, 0 means 0% and 100 100%
but the I don't think you'll ever get so many slaves that you'll notice it's only 99% chance when chance is set 99. :mischief:
 
Back
Top Bottom