1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

The Modding Q&A Thread

Discussion in 'Rhye's and Fall Modmods' started by Leoreth, Apr 2, 2011.

  1. The Turk

    The Turk Chieftain

    Joined:
    Jun 25, 2008
    Messages:
    2,189
    Gender:
    Male
    Location:
    Canada
    So.... What do I cahnge :confused:

    Should I just move back all the indentions then? Anything else?
     
  2. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Also, the if should be an elif.
     
  3. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    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
     
  4. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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...
     
  5. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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)
     
  6. The Turk

    The Turk Chieftain

    Joined:
    Jun 25, 2008
    Messages:
    2,189
    Gender:
    Male
    Location:
    Canada
    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 :)
     

    Attached Files:

  7. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    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.
     
  8. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.
     
  9. The Turk

    The Turk Chieftain

    Joined:
    Jun 25, 2008
    Messages:
    2,189
    Gender:
    Male
    Location:
    Canada
    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"
     
  10. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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!
     
  11. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    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
     
  12. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.
     
  13. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    I tried it but it didnt work out, any suggestion? (just so u know im trying to this in DOC mod)
     
  14. KMRblue1027

    KMRblue1027 The Crown!

    Joined:
    Mar 4, 2010
    Messages:
    2,181
    Location:
    Hamilton, NJ
    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++.
     
  15. srpt

    srpt Deist

    Joined:
    May 10, 2010
    Messages:
    2,025
    Location:
    Toronto
    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.
     
  16. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    @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.
     
  17. srpt

    srpt Deist

    Joined:
    May 10, 2010
    Messages:
    2,025
    Location:
    Toronto
    thank you it works now. that was a dumb mistake.
     
  18. Leoreth

    Leoreth 心の怪盗団 Moderator

    Joined:
    Aug 23, 2009
    Messages:
    33,048
    Gender:
    Male
    Location:
    Leblanc
    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.
     
  19. KMRblue1027

    KMRblue1027 The Crown!

    Joined:
    Mar 4, 2010
    Messages:
    2,181
    Location:
    Hamilton, NJ
    Thanks :)
     
  20. The Turk

    The Turk Chieftain

    Joined:
    Jun 25, 2008
    Messages:
    2,189
    Gender:
    Male
    Location:
    Canada
    Ok Baldyr, I know your frustrated with me, but I'm frustrated to...



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

Share This Page