• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

[PYTHONCOMP] Civ4lerts: Alert messages about in game events

You have to merge the two mods. You'll need a merged .ini file, and if the other one also has some Python code then you may need to reconcile the two sets of code.

Which mods do you want to merge? Civ4lerts is already a component of the HoF Mod, along with several other mods.
How does one merge two mods? I'd like to use this with Ethnic Artstyles for BtS.

Also, was this issue ever resolved:

Anyone knows if theres a way to turn off the happines and health warnings? I been using this mod sicne yesterday, and love it, only thing that bothers me is that even if your city is one turn away to get unhealthy/unhappy even if you turn on the "no growth" option it keeps spammingthe message every turn. Gets disturbing when you have 6+ cities on that state
 
Hey, you're right! And I thought it was replaced by CvRandomEventInterface.py, since CvEventInterface.py is not any of the BtS folders. Only later have I seen that other files are missing as well, presumably because they haven't been changed since the last version.
 
I tried putting all the files together into one folder called "Ethnic Artstyles" then selected the "Ethnic Artstyles" mod from within BtS. I found that my tech screens no longer popped up, and that neither Civ4lerts or Unit Statistics worked properly.

I then deleted my merged mod and tried loading Civ4lerts as a mod by itself. I found that this didn't work either. The OP doesn't seem to tell you how to install the mod, so could someone please tell me how to do that as a starting point?

Once I know that I can get this mod to work, then I can look at the merging issue again.
 
Dr. Elmer Jiggle's CustomEventManager, it seems to port to BtS will no problems.

Normally, "port" implies that you need to modify it to handle differences in the two games. Did you have to change anything, or can you confirm that using the Warlords version as-is works in BtS? I'm putting together a mashup of various interface mods with NikNaks93, and this is at the top of the list. :)
 
Normally, "port" implies that you need to modify it to handle differences in the two games. Did you have to change anything, or can you confirm that using the Warlords version as-is works in BtS? I'm putting together a mashup of various interface mods with NikNaks93, and this is at the top of the list. :)

Just so there is no misunderstanding, the same version of the CustomEventManager that worked in Vanilla and Warlords also seems to work in BtS. I've used it, completly unmodified in several different mods, and several different games and have not run into any problems. :king:


However, if anyone is using his CvConfigParser you will have to make one addition to make it function.
Open up CvPath.py.
Look for..
Code:
def _getInstallDir():
    gc = CyGlobalContext()
    subkey = r"Software\Firaxis Games\Sid Meier's Civilization 4"
    if ((gc.getDefineINT("CIV4_VERSION") / 100) == 2):
        subkey += r" - Warlords"
    return __getRegValue(_winreg.HKEY_LOCAL_MACHINE, subkey, "INSTALLDIR")
and change it to this..
Code:
def _getInstallDir():
    gc = CyGlobalContext()
    subkey = r"Software\Firaxis Games\Sid Meier's Civilization 4"
    if ((gc.getDefineINT("CIV4_VERSION") / 100) == 2):
        subkey += r" - Warlords"
    elif ((gc.getDefineINT("CIV4_VERSION") / 100) == 3):
        subkey += r" - Beyond the Sword"
    return __getRegValue(_winreg.HKEY_LOCAL_MACHINE, subkey, "INSTALLDIR")

Alternatly, in many mods that release versions specific to Warlords or Vanilla (TheLopez's mods would be a good example, and that is where I'm pasting this code from :P) you should look for this..
Code:
def _getInstallDir():
    civ4Dir = __getRegValue(_winreg.HKEY_LOCAL_MACHINE, 
            r"Software\Firaxis Games\Sid Meier's Civilization 4",
            "INSTALLDIR")
    civ4Dir = os.path.join(civ4Dir,"Warlords")
    return civ4Dir
and make it look like this..
Code:
def _getInstallDir():
    civ4Dir = __getRegValue(_winreg.HKEY_LOCAL_MACHINE, 
            r"Software\Firaxis Games\Sid Meier's Civilization 4",
            "INSTALLDIR")
    civ4Dir = os.path.join(civ4Dir,"Beyond the Sword")
    return civ4Dir

I have not thoroughly tested it, but my quick checks worked just fine, it found and read values from an ini file. I changed the values, reloaded the mod, and it read the newly changed values.

Hope this helps someone. :)
 
First post, new to python.
I've tried to merge this mod with unit statistic mod for bts.
The initial customeventmanager.py file in civ4lert file start like this:

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 <--
        Civ4lerts.Civ4lerts(self)

To merge the two mod, I add one line to the end of this block like this:

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 <--
       Civ4lerts.Civ4lerts(self)
      CvUnitStatisticsEventManager.CvUnitStatisticsEventManager(self)

The result is, Civ4lert mod doesn't work anymore. I'm confused.

I'm a newbie and this may sound foolish, but I would like very much to learn to code and any help is appreciated, thx!
 
First thing to do, open you CivilizationIV.ini file and search for an option that that says somthing like
'Set to 1 to hide Python exceptions'
Set that option to 0.

Then load your mod and see if any errors popup. They should tell you what file and line the error is in. If you need help decifering the errror popup, just post it here and I'll walk you through it.

One thing though, in your posted code block, the line you added isn't lined up with the line above it. Don't know if that is just from the text getting post on the thread, but just FYI, in python spacing is very important, so make sure everything is indented correctly.

