Need help with onCombatResult

DaddyHolby

Chieftain
Joined
Feb 20, 2003
Messages
32
Location
Superior, Co
Hello all this is my first attempt at modifying python and I'm a bit lost.

I've been trying to give the winning unit in a fight extra experience. This is just something I thought would be "easy" for a first attempt. The long term goal is to be able to give a unit a special promotion after X number of victories or span a special unit after a victory (of course this might not be the best place to do this, but like I said this looked to be the easiest place to go).

To do this I found the onCombatResult function in the CvEventManager class. So I did the following:

Orig:
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()))

Modified:
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())
		unitX.setExperience(500)
		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()))

This of course doesn't work, so I tried several other things and even just tried to get this function to error out in one of the debug logs and still didn't get anything. I've been searching the forums for anything that would help and haven't found anything that has worked, though this could be because of my lack of python knowledge.

Anybody have any clue as to what I'm doing wrong?
 
Try this:

pWinner.setExperience(500)
or
pLoser.setExperience(500)

If you are not getting any error messages from that code you probably have Python exceptions turned off. If so, it would probably be a good idea to turn them on. You can do so by editing CivilizationIV.ini (you can use the _Civ4Config shortcut) and changing HidePythonExceptions = 1 to HidePythonExceptions = 0.
 
Yeah I tried that last night and nothing happened. I even tried writing to the interface last night (code snippet escapes me right now but I believe it was in TGA's toutorial) and even that didn't work.

I also modified the ini file to no longer hide python exceptions (and to turn on logging) and I still didn't get anything.

I even put statements into the python that I believe should write to the logs, but nothing showed up in the logs.

After looking at my first post I realized that I forgot to mention that I had BUG and BAT installed and running when I was testing, could this be causing the problem?

I did try moving the code up above to the BUG Event Manager, but I still didn't get anything to work.
 
After looking at my first post I realized that I forgot to mention that I had BUG and BAT installed and running when I was testing, could this be causing the problem?

I did try moving the code up above to the BUG Event Manager, but I still didn't get anything to work.

BUG has some special loading rules (and some more). You should ask in the BUG subforum, why it doesn't work.
 
I believe that BUG uses it's own event manager. I never checked to see how it is implemented, but it may be causing the standard CvEventManager to be ignored.
 
Yeah BUG has it's own event manager and a completely different way to load things. And those rules apparently change if BAT is running too. I should have everything sorted out in a day or two.

Thanks for the help.
 
Back
Top Bottom