Creation of a unit on combat victory

liwy

Chieftain
Joined
Nov 15, 2009
Messages
63
Location
Brussels
Tired to see Scipio staying in Rome to train legions for thousands of years, I tried to build a system where the great generals would have a small chance to generate a great instructor (a copy of a great general who can only attach to cities) when they won battles.

So I splited the great general in two units, and created a new promotion that should be granted when a general join a unit like the warlord one.
Then I copied the Platytiping code of the "heroic" promotion to give to the promotion hability a small chance to be active. It should be 2%


if pWinner.isHasPromotion(gc.getInfoTypeForString("PROMOTION_MILITARY_TRADITION"):
if CyGame().getSorenRandNum(50) == 0:

(I don't know why but the message appears with a space between the R and the O where there was none appearing when I wrote it)

I don't have a lot of experience in python so is this line also mean 2% of chances for the promotion to trigger?

if CyGame().getSorenRandNum(100) <= 2:

The tricky part comes next i compared examples to make the great instructor appears, but there is a mistake and I can't see where.

pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_GREAT_INSTRUCTOR' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI)

So I got this:
if pWinner.isHasPromotion(gc.getInfoTypeForString("PROMOTION_MILITARY_TRADITION")):
if CyGame().getSorenRandNum(50) == 0:
pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_GREAT_INSTRUCTOR' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI)

And despites my numerous trying it still don't work and make the interface disappear.

Subsidiary question, how should I do to make the instructor to appear in the capital city?

Thanks in advance
 
Well...

1st: Put your codes in [CODE] xxx [/CODE] or nobody can understand them.

2nd: Activate python exceptions to tell what is the error about.

3rd: if CyGame().getSorenRandNum(100) <= 2: is NOT 2% but 3%
CyGame().getSorenRandNum(X) gives a random number from 0 to (x - 1)
 
Code:
			if pWinner.isHasPromotion(gc.getInfoTypeForString("PROMOTION_MILITARY_TRADITION")):
				if CyGame().getSorenRandNum(50) == 0:
					pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_GREAT_INSTRUCTOR' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)

It was simply an indentation error, it works.
But I still don't know how to make the instructor to appear in the capital.
 
I'd assume it's currently appearing on the same tile as pWinner, since that's what your code is doing.
You'll want to find who owns the unit (getOwner) and then find that civ's capital city (getCapitalCity) and then getX and getY and plug those into the initUnit line.

Edit: You've already got the owner, of course.
 
pPlayer.initUnit(gc.getInfoTypeForString( 'UNIT_GREAT_INSTRUCTOR' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI)

These 2 refers to X and Y coordinates of where to spawn the unit, in this case, where pWinner was.
pPlayer.getCapitalCity() will get you the Capital City, if there is one.
 
Back
Top Bottom