Need help with python killing a unit

boneys26

BTS Play session tester
Joined
Nov 24, 2005
Messages
839
Location
Coventry, England
Does anyone know a working code to kill a unit at the end of its turn even if it loses? I'm working on bringing back the cruise missile smitty has made a nice looking unit. RogerBacon gave me this code but the unit doesn't die

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())
if(pWinner == gc.getInfoTypeForString("UNITCLASS_CRUISE_MISSILE") 
pWinner.kill(0,0) # This kills the unit if it is a cruise missle and if it won combat. If it lost combat it is already dead.

and Lord Olleus gave me this one but as before the unit doesn't die

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())
		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()))
		if pWinner.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_CRUISE_MISSILE"):
			pWinner.kill(0, pWinner.getOwner())
			CvUtil.pyPrint("The Cruise Misile has detonated!")

Thanks to RogerBacon's "flying mod" the missile will be able to go on land and water although there will be 2 or 3 missiles each with its own bonus like +10% against naval ships and +10% against armor etc... so if anyone knows a code please help I've been trying for 2 months ( I don't know python trying to teach myself C & C++ ATM well have been for almost 2 months :confused: :wallbash: :suicide: )
 
You could:

setDamage(100);

Or whatever the python equivalent is (the above is the SDK command). At the end of the units turn an isDead() check is always made internally and if true then it's killed off and deleted from the unit list.

Dale
 
Back
Top Bottom