adding an event

BobeBrown

Warlord
Joined
Oct 4, 2009
Messages
255
Very stuck for last few hours. Im trying to add an event to bug.

Its the python from a modcomp called Real Always War, its all python.

All that the creator says you need is this.

Code:
def onGameStart(self, argsList):
		'Called at the start of the game'
###real always war start
		if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ALWAYS_WAR):
                        for i in xrange(gc.getMAX_CIV_TEAMS ()):
                                FirstTeam = gc.getTeam(i)
                                if FirstTeam.isHuman():continue
                                for j in xrange(gc.getMAX_CIV_TEAMS ()):
                                        SecondTeam = gc.getTeam(j)
                                        if SecondTeam.isHuman():continue
                                        if i==j:continue
                                        FirstTeam.declareWar(j,False,WarPlanTypes.WARPLAN_TOTAL)
                                        FirstTeam.setPermanentWarPeace(j,True)
                                        SecondTeam.declareWar(i,False,WarPlanTypes.WARPLAN_TOTAL)
                                        SecondTeam.setPermanentWarPeace(i,True)
###real always war end		
		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
			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)
		else:
			CyInterface().setSoundSelectionReady(true)

		if gc.getGame().isPbem():
			for iPlayer in range(gc.getMAX_PLAYERS()):
				player = gc.getPlayer(iPlayer)
				if (player.isAlive() and player.isHuman()):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_DETAILS)
					popupInfo.setOption1(true)
					popupInfo.addPopup(iPlayer)

		CvAdvisorUtils.resetNoLiberateCities()

So i made my own python file called mw.py for my mod MW

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
    Lucky Charms - Provides various free goodies at random
-->
<mod id="MW" module="mw">
    <event type="GameStart" function="onGameStart"/>
</mod>




#mw

from CvPythonExtensions import *
import BugUtil

gc = CyGlobalContext()


	def onGameStart(self, argsList):
		'Called at the start of the game'
###real always war start
		if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ALWAYS_WAR):
                        for i in xrange(gc.getMAX_CIV_TEAMS ()):
                                FirstTeam = gc.getTeam(i)
                                if FirstTeam.isHuman():continue
                                for j in xrange(gc.getMAX_CIV_TEAMS ()):
                                        SecondTeam = gc.getTeam(j)
                                        if SecondTeam.isHuman():continue
                                        if i==j:continue
                                        FirstTeam.declareWar(j,False,WarPlanTypes.WARPLAN_TOTAL)
                                        FirstTeam.setPermanentWarPeace(j,True)
                                        SecondTeam.declareWar(i,False,WarPlanTypes.WARPLAN_TOTAL)
                                        SecondTeam.setPermanentWarPeace(i,True)
###real always war end		
		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
			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)
		else:
			CyInterface().setSoundSelectionReady(true)

		if gc.getGame().isPbem():
			for iPlayer in range(gc.getMAX_PLAYERS()):
				player = gc.getPlayer(iPlayer)
				if (player.isAlive() and player.isHuman()):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_DETAILS)
					popupInfo.setOption1(true)
					popupInfo.addPopup(iPlayer)

		CvAdvisorUtils.resetNoLiberateCities()

Does not work. Its gota be simple right lol? But i really cant get it working . CAn someone help please
 
For a start, in this line of code:

def onGameStart(self, argsList):

Remove the word "self".

The BUG method you're using doesn't need it. I'm sure EF will have something more intelligent to say, but thats a good place to start. :)
 
For a start, in this line of code:



Remove the word "self".

The BUG method you're using doesn't need it. I'm sure EF will have something more intelligent to say, but thats a good place to start. :)

Did not work :/

I also tried adding this to BugEventManager, but no luck. Anyone share some knowledge?
 
Always post the PythonErr.log and PythonDbg.log files or we can only guess at what's wrong. Yes, remove "self". Also, remove one level of indentation of everything starting with the "def" line and remove everything after the "###real always war end" line. If you leave that last stuff in it will get run twice: once for your event and again as part of CvEventManager from where it comes.
 
So it now looks like this.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
    Lucky Charms - Provides various free goodies at random
-->
<mod id="MW" module="mw">
    <event type="GameStart" function="onGameStart"/>
</mod>




#mw

from CvPythonExtensions import *
import BugUtil

gc = CyGlobalContext()


	def onGameStart(argsList):
		'Called at the start of the game'
###real always war start
		if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ALWAYS_WAR):
                        for i in xrange(gc.getMAX_CIV_TEAMS ()):
                                FirstTeam = gc.getTeam(i)
                                if FirstTeam.isHuman():continue
                                for j in xrange(gc.getMAX_CIV_TEAMS ()):
                                        SecondTeam = gc.getTeam(j)
                                        if SecondTeam.isHuman():continue
                                        if i==j:continue
                                        FirstTeam.declareWar(j,False,WarPlanTypes.WARPLAN_TOTAL)
                                        FirstTeam.setPermanentWarPeace(j,True)
                                        SecondTeam.declareWar(i,False,WarPlanTypes.WARPLAN_TOTAL)
                                        SecondTeam.setPermanentWarPeace(i,True)
###real always war end

PythonErr.log was empty.
other is attached.


Plus EmperorFool, Im trying to add a corporation to my mod. It goes a lil hayware inside the sevopedia of Bug. I searched your website and this website for any information on adding a corporation to python and did not find anything. Can you point me in right direction to find that information please?
 
Looks like you aren't loading the above XML file from init.xml or any other configuration XML file.
 
Well i have no idea what I need to add and where I need to add it. Its rather confusing and theres very little information any forum to learn how to add events with BUG
 
Yes, my sig contains a link to the BUG Modding Tutorial which describes the full process of adding events. You'll want to jump to the configuration section to see how to load your XML file from init.xml.
 
In init.xml, add your module as follows:

Code:
    <load mod="MapFinder"/>
    <load mod="Advanced Combat Odds"/>
    
    <!-- BUFFY -->
    
    <load mod="BUFFY"/>
    
    [COLOR=Red][B]<!-- New Mods -->[/B][/COLOR]  [B](Add the line in red, and the one below at this point)[/B]
    
    [COLOR=Red][B]<load mod="Name of your mod goes here"/>[/B][/COLOR]
    
    <!-- Options Screen -->
    
    <screen id="BUGFull">
        <tab module="BugGeneralOptionsTab"/>
        <tab module="BugMapOptionsTab"/>
        <tab module="BugCityScreenOptionsTab"/>
That should help get you part of the way there at least. It should load then, but you might still have some debugging to do. Hope that helped. :)
 
Top Bottom