Page 2 of 4 FirstFirst 1 2 3 4 LastLast
Results 31 to 60 of 113

Thread: Initial Python reference

  1. #31
    Mylon
    Warlord
    Join Date
    31 Oct 2005
    Posts
    145
    Country
    This is Mylon's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    You can't just change the value of YieldTypes.YIELD_FOOD though, that's just the index of the food value, not the actual food value. You can't manipulate in-game variables such as food, hitpoints, etc directly, you have to do so through functions. The onCityDoTurn event gives you a city argument, so the second line in your example would have to be something like:

    Code:
    pCity.changeFood(Pycity.getFoodRate() * (getGoodHealth() -  getBadHealth()) * 0.05)
    I took the popup code and added it in a bunch of different places: onCityDoTurn, onPlayerEndTurn, OnCultureExpansion... But they never showed up, which suggests that even a changefood command wouldn't process.

  2. #32
    Locutus
    Deity Locutus's Avatar
    Join Date
    23 Nov 1999
    Location
    De Hel van Enschede
    Posts
    11,706
    Country
    This is Locutus's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    23:53
    Then you're doing something wrong, because it works for me. Can you post the exact file you're testing with?
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

  3. #33
    TheDarkside
    Prince TheDarkside's Avatar
    Join Date
    29 Oct 2001
    Location
    New York
    Posts
    586
    Country
    This is TheDarkside's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    17:53
    Originally posted by Locutus


    You have to use attachMultilineText instead of setText or whatever is currently used. The civilopedia file (CvPedia*) have a number of examples of this.

    Thanks for the reply Locutus!

    What I mean is I'm writing text to a panel and it's clipping vertically, not horizontally... It's a list of text (in the Civolopedia actually) but it's too long to show all at once so it goes off the bottom edge...

  4. #34
    Locutus
    Deity Locutus's Avatar
    Join Date
    23 Nov 1999
    Location
    De Hel van Enschede
    Posts
    11,706
    Country
    This is Locutus's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    23:53
    Vertical, horizontal, it's all the same with attachMultilineText, if I'm not mistaken. The two booleans you have to give when adding the panel determine the type of scroll you get, play around with those.
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

  5. #35
    Mylon
    Warlord
    Join Date
    31 Oct 2005
    Posts
    145
    Country
    This is Mylon's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    I'm taking the entire CvEventManager.py file and adding the popup to it inside one of the functions:

    Code:
    	def onCultureExpansion(self, argsList):
    		'City Culture Expansion'
    
    		popup = PyPopup.PyPopup()
    		popup.setBodyString( 'Hello World' )
    		popup.launch()
    		
    		pCity = argsList[0]
    		iPlayer = argsList[1]
    		CvUtil.pyPrint("City %s's culture has expanded" %(pCity.getName(),))
    I can't say I'm experienced with Python or object oriented language for that matter, so I don't know how to properly initialize a file, so I just used an already existing one. I also added the same popup code to other functions in the same file, such as OnEndTurn, OnCityDoTurn, ect... Just as a kind of troubleshooting to see if the commands are being processed.
    Mylon Mod - Adressing game pace and making big cities bigger.
    Inquisition Mod - Exterminating heretic religions since 1200 AD

  6. #36
    Mylon
    Warlord
    Join Date
    31 Oct 2005
    Posts
    145
    Country
    This is Mylon's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    Okay, it seems that the problem is that the python files weren't updating. The cache needed to be cleared.
    Mylon Mod - Adressing game pace and making big cities bigger.
    Inquisition Mod - Exterminating heretic religions since 1200 AD

  7. #37
    Jon Shafer
    Firaxis Games Programmer/Designer
    Join Date
    09 Apr 2002
    Location
    Maryland
    Posts
    9,566
    Country
    This is Jon Shafer's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    17:53
    Are you modifying the main game files or using a Mod folder?

  8. #38
    Mylon
    Warlord
    Join Date
    31 Oct 2005
    Posts
    145
    Country
    This is Mylon's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    I'm using a mod folder, but I'm also launching the game directly into the mod using the command line. Still, even before I did that I wasn't getting any error messages.

    Error messages are something I'm familiar and comfortable with. Changing files and seeing no result at all is not.

  9. #39
    Mylon
    Warlord
    Join Date
    31 Oct 2005
    Posts
    145
    Country
    This is Mylon's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    Okay, on another note, I'm having a hard time changing the food rate of the city. I believe it's a type-casting error: My formula mixes integers and a float, and passes the result of this formula to a function expecting an integer. Typecasting really bugged the heck out of me in C, so could I get some help on this?

    The code I'm using now is:
    Code:
                    HealthyFood = getFoodRate(pCity) * (getGoodHealth(pCity) -  getBadHealth(pCity)) * 0.1
    		pCity.changeFood(HealthyFood)
    If I use pCity.changeFood(10) it works just fine.

    Neither does pCity.changeFood(getGoodHealth(pCity)) or pCity.changeFood(pCity.getGoodHealth()) oddly enough.
    Last edited by Mylon; November 6, 2005 at 10:36.
    Mylon Mod - Adressing game pace and making big cities bigger.
    Inquisition Mod - Exterminating heretic religions since 1200 AD

  10. #40
    Jon Shafer
    Firaxis Games Programmer/Designer
    Join Date
    09 Apr 2002
    Location
    Maryland
    Posts
    9,566
    Country
    This is Jon Shafer's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    17:53
    You can just cast HealthyFood to an int as you pass it into that function.
    Code:
    pCity.changeFood(int(HealthyFood))

  11. #41
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    16:53
    For the onUnitMove() function... Is there any way to get both the original and destination plot locations? Obviously the destination is the value of pPlot (or pUnit.pPlot()). But I can't see any way to figure out where the unit came from.

    Alternatively, is there any event trigger that can be called before the unit is moved (but after the move order has been issued)?

    Bh

  12. #42
    The_Aussie_Lurker
    King
    Join Date
    06 May 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    1,457
    Country
    This is The_Aussie_Lurker's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    Hi Trip, is there a way of switching the Health and food values-such that Health dictates population growth and Food surplus/deficit dictates the health bonus/penalty? If so, where will I find it in the scripts?
    Thanks a bunch !

    Yours,
    Aussie_Lurker.

    P.S. In combination with that, how do I add/subtract the things which contribute to health/unhealth?

  13. #43
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    16:53
    Another question - it's possible to add new Promotion types, yes? I haven't been able to successfully do so at this point, just want to make sure I'm not banging my head against the wall pointlessly.

    edit: nm, got it working. Apparently if you add a new promotion type and try and load an old savegame, it'll die, but if you start a new one, it works fine.

    Bh
    Last edited by Bhruic; November 8, 2005 at 23:56.

  14. #44
    Locutus
    Deity Locutus's Avatar
    Join Date
    23 Nov 1999
    Location
    De Hel van Enschede
    Posts
    11,706
    Country
    This is Locutus's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    23:53
    Originally posted by Bhruic
    Obviously the destination is the value of pPlot (or pUnit.pPlot()).
    Actually, I'm about 99% sure pPlot is the original plot and pUnit.plot() the destination.

    Alternatively, is there any event trigger that can be called before the unit is moved (but after the move order has been issued)?
    No, we'll have to add that ourselves when the SDK comes out.
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

  15. #45
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    16:53
    Originally posted by Locutus
    Actually, I'm about 99% sure pPlot is the original plot and pUnit.plot() the destination.
    I'd hate to argue with you, but I'm pretty sure it's not.

    I did a popup that displayed the getX/getY values for both, and they were always identical.

    Bh

  16. #46
    LDiCesare
    Emperor
    Join Date
    03 Jan 2001
    Location
    Ashes
    Posts
    3,215
    Country
    This is LDiCesare's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    23:53
    I'm trying to see if I can add an option to the diplo screen, namely:
    Allow the player to offer declare war on opponent in exchange of whatever. Currently, I can declare war on Cyrus when Peter asks me to, but I can't barter and agree in exchange of this or that tech (but I can get Alex to fight Mansa Musa in exchang of Biology). This is asymetrical, the player cannot do what the ai can (and vice versa).
    So I tried to do it, but don't know where to find CyDiplomacy?
    I'll probably try to simplify the accept trade/neogtiate etc which I find really clunky to work with but for the moment I can't find where the screen class really is and that bothers me. Any ideas?
    Clash of Civilization team member
    (a civ-like game whose goal is low micromanagement and good AI)
    web site http://clash.apolyton.net/frame/index.shtml and forum here on apolyton)

  17. #47
    vovan
    Emperor vovan's Avatar
    Join Date
    23 Oct 2001
    Posts
    5,725
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    15:53

    Re: Initial Python reference

    Question. This here event:

    Originally posted by Locutus
    onCityAcquired
    'City Acquired'
    arguments: owner,playerType,city,bConquest,bTrade
    What are the parameters exactly? 'owner' - is that the person that lost the city or that got the city? Same for 'playerType'? And for 'city.getOwner()', has that already been set to the new owner, or is it at this point still for the original owner?

    Thanks,
    Vovan

  18. #48
    eotinb
    Settler
    Join Date
    30 Oct 2005
    Posts
    7
    Country
    This is eotinb's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    A couple of (I hope) easy questions:

    1. In the reportEvent function of CvEventManager.py there is a reference to Events.log. Where is this file? Does CvUtil.PyPrint() print to it?

    2. Can I get more detail about the arguments to CyInterface().addMessage()? The API reference is kind of vague.

  19. #49
    Sessil3
    Chieftain
    Join Date
    31 Oct 2005
    Posts
    38
    Country
    This is Sessil3's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    Thanks a lot for the class reference, Locutus. You own. I detected an error in the api if you want to fix the master:
    CvCity::getProduction() does return an int, and it is the base production of that city at that moment, not a boolean.

    I'm now trying to figure out how to change that base :]

  20. #50
    sabrewolf
    Emperor sabrewolf's Avatar
    Join Date
    10 Jun 2002
    Location
    turicum, helvetistan
    Posts
    9,852
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    22:53
    i looked through this and other threads and some things are not yet very clear to me:

    * what if i only want to overwrite parts of the things. for instance i want to add my own additional keyboard shortcuts for my notebook. eg. ALT-right moves the unit right.
    how could i make sure that that works but keeps everything else the same? is that possible?

    * is there a "safe" way to add such stuff to the normal game (not a special mod) without fiddling around with the game's own "asset" folder? please note: this should be UI only
    - Artificial Intelligence usually beats real stupidity
    - Atheism is a nonprophet organization.

  21. #51
    CAB
    Settler
    Join Date
    31 Dec 1969
    Location
    Sweden
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    I'm trying to lear a thing or two here and I tried using your code.

    I replaced this lines in the CvEventManager.py file

    PHP Code:
    def onCityBuilt(selfargsList):
          
    'City Built'
          
    city argsList[0]
          if (
    city.getOwner() == CyGame().getActivePlayer()):
               
    self.__eventEditCityNameBegin(city)    
          
    CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
          
    popup PyPopup.PyPopup()
          
    popup.setBodyString'Hello World' )
          
    popup.launch()
          
    city.getOwner().initUnit(17city.getX(), city.getY(), UnitAITypes.NO_UNITAI
    The popup box shows but no unit is spwned in the city, I have tried the documentation and I can't find whats wrong here.

    I also tried your original code, no luck there either, the popup box shows but no unit is spawned. What is wrong???

  22. #52
    CAB
    Settler
    Join Date
    31 Dec 1969
    Location
    Sweden
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    Hummm, ok i reply to my self here.


    I inserted this Row..
    gc.getPlayer(CyGame().getActivePlayer()).initUnit( 17,city.getX(),city.getY(),UnitAITypes.NO_UNITAI)

    Instead of this...
    city.getOwner().initUnit(17, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)

    Seemed to work, now could anyone explain to me if there was something wrong with the original code or have I forgot to import a module into the CvEventManager.py file???

    I'm lost here!?!?

  23. #53
    PJayTycy
    King
    Join Date
    23 Apr 2005
    Posts
    1,709
    Country
    This is PJayTycy's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    22:53
    Enable python error messages in the civ .ini file and enable logging. They will tell you what's wrong.

    My guess would be that either city.getOwner() doesn't exists or it returns an integer so you should wrap it with gc.getPlayer(...) like you did in the new line you used. (I couldn't find it in the python api, but maybe city here is not of the CyCity type)
    no sig

  24. #54
    CAB
    Settler
    Join Date
    31 Dec 1969
    Location
    Sweden
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    the city.(getowner()) works even better than CyGame().getActivePlayer() because the latter give me a unit for all cities created the first only the owner.

    city is a variable containing the newly created city defined in the line...

    city = argsList[0]

    Now i have bin able to make this work, but I can't figure out how to add promotions. I have looked around in other mods that adds them but it does not see, to work.

    I try to add the "combat I" promotion but it will simply not be attached.

    I added the line setHasPromotion(0,TRUE) so the last line would be then...

    gc.getPlayer(city.(getowner()).initUnit(17,city.ge tX(),city.getY(),UnitAITypes.NO_UNITAI).setHasProm otion(0,TRUE)

    this should add a promotion type Combat I

  25. #55
    jimmyh
    Warlord
    Join Date
    18 Sep 2001
    Location
    Sunny Old England
    Posts
    161
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    Does any one know if it's posibble to force the Technology Discovered popup dialog appear.

    I want to use the setHasTech api call and display the popup, i have the call working but no popup appears.

  26. #56
    PJayTycy
    King
    Join Date
    23 Apr 2005
    Posts
    1,709
    Country
    This is PJayTycy's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    22:53
    how do I pass a null-pointer to a function ?
    eg: for the argument "CyCity* pSkipCity = NULL" in CyMap.findCity( ... )

    When I tried this in the in-game python console, I got errors about Null, NULL, null being unknown. Just passing a 0 got me the error "arguments "..., ..., int" don't match "..., ..., CyCity* ". Passing an empty list [] didn't work either.



    Oh, and btw: could it be that "onUnitLost" has more arguments than only pUnit ? With this code:
    Code:
    	def onUnitLost(self, pUnit):
    		if pUnit.getUnitClassType() == self.iUnitClassHarvester :
    			self.hu.lostHarvester(pUnit)
    I always get the error getUnitClassType() can't be executed on a tuple.
    Last edited by PJayTycy; November 17, 2005 at 20:51.
    no sig

  27. #57
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    great thread!

    one question:

    i try to implement a wonder which provides a unit/or a certain tech (no free tech like in the xml file).
    the 'onCityBuilt' example combined with the 'onBuildingBuilt' command is maybe a ?good idea to make this work - but i'm too stupid (learning python in a few days is a hard job) - the game don't do i want them to do.

    can some1 help me?
    Last edited by GIR; November 26, 2005 at 07:57.

  28. #58
    Mylon
    Warlord
    Join Date
    31 Oct 2005
    Posts
    145
    Country
    This is Mylon's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    I don't feel like looking up the API, so double check this code before you use it!
    During OnBuildingBuilt:

    if iBuilding == gc.getInfoTypeForString('BUILDING_YOURWONDER')
    (tab) iPlayer = pCity.getOwner()
    (tab) gc.setPlayerHasTech(iPlayer, gc.getInfoTypeForString('TECH_YOURTECH').

    And there ya go.
    Mylon Mod - Adressing game pace and making big cities bigger.
    Inquisition Mod - Exterminating heretic religions since 1200 AD

  29. #59
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    21:53
    big thx Mylon for you help, the whole day i am trying to get it running!
    this looks like a simple way but i think i make something wrong, because the game says:

    Failed to load python module CvEventInterface.

    her is the part i includet to the onbuildingbuilt:

    PHP Code:

            
    if iBuilding == gc.getInfoTypeForString'BUILDING_STONEHENGE' ):
                
    iPlayer pCity.getOwner()
                
    gc.setPlayerHasTech(iPlayergc.getInfoTypeForString'TECH_ROCKETRY' 
    Last edited by GIR; November 26, 2005 at 17:05.

  30. #60
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    May 24, 2013
    Local Time
    16:53
    The code you added should look like:
    PHP Code:
    if iBuildingType == gc.getInfoTypeForString'BUILDING_STONEHENGE' ):

                
    pPlayer gc.getPlayer(pCity.plot().getOwner())

                
    gc.getTeam(pPlayer.getTeam()).setHasTech(gc.getInfoTypeForString'TECH_ROCKETRY' ), truepPlayer.getID(), falsefalse
    edit: Made slight change

    Bh
    Last edited by Bhruic; November 26, 2005 at 14:57.

Page 2 of 4 FirstFirst 1 2 3 4 LastLast

Similar Threads

  1. python import of external python question
    By DougM in forum Civilization IV Creation
    Replies: 0
    Last Post: February 8, 2006, 15:34
  2. Python reference question
    By vovan in forum Civilization IV Creation
    Replies: 4
    Last Post: November 1, 2005, 11:02
  3. CIV 4 - Initial Python Reference y una Utilidad
    By OBV in forum Civilization en Español
    Replies: 3
    Last Post: October 26, 2005, 19:34
  4. Replies: 14
    Last Post: March 23, 2003, 12:11
  5. mod cross-reference
    By seawolfe in forum CtP2-Creation/AI/Mods/Scenarios-Archive
    Replies: 4
    Last Post: February 15, 2002, 13:37

Visitors found this page by searching for:

powered by vBulletin reference

civ4 python api onsavegame

civilizaton 3 pyton scripti

initial python

techacquired civ5

civ iv cultural citystyles and roads

send string python to dll civfanatics

civilization 4 python reference

initial references page

CvUtil.pyPrint

civ4 trigger(gc.getInfoTypeForString position

CvUnitInfo civ4

civilization 4 onbeginplayerturn

civ4 colonization python addcombatmessage

civ5 add new promotion

civ4 python city object

cvi4 gc.getinfotypeforstring

civ 4 change specialistinfos

how to make a python map civ 4

civ4 python check player has tech

civilization iv cant start pyhton

civilization 5 pplayer

civ4 gc.getinfotypeforstring(improvement_farm)

civfanatics g&k unitaitype

pplot documentation python

Bookmarks

Posting Permissions