Spawn units at sqaure on turn

You can create units using this function (it is part of the CyPlayer object):
CyUnit initUnit (UnitType iIndex, INT iX, INT iY, UnitAIType eUnitAI, DirectionType eFacingDirection)

You can declare war using this function (it is part of the CyTeam object):
VOID declareWar (TeamType eTeam, BOOL bNewDiplo, WarPlanType eWarPlan)

This site gives more information about what is can be done using Python:
http://civ4bug.sourceforge.net/PythonAPI/index.html

There are several functions in Python\CvEventManager.py such as onBeginPlayerTurn that can be used for making things happen on a certain turn. If you are new to modding, one word of advise - never change the original game files - check out the tutorials section for more details.
 
well you could go back and look at the python for the American Revolution, for vanilla. It has that for french and british troops, as well partisans, its probably more than you need, but if you can sift through it and kinda understand whats going on, you may at least be able to get a decent enough start someone would help you the rest of the way through it.

I would tell you how, but I don't really know how either
 
Code:
        def __eventAmericanrev
        if (turn == 586):
            pPlayer = gc.getPlayer(iAmerica)
            iUnitType = gc.getInfoTypeForString("UNIT_MUSKETMANN")  
            iCityX = 54
            iCityY = 80
            DefaultUnitAI = "UNIT_AI_ATTACK"
            pPlayer.initUnit(iUnitType, iCityX, iCityY, DefaultUnitAI)
            return
I tried to put this code in CvEventmanager.py and it didn't make the units apear
 
This is heading in the right direction, but you are missing a few steps. This may not be a complete list:

1. Turn on "python logging" and "python exceptions" in your civilizationiv.ini file. This will show syntax errors, which will make debugging easier.

2. When you define a function in python you need to give an argument list and you need to be very careful about indentation. An example function looks like:

Code:
	def __eventAmericanrev (turn):
		if (turn == 586):
			pPlayer = gc.getPlayer(iAmerica)

3. Perhaps you added some other code to *call* this function, or perhaps not. Please show the code which calls the function. If you did not call it, that would be one reason it is not running. Since another poster suggested the American Revolution mod as an example, please note lines 1476-1480 of that file:
Code:
	def onBeginGameTurn(self, argsList):
		'Called at the beginning of the end of each turn'
		iGameTurn = argsList[0]
		
		# American Revolution events
		self.turnChecker(iGameTurn)

You would need to add a line like:
Code:
		self.__eventAmericanrev(iGameTurn)
If you are making your changes directly into vanilla CvEventManager.py, that will work also; add the line into the onBeginGameTurn of that file.

4. The American Revolution mod is for the original game, not BTS. If you are creating a mod for BTS, the initUnit line has one additional argument; add DirectionTypes.NO_DIRECTION at the end of your call.
 
Code:
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "<string>", line 52, in load_module
  File "CvEventInterface", line 13, in ?
  File "<string>", line 35, in load_module
  File "<string>", line 13, in _get_code
  File "CvEventManager", line 1078
    iUnitType = gc.getInfoTypeForString("UNIT_MUSKETMAN")  
                                                          ^
IndentationError: unindent does not match any outer indentation level
load_module CvAppInterface
That was the error message i got and i don't what it means
 
Your code is not intended right.
Python is sensitive about it, like Davidlallen already explained.

Something like this:
PHP:
            pPlayer = gc.getPlayer(iAmerica)
            iUnitType = gc.getInfoTypeForString("UNIT_MUSKETMANN")  
            iCityX = 54

will work.

Something like this:
PHP:
            pPlayer = gc.getPlayer(iAmerica)
                    iUnitType = gc.getInfoTypeForString("UNIT_MUSKETMANN")  
    iCityX = 54

will not.



Show us your current code please.
 
Code:
      def __eventAmericanrev (self):
	   if (turn == 586):
	   pPlayer = gc.getPlayer(iAmerica)
                iUnitType = gc.getInfoTypeForString("UNITCLASS_MUSKETMAN")  
                iCityX = 54
                iCityY = 80
                DefaultUnitAI = "UNIT_AI_ATTACK"
                pPlayer.initUnit(iUnitType, iCityX, iCityY, DefaultUnitAI,DirectionTypes.NO_DIRECTION )
                return
Here it is
the space beetween p.player and iunit type does not exist
 
pPlayer = gc.getPlayer(iAmerica) should be indented so that it lines up with iUnitType = gc.getInfoTypeForString("UNITCLASS_MUSKETMAN") .

Edit: oops, I just noticed the last line of your post. Python tends to act funny when spaces and tabs are mixed, you might want to check that.
 
Here it is
the space beetween p.player and iunit type does not exist

So it's all in one line, right?

Another thing: Simplified rule, after a : every line below has to be intended one tab more.
After your if (turn == 586): it's not the case.
 
Code:
        def __eventAmericanrev (self):
	        if (turn == 586):
                    pPlayer = gc.getPlayer(iAmerica)
                    iUnitType = gc.getInfoTypeForString("UNITCLASS_MUSKETMAN")  
                    iCityX = 54
                    iCityY = 80
                    DefaultUnitAI = "UNIT_AI_ATTACK"
                    pPlayer.initUnit(iUnitType, iCityX, iCityY, DefaultUnitAI,DirectionTypes.NO_DIRECTION )
                    return
 
Code:
        def __eventAmericanrev (self):
	        if (turn == 586):
                    pPlayer = gc.getPlayer(iAmerica)
                    iUnitType = gc.getInfoTypeForString("UNITCLASS_MUSKETMAN")  
                    iCityX = 54
                    iCityY = 80
                    DefaultUnitAI = "UNIT_AI_ATTACK"
                    pPlayer.initUnit(iUnitType, iCityX, iCityY, DefaultUnitAI,DirectionTypes.NO_DIRECTION )
                    return
so it should look like this
 
Code:
        def onBeginGameTurn(self, argsList):
	        if (turn == 586):
                    pPlayer = gc.getPlayer(iAmerica)
                    iUnitType = gc.getInfoTypeForString("UNITCLASS_MUSKETMAN")  
                    iCityX = 47
                    iCityY = 70
                    DefaultUnitAI = "UNIT_AI_ATTACK"
                    pPlayer.initUnit(iUnitType, iCityX, iCityY, DefaultUnitAI,DirectionTypes.NO_DIRECTION )
                    return
The New code
 
It seems clear you have not looked into my point #1, since the new code has an error: "turn" is never defined. Once you turn on python exceptions you will see popups for this error. You are missing the line like, "turn = argsList[0]".
 
Top Bottom