Other then that, yea, you should just have to add that line you added and put the files from both mods into one mod and it should work. :)
 
Thanks a lot Jeckel:) Yes, the line didn't lined up only in my last post but not in the code i'm using.

I did what you instructed, changed the civilization.ini file and ran the mod, it gave me the following error message

1. Trackback (most recent call last):

2. File"<string>", line1,in?

3. File"<string>", line52, in load_module

4. File"CvEventInterface", line 13, in?

5. File"<string>", line52, in load_module

6. File"CvCustomEventManager", line26, in?

7. ImportError

8. : (ye, just a colon)

9. No module named CvUnitStatisticsEventManager

10. (nothing, just blank)

11. Failed to load python module CvEventInterface

I just added the line "import CvUnitStatisticsEventManager" and the line I mentioned in my last post, and it gives me 11 error messages, truly generous:lol:

These messages may mean something to me standalone but altogether they make me confused. Any idea what I have messed up?
 
Hehe, yea, when there are a bunch of errors it can be daunting. ;)

That error though is saying it can't find the CvUnitStatisticsEventManager.py file. Did you put the Unit Statistics files in with the Alert mod files?
 
J
However, if anyone is using his CvConfigParser you will have to make one addition to make it function.
Open up CvPath.py.
Look for..
Code:
def _getInstallDir():
    gc = CyGlobalContext()
    subkey = r"Software\Firaxis Games\Sid Meier's Civilization 4"
    if ((gc.getDefineINT("CIV4_VERSION") / 100) == 2):
        subkey += r" - Warlords"
    return __getRegValue(_winreg.HKEY_LOCAL_MACHINE, subkey, "INSTALLDIR")
and change it to this..
Code:
def _getInstallDir():
    gc = CyGlobalContext()
    subkey = r"Software\Firaxis Games\Sid Meier's Civilization 4"
    if ((gc.getDefineINT("CIV4_VERSION") / 100) == 2):
        subkey += r" - Warlords"
    elif ((gc.getDefineINT("CIV4_VERSION") / 100) == 3):
        subkey += r" - Beyond the Sword"
    return __getRegValue(_winreg.HKEY_LOCAL_MACHINE, subkey, "INSTALLDIR")

This can cause problems if you auto-load your mod, ie specify in CivilizationIV.ini:
Mod = Mods/My Mod

It doesn't appear that the civ version number is defined when the game first loads the python files. I think it works fine if you use the more normal 'Load a Mod' option after starting up the main game. Just a heads up, and the solution is to just use the other version you mention:

Alternatly, in many mods that release versions specific to Warlords or Vanilla (TheLopez's mods would be a good example, and that is where I'm pasting this code from :P) you should look for this..
Code:
def _getInstallDir():
    civ4Dir = __getRegValue(_winreg.HKEY_LOCAL_MACHINE, 
            r"Software\Firaxis Games\Sid Meier's Civilization 4",
            "INSTALLDIR")
    civ4Dir = os.path.join(civ4Dir,"Warlords")
    return civ4Dir
and make it look like this..
Code:
def _getInstallDir():
    civ4Dir = __getRegValue(_winreg.HKEY_LOCAL_MACHINE, 
            r"Software\Firaxis Games\Sid Meier's Civilization 4",
            "INSTALLDIR")
    civ4Dir = os.path.join(civ4Dir,"Beyond the Sword")
    return civ4Dir
 
Have multiple people confirmed that the existing version in the original post will work in BtS? If so I'll give it a try tonight when I get home.
 
Have multiple people confirmed that the existing version in the original post will work in BtS? If so I'll give it a try tonight when I get home.

Yes, but to get .ini config files to work properly you need to use the modifications Jeckel posted above.
 
Hmmm my registry key is different, in my case...

Code:
def _getInstallDir():
    civ4Dir = __getRegValue(_winreg.HKEY_LOCAL_MACHINE, 
            r"Software\Firaxis Games\Sid Meier's Civilization 4  - Beyond the Sword",
            "INSTALLDIR")
    civ4Dir = os.path.join(civ4Dir,"Beyond the Sword")
    return civ4Dir

Still does not work in my case though.... :(

OH I SEE he's concatinating beyond the sword onto the civ 4 directory...i got it i got it...
ok lets see if i can get that to work

WAIT NO.... im on to something here as my standard civ 4 key is Sid Meier's Civ 4 Gold
 
my standard civ 4 key is Sid Meier's Civ 4 Gold

You don't have a key for BtS as well? Something like

"Sid Meier's Civ 4 Gold - Beyond the Sword"

?

Note also that you have an extra space betwee the "4" and the "-" in the code you posted.
 
HKEY_LOCAL_MACHINE\SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword

No dice there either...
 
I found the problem! There is a bug in CvPath -- it is taking only the base directory name to find the INI file. In other words, it's looking in "CustomAssets" rather than "C:\Docs and Settings ... \CustomAssets". I've only tested for that so far, but here's the change:

Code:
def get_INI_File(szINIFileName):
    # BUG - EF: replaced "os.path.dirname(dir)" with "dir"
    filepaths = [os.path.join(dir, szINIFileName) 
        for dir in assetsPath]
    for filepath in filepaths:
        if os.path.isfile(filepath):
            return filepath
    return ""

See if that fixes it for you with your Gold version and running it as a mod. If not, I'll keep investigating.
 
Back
Top Bottom