Python problem - How to spawn a unit on unit creation?

Merkava120

Oberleutnant
Joined
Feb 2, 2013
Messages
450
Location
Socially distant
I'm trying to make it so that whenever I build a certain unit, another spawns, i.e. building an army all at once instead of just one unit at a time. Nothing's happening though.

Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())
## Armies ##
		int iUnitID = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_INFANTRY')
		if unit.getUnitType() == iUnitID:
			initUnit(iUnitID,city.getX(),city.getY(),UnitAITypes.NO_UNITAI)
## Armies ##

		CvAdvisorUtils.unitBuiltFeats(city, unit)

I don't know enough about python to know what's happening (or rather, what isn't happening). Could someone enlighten me?
 
I think you need to say which player is getting the unit.

Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())
## Armies ##
		int iUnitID = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_INFANTRY')
		if unit.getUnitType() == iUnitID:
			[B]player.[/B]initUnit(iUnitID,city.getX(),city.getY(),UnitAITypes.NO_UNITAI)
## Armies ##

		CvAdvisorUtils.unitBuiltFeats(city, unit)
 
Oh, thanks! Didn't catch that.

Unfortunately, still nothing special is happening when I build an infantry.
 
Oh, thanks! Didn't catch that.

Unfortunately, still nothing special is happening when I build an infantry.

I am not sure you should have the int in the line before the if test and I would usually code it something like
Code:
iUnitID = CyGlobalContext().getInfoTypeForString('UNIT_INFANTRY')
 
That worked!! Thanks a ton!
 
Top Bottom