Small problem with Python

I suppose that the unit bunker is not a sort of settler then... :D

Question: that unit bunker is of the same Civ? What should happen if it's from another Civ? Kill it too?
 
Sorry, but i dont know the bunker of the vanilla civ! :undecide:

My bunker works so: A Worker build a improvement Bunker, after this improvement is finished, a pythoncode delate this improvement and set a unit Bunker with Domain Immobile . Because a Unit can do an active Action - linke Range Combat an Defending...and so on...

What should happen if it's from another Civ? Kill it too?

You cant go with a settler on a plot with a bunker (in my case) of a another civ, because the settler would be destroyed. Because my bunkers are units...

But it is possible to move with your own settler on a plot with a own bunker...and in this case, after you build a City on the Bunker plot, the bunker unit should be killed. Thats the idear.
 
Ah, I see, interesting! You can reserve your spot in advance like that! :D

So there is no need to check the civilization of the bunker, just kill it! :sniper:

This should do the trick then:
Code:
	def onCityBuilt(self, argsList):
		'City Built'
		city = argsList[0]
		if (city.getOwner() == gc.getGame().getActivePlayer()):
			self.__eventEditCityNameBegin(city, False)	
		CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
		## Kill all the bunkers!
		pPlot = city.plot()
		for iUnit in xrange(pPlot.getNumUnits()):
			pLoopUnit = pPlot.getUnit(iUnit)
			if pLoopUnit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_BUNKER"):
				pLoopUnit.kill(False, pLoopUnit.getOwner())

Check if the name of the Unitclass is correct. Or just use the UnitType if it's more convenient:
Code:
if pLoopUnit.getUnitType() == gc.getInfoTypeForString("UNIT_BUNKER"):
 
Okay, thank u very much! :goodjob:

I did a litte change...because i have 3 different types of bunkers...

Code:
pPlot = city.plot()
		for iUnit in xrange(pPlot.getNumUnits()):
			pLoopUnit = pPlot.getUnit(iUnit)
			if pLoopUnit.getUnitType() == gc.getInfoTypeForString("UNIT_BUNKER") or pLoopUnit == gc.getInfoTypeForString("UNIT_BUNKER2") or pLoopUnit == gc.getInfoTypeForString("UNIT_BUNKER3"):
				pLoopUnit.kill(False, pLoopUnit.getOwner())

Sadly, bunker 2 and 3 not killed.
But i dont get a Errormessage.
Without my change it works fine! :lol:


Edit:

Did it in this way...


Code:
for iUnit in range (pPlot.getNumUnits()):
			iUnitType = pPlot.getUnit(iUnit).getUnitType()
			if iUnitType == gc.getInfoTypeForString("UNIT_BUNKER") or iUnitType == gc.getInfoTypeForString("UNIT_BUNKER2") or iUnitType == gc.getInfoTypeForString("UNIT_BUNKER3"):
				pPlot.getUnit(iUnit).kill(1,city.getOwner())

Works! Thanks for your help!!!! ;)
 
I don't know your mod and how many types you have but UNITCLASS is more general of course.

What is wrong in your first test is that you have to repeat the whole thing:
Code:
if pLoopUnit.getUnitType() == gc.getInfoTypeForString("UNIT_BUNKER") or pLoopUnit == gc.getInfoTypeForString("UNIT_BUNKER2") or pLoopUnit == gc.getInfoTypeForString("UNIT_BUNKER3"):
should have been:
Code:
if pLoopUnit.getUnitType() == gc.getInfoTypeForString("UNIT_BUNKER") or pLoopUnit.getUnitType() == gc.getInfoTypeForString("UNIT_BUNKER2") or pLoopUnit.getUnitType()  == gc.getInfoTypeForString("UNIT_BUNKER3"):
The last version is fine.
 
Top Bottom