The Modding Q&A Thread

So.... What do I cahnge :confused:

Should I just move back all the indentions then? Anything else?
 
Also, the if should be an elif.
 
No, not even elif, the whole thing is correct but in wrong place, wrong file.

You've pasted an IF that checks year in the IF/ELIF sequence that checks resurrected civs, within the resurrection method. So your code would be only applied when a civ is resurrected and it's not Armenia, and it's year 1096 - i.e. never.

There isn't one correct place for it but the most logical would be anywhere in the checkTurn method of Barbarian.py
 
I just helped The Turk out with this issue and the code ended up in checkTurn() in RiseAndFall. I wasn't aware there was a Barbarians.py...
 
This is basically how you could add the code into Barbs.py:
Code:
	def checkTurn(self, iGameTurn):

[b]		#The Turk: Add Castle to indie/barb Damascus:   
		if iGameTurn == getTurnForYear(1096): 
			if gc.getMap().plot(22,43).getPlotCity().getOwner() >= [COLOR="Red"]con.[/COLOR]iNumPlayers: 
				gc.getMap().plot(22,43).getPlotCity().setHasNumRealBuilding([COLOR="Red"]con.[/COLOR]iCastle, 1)[/B]
A somewhat more streamlined version could be:
Code:
		#The Turk: Add Castle to indie/barb Damascus:   
		if iGameTurn == getTurnForYear(1096):
			pCity = gc.getMap().plot(22,43).getPlotCity()
			if pCity.getOwner() >= con.iNumPlayers: 
				pCity.setHasNumRealBuilding(con.iCastle, 1)
The code has one problem though - what happens if there is no city at the Damascus plot? Then logic would break down. You could add this line in order to make sure it doesn't happen:
Code:
		#The Turk: Add Castle to indie/barb Damascus:   
		if iGameTurn == getTurnForYear(1096):
			pPlot = gc.getMap().plot(22,43)
[B]			if pPlot.isCity():[/B]
				pCity = pPlot.getPlotCity()
				if pCity.getOwner() >= con.iNumPlayers: 
					pCity.setHasNumRealBuilding(con.iCastle, 1)
 
Ok, I've done what Baldyr has asked me to, and I added it into my barbs file, but it STILL won't work!
I've attached it here, so if someone could please take a look, I'd be very grateful!

Thanks anyway,

The Turk :)
 

Attachments

You still haven't turned on Python exceptions, did you? You know it can actually show you the error on screen, and it's generally better at finding typos than humans are. In this case it's likely about wrong function name setHasNumRealBuilding should be setNumRealBuilding.

For Python Exceptions:

Open Beyond the Sword/_Civ4Config and at the end add this line:
ShowPythonDebugMsgs = 1

also change LoggingEnabled from 0 to 1.
 
Yeah, there is no point in editing Python modules unless you enable exceptions... Because you could end up looking for an error and never finding it otherwise. I for sure didn't notice the typo embryodead is referring to. (I'm guessing its due to copy-paste of an instance of the isHasNumRealBuildings() method. There is a library of all the available class methods - you should check the spelling and the all the parameters of each.)

Also, there is little point in feeling frustrated over some code posted by someone else on these boards isn't working. You need to be able to read the code yourself to verify that it does what it advertises, and also evaluate it so that you know how and where to implement it. And there will always be mistakes in code, unless throughly tested. And the way to test code is to run it - with exceptions enabled.

It could be added that the Python Error Log(s) can be found in \Documents\Games\Beyond the Sword\Logs\ - there is also a Python Debug Log.
 
Hi Everyone,

Ok this is what I got from the PythonErr.log file:

Spoiler :
Traceback (most recent call last):

File "CvEventInterface", line 22, in onEvent

File "CvCustomEventManager", line 145, in handleEvent

File "CvCustomEventManager", line 156, in _handleDefaultEvent

File "CvRFCEventHandler", line 132, in onBeginGameTurn

File "Barbs", line 776, in checkTurn

AttributeError: 'CyCity' object has no attribute 'setHasNumRealBuilding'
ERR: Python function onEvent failed, module CvEventInterface


Now how can I fix it? Is it supposed to be "isHasNumRealBuilding"
 
As embryodead said, you lose the "Has" bit. Because the exception says just that - there is no method by that name belonging to the CyCity class. Look for yourself.
VOID setNumRealBuilding (BuildingType iIndex, INT iNewValue)
(BuildingID, iNum) - Sets number of buildings in this city of BuildingID type
You have so much to learn about Python and how it is used with CivIV, so I suggest you get started. Once you get some of the basics in, this will be so much less painful for you!
 
