need help with python

Manifold

ModderProtectionAdvocate
Joined
Aug 27, 2007
Messages
1,580
EDIT: Result is at the end

this is the code now

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())
###unit after palace captured start part 2		
                iX = pLoser.getX()
                iY = pLoser.getY()
                iPlayer = pWinner.getOwner()
                pPlayer = gc.getPlayer(iPlayer)                 
                myplot = CyMap().plot(iX,iY)
                if myplot.isCity()==True:
                        pCity = myplot.getPlotCity()
                        if pCity.isCapital() :                    
                                WinnerPlayer = gc.getPlayer(pWinner.getOwner())
                                iThisTeam = WinnerPlayer.getTeam()
                                ThisTeam = gc.getTeam(iThisTeam)
                                NumDef = 0
                                for i in range (gc.getMAX_PLAYERS ()):
                                        CurPlayer = gc.getPlayer(i)
                                        iCurTeam = CurPlayer.getTeam()
                                        if iThisTeam ==iCurTeam:continue
                                        if ThisTeam.isAtWar(iCurTeam):                                                
                                                CurDef = myplot.getNumDefenders(i)                                                
                                                NumDef = NumDef+CurDef
                                                if NumDef >=2:
                                                        break                                
                                if NumDef<=1:
                                        self.CapturedCapital = True
                                        return
###mnit after palace captured end part 2  
		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()))

i wanna fit this in
Code:
###Chimere dead###
        
				if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_TACTICAL_NUKE'):
					iX = pLoser.getX()
					iY = pLoser.getY()
					pPlot = CyMap().plot(iX, iY)
					pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_VOLCANO'), -1)
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIGHTER'), pPlot.getX(), pPlot.getY()+1, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_WEST)
		
###Chimere END###

it seems done twice:mad:

the nuke is the chimere and the fighter is the pegasus.
 
this is the code now

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())
###unit after palace captured start part 2		
                iX = pLoser.getX()
                iY = pLoser.getY()
                iPlayer = pWinner.getOwner()
                pPlayer = gc.getPlayer(iPlayer)                 
                myplot = CyMap().plot(iX,iY)
                if myplot.isCity()==True:
                        pCity = myplot.getPlotCity()
                        if pCity.isCapital() :                    
                                WinnerPlayer = gc.getPlayer(pWinner.getOwner())
                                iThisTeam = WinnerPlayer.getTeam()
                                ThisTeam = gc.getTeam(iThisTeam)
                                NumDef = 0
                                for i in range (gc.getMAX_PLAYERS ()):
                                        CurPlayer = gc.getPlayer(i)
                                        iCurTeam = CurPlayer.getTeam()
                                        if iThisTeam ==iCurTeam:continue
                                        if ThisTeam.isAtWar(iCurTeam):                                                
                                                CurDef = myplot.getNumDefenders(i)                                                
                                                NumDef = NumDef+CurDef
                                                if NumDef >=2:
                                                        break                                
                                if NumDef<=1:
                                        self.CapturedCapital = True
                                        return
###mnit after palace captured end part 2  
		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()))

i wanna fit this in
Code:
###Chimere dead###
        
				if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_TACTICAL_NUKE'):
					iX = pLoser.getX()
					iY = pLoser.getY()
					pPlot = CyMap().plot(iX, iY)
					pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_VOLCANO'), -1)
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIGHTER'), pPlot.getX(), pPlot.getY()+1, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_WEST)
		
###Chimere END###

it seems done twice:mad:

the nuke is the chimere and the fighter is the pegasus.

I can't see your problem. :confused: If you need to put that part there, put it there.
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())
###unit after palace captured start part 2		
                iX = pLoser.getX()
                iY = pLoser.getY()
                iPlayer = pWinner.getOwner()
                pPlayer = gc.getPlayer(iPlayer)                 
                myplot = CyMap().plot(iX,iY)
                if myplot.isCity()==True:
                        pCity = myplot.getPlotCity()
                        if pCity.isCapital() :                    
                                WinnerPlayer = gc.getPlayer(pWinner.getOwner())
                                iThisTeam = WinnerPlayer.getTeam()
                                ThisTeam = gc.getTeam(iThisTeam)
                                NumDef = 0
                                for i in range (gc.getMAX_PLAYERS ()):
                                        CurPlayer = gc.getPlayer(i)
                                        iCurTeam = CurPlayer.getTeam()
                                        if iThisTeam ==iCurTeam:continue
                                        if ThisTeam.isAtWar(iCurTeam):                                                
                                                CurDef = myplot.getNumDefenders(i)                                                
                                                NumDef = NumDef+CurDef
                                                if NumDef >=2:
                                                        break                                
                                if NumDef<=1:
                                        self.CapturedCapital = True
                                        return
