Announcement

Collapse
No announcement yet.

setting up the python files for a mod

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • setting up the python files for a mod

    hi,

    if you make your own mod, how do you set up the new python files?

    i understand you need the assets/python directory, what about the other files found with the civ4 mods (Entrypoint/ and Screens/)

    do i need to make a Cv[modname]EventManager.py, Cv[modname]GameUtils.py along with the Cv[modname].py?

    and is there a naming convention? do i have to have the python files named an exact way? asides when there's a class: name .. the file must be name.py right?

    I've been messing for a few hours looking for a way to get a simple welcome pop up at the game start. I basically copied from the desert war scenario, made the assets/XML/Text/[modname]GameTextInfos.xml (speaking of which is there a name convention to that too? if so how does it work?), made sure the code was okay - as best as i could - and well i don't get any pop up

    all i want it to do is pop up with "This is a test" in my own mod files.

  • #2
    If you want a popup at game start all you need to change is CvEventManager.py.

    In the onGameStart() function the Dawn of Man screen is already brought up 'through' a popup - that is a bit complicated but you don't need to worry about it.

    The old onGameStart() code:
    Code:
    	def onGameStart(self, argsList):
    		'Called at the start of the game'
    		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR")):
    			for iPlayer in range(gc.getMAX_PLAYERS()):
    				player = gc.getPlayer(iPlayer)
    				if (player.isAlive() and player.isHuman()):
    					popupInfo = CyPopupInfo()
    					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
    					popupInfo.setText(u"showDawnOfMan")
    					popupInfo.addPopup(iPlayer)
    Showing a random popup:

    Code:
    	def onGameStart(self, argsList):
    		'Called at the start of the game'
    		
    		popup = PyPopup.PyPopup(-1)
    		popup.setHeaderString("Test Popup Title")
    		popup.setBodyString("This is a Test Popup")
    		popup.launch(true, PopupStates.POPUPSTATE_QUEUED)
    		
    		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR")):
    			for iPlayer in range(gc.getMAX_PLAYERS()):
    				player = gc.getPlayer(iPlayer)
    				if (player.isAlive() and player.isHuman()):
    					popupInfo = CyPopupInfo()
    					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
    					popupInfo.setText(u"showDawnOfMan")
    					popupInfo.addPopup(iPlayer)
    This will just show a little popup when the game starts. Setting it to POPUPSTATE_QUEUED means it won't popup at the same exact time as another popup, and instead they will go in order. This is why a lot of screens are brought up 'as popups' - so that they don't come up at the same time as other stuff. If you change it from POPUPSTATE_QUEUED to POPUPSTATE_IMMEDIATE it will come up instantly without regards for whatever else is up.

    Comment


    • #3
      thanks, i figured out what to do though. at least i think i did.

      what i was missing in my moddir/assets/python was the directory entrypoints, that needed the file 'CvEventInterface.py' and in there i put in:
      Code:
      import CvUtil
      import CvTestEventManager
      from CvPythonExtensions import *
      
      normalEventManager = CvTestEventManager.CvTestEventManager()
      
      def getEventManager():
      	return normalEventManager
      
      def onEvent(argsList):
      	'Called when a game event happens - return 1 if the event was consumed'
      	return getEventManager().handleEvent(argsList)
      
      def applyEvent(argsList):
      	context, playerID, netUserData, popupReturn = argsList
      	return getEventManager().applyEvent(argsList)
      
      def beginEvent(context, argsList=-1):
      	return getEventManager().beginEvent(context, argsList)
      i only changed the second import line and the "normalEventManager =" line. was this a required step, and are all of those definitions required also?

      next, in my moddir/assets/python i have three files

      the first, CvTestGameUtils.py, i just copied from another mod and deleted most of the stuff except the first def where it does "self.parent = CvGameUtils.CvGameUtils" .. so basically copying all the functions from the main civ4 gameutils file? so is my copy even needed?

      my second python file is CvTestEventManager.py. i copied the desert war one, and i deleted all of the defs except the init (same as gameutils, is it copying all the default game defs, and then subsequent defs in the script simply add to the events?) and the "def onGameStart(self, argsList):" this is when i want the pop up to happen:
      Code:
      	def onGameStart(self, argsList):
      		'Called at the start of the game'
      		# display welcome message
      		self.parent.onGameStart(self, argsList)
      		dw.welcome()
      dw is defined a few lines above, i changed it to CvTest, which is my third file, that contains the def welcome:
      Code:
      	def displayWelcomePopup( self ):
      		"""At the start of the game, display a welcome message."""
      		popup = PyPopup.PyPopup()
      		popup.setHeaderString( localText.getText("TXT_KEY_DAWN_OF_MAN_SCREEN_TITLE", ()) )
      		popup.setBodyString( localText.getText("TXT_KEY_WW2_EVENT_BEGIN", ()) )
      		popup.launch()
      
      	def welcome( self ):
      		"""Sets everything up at the start of the game."""
      		self.displayWelcomePopup()
      seems like lots of files to get everything working. is there anything above that i didn't have to do? can i get things to work with just one eventmanager file?

      well anyway, i made it work, and suddenly most of the stuff started making more sense. i had just finished testing another event that rewarded several units when a tech is researched. i'm going to add a sort of on/off flag for that event next.

      loads of fun

      Comment


      • #4
        I'm less familiar with the Desert War structure as I did not work on that scenario. However, what they did is similar to what I've done in my own scenarios.

        That file structure is probably not the best thing to copy for simple mods. We at Firaxis did that in our scenarios because things were changing a lot and if each scenario had its own CvEventManager.py file then changes to the one for the main game would often not make it into the scenario versions... leading to bad things. So that's kind of a way around that such that only certain functions are overriden while keeping the default file intact. The only other advantage may be in making it easier to mix-and-match mods, but that's not something I've looked into too much.

        The code I posted above in only a single mod file (CvEventManager.py) will essentially do the same thing, only with fewer files. If all you want to accomplish is having a popup on game startup the ONLY thing you need to change is what I outlined in my post above.

        Comment

        Working...
        X