Thank u Baldyr and Jakov :D. I was successful in spawning an independent Warsaw but I have a new problem:
How do i exclude warsaw from the german flip zone
 
How do i exclude warsaw from the german flip zone
The spawn zone is also know as the Core Area, and its coordinates are defined in the Consts.py file. Its basically a rectangular shaped area defined by these values, but IIRC there is also an array of tiles that are excepted from the area. These would be defined directly below the Core Area values. So you add the coordinates of Warzaw (as a tuple) in the German slot in the data structure.
 
The spawn zone is also know as the Core Area, and its coordinates are defined in the Consts.py file. Its basically a rectangular shaped area defined by these values, but IIRC there is also an array of tiles that are excepted from the area. These would be defined directly below the Core Area values. So you add the coordinates of Warzaw (as a tuple) in the German slot in the data structure
I tried it but it didnt work out, any suggestion? (just so u know im trying to this in DOC mod)
 
How can I make it so a Civ changes it's capital on city acquired? (Like Turkey)

I've been messing with RFC a ton and changed Rome to being Italy. However on spawn they kiledl Roma which has 2 wonders (Including the very important AP) so my solution was to spawn them at Messina. Now unfortunately Rome is no longer their capital even on respawns. I kinda need a fix that hopefully could be done in python rather then C++.
 
Hello folks. I'm trying to add a barbarian spawn, namely the "sea peoples" who raided eastern mediterranean lands in the late bronze age. I want to spawn them as spearmen and axemen in galleys. To do this I copied the bits for adding settlers in galleys for a couple of the civ spawns, like this:

Code:
                if (iGameTurn >= getTurnForYear(-1200) and iGameTurn <= getTurnForYear(-1000)):
                        tSeaPlot = self.findSeaPlots((70, 39), 3, iBarbarian)
                if (tSeaPlot):                                
                        pBarbarian.initUnit(con.iGalley, tSeaPlot[0], tSeaPlot[1], UnitAITypes.UNITAI_SETTLER_SEA, DirectionTypes.DIRECTION_SOUTH)
                        utils.makeUnit(con.iSpearman, iBarbarian, tSeaPlot, 1)
                        utils.makeUnit(con.iAxeman, iBarbarian, tSeaPlot, 1)

replacing the civ capital plot which centered the plot search with a predetermined plot and allowing a radius of 3 around that plot and hoping to spawn the 3 units in that plot together.

I also copied the "def findSeaPlots" from RiseAndFall into Barbs.

so what I get is this: UnboundLocalError: local variable tSeaPlot referenced before assignment. I get the idea of what I've done wrong, but not how to fix it.
 
@srpt
Wrong indentation. In your code, tSeaPlot is defined only if the year condition is met, yet the second IF condition is checked every time. To fix the problem simply move the whole second IF block one tab to the right.
 
How can I make it so a Civ changes it's capital on city acquired? (Like Turkey)

I've been messing with RFC a ton and changed Rome to being Italy. However on spawn they kiledl Roma which has 2 wonders (Including the very important AP) so my solution was to spawn them at Messina. Now unfortunately Rome is no longer their capital even on respawns. I kinda need a fix that hopefully could be done in python rather then C++.
Consider yourself lucky, because it's possible in Python. Rhye does the capital switch together with the rename, so I suggest you simply look at his implementation in CityNameManager.onCityAcquired() - or simply search for "Istanbul" in that file. In practice, you don't have to do it in the city name manager, any instance of onCityAcquired() will do, e.g. in CvEventHandler.py.
 
Consider yourself lucky, because it's possible in Python. Rhye does the capital switch together with the rename, so I suggest you simply look at his implementation in CityNameManager.onCityAcquired() - or simply search for "Istanbul" in that file. In practice, you don't have to do it in the city name manager, any instance of onCityAcquired() will do, e.g. in CvEventHandler.py.

Thanks :)
 
As embryodead said, you lose the "Has" bit. Because the exception says just that - there is no method by that name belonging to the CyCity class. Look for yourself.

You have so much to learn about Python and how it is used with CivIV, so I suggest you get started. Once you get some of the basics in, this will be so much less painful for you!

Ok Baldyr, I know your frustrated with me, but I'm frustrated to...

CaslteRage.png


So, are you saying that I should remove the "has" from the code? Is that what I should do?
 
Back
Top Bottom