python aid needed

smortt

Warlord
Joined
Jan 16, 2008
Messages
283
Location
Israel
I've added a piece of code to onUnitKilled

Code:
def onUnitKilled(self, argsList):
		'Unit Killed'
		unit, iAttacker = argsList
		player = PyPlayer(unit.getOwner())
		attacker = PyPlayer(iAttacker)
		
		
		## raise undead from barb start
		

		 
		if (not unit.isAnimal()):
			iStr = unit.baseCombatStr()
			randUnit = CyGame().getSorenRandNum(20, "random undead spawn")
			if (randUnit==0):
				undead = "UNIT_ZOMBIE"
			if (randUnit==1):
				undead = "UNIT_SKELETON"
			if (iStr >5):
				if (randUnit==2):
					undead = "UNIT_GHOST"
				if (randUnit==3):
					undead = "UNIT_SKELETON_LORD"
				if (randUnit==4):
					undead = "UNIT_LEECH"	
			
			barbPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
			pUnit = unit.plot() 
		
			pNewUnit = barbPlayer.initUnit(gc.getInfoTypeForString(undead), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
			pNewUnit.finishMoves()
			
		## raise undead from barb end
		
		if (not self.__LOG_UNITKILLED):
			return
		CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d' 
			%(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))

It gives a chance to spawn an undead barbarian unit when a unit is killed.
I need to add 2 things:
- check the unitcombat of the killed unit (no spawning if it is of a specific unitcombat)
- check the attacker and defender tiles, and only spawn if one of them is empty.
 
Use oncombatresult.
You can't tell which unit is attacker because it can simply die for weird reasons like nukes from onunitkilled
 
So how are you supposed to know which is the attacking unit if
A) all you know is the id of attacking player
B) attacker may not exist at all

That is why you have to write the code there and not here
 
Not necessary. Only triggered when unit defeated in combat.
Use getNumUnits
After

Anyway there are lots more thingss to check. Domain for instance, unless your zombies can swim
 
Oncombatresult is triggered so long as you get the xxx is defeated message
So even if you captured a worker or you capture a city with ships planes or missiles, those will trigger as well.
Air battles and interception don't trigger though
 
Top Bottom