Hephaistion
Warlord
To any Python-heads who'd like to help me:
I've been trying to get my BtS mod to use Dr.G's CvCustomEventManager and have been getting some major headaches and have not been able to figure out how to cure them myself.
At the moment I'm just trying to implement some very simple code to prevent a city building a building (pagan temple) if a religion is present in the city. Now, I know the code works because I've used it after adding it directly into a copy of CvGameUtils under 'def cannotConstruct' and enabling that callback function in PythonCallbacks.xml. I want to use the CustomEventManager, though, so I can more easily keep track of my mods and make them modder-friendly for others.
So I have Dr. G's CvCustomEventManager import my utilities file, HephUtils.py. At first, this file would not get imported at all. THen I added CvEventInterface in the EntryPoints folder from Civ4lerts (I also tried another version from EnhancedCUlturalDecay mod). The game loads up my modded files, but I get a whole load of errors saying it can't find CvEventInterface.
Here's my CvCustomEventManager:
and
HephUtils:
CvEventInterface (in EntryPoints):
And, PythonErr:
PythonErr2:
What did I do wrong?
I've been trying to get my BtS mod to use Dr.G's CvCustomEventManager and have been getting some major headaches and have not been able to figure out how to cure them myself.
At the moment I'm just trying to implement some very simple code to prevent a city building a building (pagan temple) if a religion is present in the city. Now, I know the code works because I've used it after adding it directly into a copy of CvGameUtils under 'def cannotConstruct' and enabling that callback function in PythonCallbacks.xml. I want to use the CustomEventManager, though, so I can more easily keep track of my mods and make them modder-friendly for others.
So I have Dr. G's CvCustomEventManager import my utilities file, HephUtils.py. At first, this file would not get imported at all. THen I added CvEventInterface in the EntryPoints folder from Civ4lerts (I also tried another version from EnhancedCUlturalDecay mod). The game loads up my modded files, but I get a whole load of errors saying it can't find CvEventInterface.
Here's my CvCustomEventManager:
Code:
import CvEventManager
# HephMod ##########################
import HephUtils
#####################################################
class CvCustomEventManager(CvEventManager.CvEventManager, object):
and
Code:
def __init__(self, *args, **kwargs):
super(CvCustomEventManager, self).__init__(*args, **kwargs)
# map the initial EventHandlerMap values into the new data structure
for eventType, eventHandler in self.EventHandlerMap.iteritems():
self.setEventHandler(eventType, eventHandler)
# --> INSERT EVENT HANDLER INITIALIZATION HERE <--
HephUtils.HephUtils(self)
HephUtils:
Code:
import CvUtil
from CvPythonExtensions import *
# globals
gc = CyGlobalContext()
class HephUtils:
def cannotConstruct(self,argsList):
pCity = argsList[0]
eBuilding = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
#player can't build pagan temple if they have a religion
if eBuilding == gc.getInfoTypeForString("BUILDING_TP_PAGAN_TEMPLE"):
if pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_JUDAISM")) or pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_CHRISTIANITY")) or pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_ISLAM")) or pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_HINDUISM")) or pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_BUDDHISM")) or pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_CONFUCIANISM")) or pCity.isHasReligion(gc.getInfoTypeForString("RELIGION_TAOISM")):
return True
return False
CvEventInterface (in EntryPoints):
Code:
import CvUtil
from CvPythonExtensions import *
import CvCustomEventManager
normalEventManager = CvCustomEventManager.CvCustomEventManager()
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)
And, PythonErr:
Code:
Traceback (most recent call last):
ERR: Call function onEvent failed. Can't find module CvEventInterface
File "<string>", line 1, in ?
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
File "<string>", line 52, in load_module
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
File "CvEventInterface", line 18, in ?
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
File "CvCustomEventManager", line 73, in __init__
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
TypeError
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
:
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
this constructor takes no arguments
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
Failed to load python module CvEventInterface.
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
PythonErr2:
Code:
load_module HephUtils
Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 18, in ?
File "CvCustomEventManager", line 73, in __init__
TypeError: this constructor takes no arguments
What did I do wrong?