Triggering an Event if certain unit is killed

renegadechicken

Warlord
Joined
Aug 12, 2007
Messages
227
Location
Civ II Verne Scenario
I'd like to create an event that triggers when a unit is killed (think back to the "glory days" of Civ II, like in the Verne scenario). This is my attempt to code a check for such an event:

Spoiler :

def canTriggerAlienMenaceKilled(argsList):
kTriggeredData = argsList[0]​
player = gc.getPlayer(kTriggeredData.ePlayer)​
unit = unit.getUnitType() == gc.getInfoTypeForString('UNIT_GUARDIAN')​

if unit.onUnitKilled:​
return true​

return false​


Am I on the right track? :)
 
I'm not sure if it works, but there is a function onUnitKilled(self, argsList) in CvEventManager.py
If it actually works then you should add your code there.
 
Yea, you can intercept the onUnitKilled function to check if the unit killed is of a particular unit class, and if so, then you can execute whatever code you like.
 
I would recommend checking out a python tutorial to start with and once you get the basics of python down then it will be easyer to try some Civ4 python moddding.
 
Checking for a unit on killed is easy simply replace UNIT_KING below with the unit you want to check for.

Spoiler :
PHP:
	def onUnitKilled(self, argsList):

		'Unit Killed Trigger'
		unit, iAttacker = argsList
		player = PyPlayer(unit.getOwner())
		attacker = PyPlayer(iAttacker)

		'Check if unit killed was a king'
		if unit.getUnitType() == gc.getInfoTypeForString("UNIT_KING")
                        #Do Something Here!
 
Back
Top Bottom