Do custom Python functions need to be "allowed" before they work?

No, you can add Python as you like and call those functions. However, if you are overriding certain callback functions in CvGameInterface.py such as cannotFoundCity(), you need to enable them in PythonCallbackDefines.xml.

Can you provide an example Python function that isn't working? Where did you put the code?
 
Here's one

Code:
def onUnitKilled(self, argsList):
		'Unit Killed'
		unit, iAttacker = argsList
		player = PyPlayer(unit.getOwner())
		attacker = PyPlayer(iAttacker)
		
		if unit.getUnitType() == gc.getInfoTypeForString('UNIT_KING_KONG'):
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ARTIST'), gc.getPlayer(pAttacker).getCapitalCity().getX(), gc.getPlayer(0).getCapitalCity().getY(), DirectionTypes.DIRECTION_SOUTH)
			szHelp = localText.getText("TXT_KEY_EVENT_KING_KONG_HELP_2", ())
		
		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()))

This is supposed to grant the attacking civ a Great Artist when a particular unit is killed. This is all in CvEventManager. I've tested this in World Builder and when this unit is killed, I get nothing.

It's the same with all of my other custom functions as well.
 
Where did you put the code? Did you modify CvEventManager.py in your Civ4 install's Assets folder or in a copy in "My Games/BTS/CustomAssets" or elsewhere?

It's possible there's a bug in the code -- that it's being run but fails. Do you see any errors in Logs/PythonErr.log?
 
Is 'show python exceptions' turned on?

That code seems weird to me. For starters, you're using pPlayer and pAttacker, which haven't been defined anywhere.

Also, another time you say gc.getPlayer(0) instead of gc.getPlayer(pAttacker).
Unless you only want this event to work correctly in single player for a human player, I think that will cause problems too.
 
Top Bottom