###mnit after palace captured end part 2
[COLOR="Red"]]###Chimere dead###
        
		if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_TACTICAL_NUKE'):
			iX = pLoser.getX()
			iY = pLoser.getY()
			pPlot = CyMap().plot(iX, iY)
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_VOLCANO'), -1)
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIGHTER'), pPlot.getX(), pPlot.getY()+1, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_WEST)
		
###Chimere END##[/COLOR]  
		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()))
Or what do you want your code to do?
 
sorry, i just start with python. so i take a look at some other codes to fit them into my code. For now every thing i fit in works. but this did not work. i guess it is because of the other already existing entry in the def onCombatResult(self, argsList):

my goal is, that, if the nuke is killed the winner gets the fighter and the volcano feature appears.
It still not work this way. what should the code else do?
 
my goal is, that, if the nuke is killed the winner gets the fighter and the volcano feature appears.
It still not work this way. what should the code else do?

What isn't working? Do you get no new feature? Do you get no new unit? Have you enabled python exceptions?
You need to describe accurately your problems. :)

Try to replace this
Code:
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIGHTER'), pPlot.getX(), pPlot.getY()+1, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_WEST)
with this
Code:
			pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIGHTER'), pPlot.getX(), pPlot.getY()+1, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_WEST)
 
thanks, i tried it, but it still happened nothing after the combat. either the new feature or the new unit.

Have you enabled python exceptions?
???? i already fit successfully some other codes in. did this code need something extra?
 
???? i already fit successfully some other codes in. did this code need something extra?

No, it only prints an error message if there was something in python that doesn't work. Go to My Games/Beyond The sword, there you'll find the CivilizationIV.ini. Open it and search for "HidePythonExceptions", it should look like this
Code:
; Set to 1 for no python exception popups
HidePythonExceptions = [COLOR="Red"]1[/COLOR]
Change the number in red to 0 then try to run your code again.
 
no effect: what i did is:

1. open the CivilizationIV.ini in my games/beyond the... and change HidePythonExceptions from 1 to 0, save it ----------(?i work on a mod. should i work the ini there?)
2. then i start the mod by dooble click the scenario (loading uncached)
3. open the wb, set the units, close wb, start combat, end turn
4. nothing happend:cry:

could it be a problem with the entry before?
 
I tested the code and the feature appears, but I get a python error about the initUnit. Are you sure you enabled python exceptions? it seems to say that "initUnit() takes at most 5 arguments (6 given)". Interesting.
 
The other code should only affect the whole thing, when you attack an enemy capital.

The feature and the unit itself work?

you mean, i should create another test-mod and test just the thing with the feature and new unit?
 
i made a new test-mod and did the same procedure

now i get something, but not the desired effect



line 392 - 412
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())
		[COLOR="Red"]if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_AXEMAN'):
						iX = pLoser.getX()
						iY = pLoser.getY()
						pPlot = CyMap().plot(iX, iY)
						pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_ICE'), -1)
						pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WARRIOR'), pPlot.getX(), pPlot.getY()+1, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_WEST)[/COLOR]
		
		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()))
 
I did it:king::king::king:

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())
		
		pPlayer = gc.getPlayer(pWinner.getOwner())
		if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_AXEMAN'):
			iX = pLoser.getX()
			iY = pLoser.getY()
			pPlot = CyMap().plot(iX, iY)
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FALLOUT'), -1)
			iUnitType = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_WARRIOR')
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_WARRIOR' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
		
		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()))

Thank you NotSoGood for your patience!!!
 
I'm curious, what did you change to get it work? I have no idea why it said you passed too many variables to it.

Dont know, how i get this work, it must be divine mercy

Code:
[COLOR="Red"]pPlayer = gc.getPlayer(pWinner.getOwner())[/COLOR]
		if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_AXEMAN'):
			iX = pLoser.getX()
			iY = pLoser.getY()
			pPlot = CyMap().plot(iX, iY)
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FALLOUT'), -1)
			[COLOR="Red"]iUnitType = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_WARRIOR')
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_WARRIOR' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)[/COLOR]

Now i will try to give the pegasus a rider:D I guess i need a lot of mercy for this.
 
You are very fond of making variables that are identical to other variables.

This makes pPlayer is identical to pWinner:
Code:
pPlayer = gc.getPlayer(pWinner.getOwner())

You do the same sort of thing a few times in the code in your original post too.

Instead of jumping through hoops to make the same thing but with a different name, you could just use the original.
 
You are very fond of making variables that are identical to other variables.

This makes pPlayer is identical to pWinner:
Code:
pPlayer = gc.getPlayer(pWinner.getOwner())

You do the same sort of thing a few times in the code in your original post too.

Instead of jumping through hoops to make the same thing but with a different name, you could just use the original.

Yes it looks strange, but it works:D Or do you want to tell me how i can rump up the code?
 
Top Bottom