Python Console Mod Tools

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296

This is a simple python utility; it is a modcomp you can easily add to your mod that will give you access to a few very useful functions, especially for modders who do alot of work with unit art. To install simply extract, and put the ModTools folder into your mod's python folder. This modcomp will not conflict with other mods, it is entirely self contained.

How to use:

Setting up debugging mod: Skip this if you've already done so (most modders have, if you haven't there is other stuff you should do in the config file, such as enable python exceptions and logging):

Spoiler :
First you must have deguggin enabled to access the console. To do this locate your main BtS config file, it'll be found in ...$MyDocuments/$MyGames/$BtS and is called CivilizationIV.ini. As an example on my computer it is here: C:\Documents and Settings\P\My Documents\My Games\Beyond the Sword

Now open it up with notepad or other simple text editor, and search for cheatcode. Change the line
Code:
; Move along
CheatCode = 0
to
Code:
; Move along
CheatCode = chipotle

Now that you have the cheatcode enabled many debugging tools become available; including access to the console, and python console (this does not work in multiplayer). Another very useful debugging tool is exposing the map. Press ctrl + z to expose the map.



Once you have put the ModTools folder into your mod's python directory, and once debugging is enabled, you may start up civ4 and load up your mod to access the ModTools python functions. In game press SHIFT and ~. Don't just hit the ` button, you must hit shift (otherwise you just get the console, you must open up the python console). The python console should pop up, and you should see something like this:

Spoiler :

Notice the word python in the bottom left of the console. If that's not there you didn't press shift. If the console doesn't pop up at all, you have either not enabled the cheatcode in civ4's main config file, which grants access to the debugging tools, or you hit the wrong button (it's the ` or ~ button depending on how you look at it).

The ModTools files (ModTools.py and ModToolsUtils.py; both of which are in the ModTools folder) are not automatically imported into the Python Console's member functions. To gain access to them you need to tell the console to import the python file; to do so Type:
Code:
import ModTools

hit enter and mod tools will be loaded:
Spoiler :


Once the ModTools have been loaded, these are the functions you have access to, you must also include ModTools. at the beggining of the function, so that the Python Console knows you are accessing a member function of ModTools.

ModTools.clearMap()
the clear map function clears all units from the map. It is also executed automatically whenever the showUnits and showUnitsTerrain functions are run
Spoiler :


ModTools.showUnits()
Shows All units of all civs currently in the game. Ported from Avain's ShowMeAllDaUnitz modcomp. If the function runs out of space to add more units, it will tell you. Be aware this function may take some time to run if it is a large map with lots of civs. It took over half an hour for civ to finish running this function on a huge map with 50 civs on my computer; though my computer is old (got it in 2002), so it shouldn't take that long for most folks.
Spoiler :



ModTools.showUnitClass("UNITCLASS_TYPE")
Spawns the specified unitclass for all civs in the game for you to compare. It is important to notice that the specified unitclass inside the brackets is inside quotation "" marks. This is to identify this as a string for the function, if you don't use brackets it wol't work. Also as you add more unitclasses to compare the units will be placed above the old ones, so you may compare specific unitclasses side by side.
Spoiler :



ModTools.showUnitsTerrain("TERRAIN_TYPE")
Similar to showUnits, but allows you to specify the background terrain, instead of always being Ocean, as is the default terrain in show units. Again you must use quotes around the terrain type you specify. Also like showUnits() this function may take a while to finish running.
Spoiler :


ModTools.advanceEra()
Advances the era for all civs in the game (advances to 1 era above the most advanced civ):
Spoiler :



Once again all credit due to Avain for creating the ShowMeAllDaUnitz modcomp in the first place. I just didn't want to tack it into CvEventManager and tie it into unit naming. Making it a console command allows for moders to keep this completely separate and just gives them more tools to work with without causing conflicts or complicating things. Also I wanted to add the functions to compare a specific unitclass, and to advance the era, as the era is very important for art as well and further the code needed to be changed somewhat to handle more operations and generally be more robust.

A big thanks to EmperorFool as well for describing how to use the Python Console. I intend to port this over to RevDCM by default and have it load up automatically without the need to import the module, but for those wanting the functions now or do not want to use RevDCM, here they are. Also I may just port over these functions to RevDCM as is anyway.

If you have any ideas for other conceptually simple but useful functions feel free to make a request. If the request is doable and it makes sense I will most likely add it. Hope some moders find it useful. And feedback is always good.

Download here:
Python Console Mod Tools download
 
I fixed up the code, so now it displays multiple rows and wol't overlap. If you have too many civs for the map size the function will run till there is a civ who's units would be populated off the map, and then the function will abort and let you know there are too many units to fit.

Also added new logic to the show unit class function, so that you can now compare multiple unit classes. Ie if you tell it to show a specified unitclass, then ask it to show another, it'll spawn the next set of units above the last ones, so that you can see how they look side by side.

I also added two new functions:
clearMap()
-Does what it says, clears the map. This is automatically run when showUnits is run as well. A city is spawned for every player moving right from the origin so that there isn't a "You have been defeated" issue.

showUnitsTerrain("TERRAIN_TYPE")
-Allows you to set the background type of terrain. The default showUnits() function automatically uses ocean, this lets you change it. Normally I'd have overloaded the function, but python doesn't allow that, so I had to designate an entire new one.


Also because clearMap() is executed at the start of the show units code I had to add a second file ModToolsUtils.py for this function to be pulled from to be executed. For some reason python doesn't let you call functions from the same file, they must be imported from outside. Well you can, but you have to declare the function as an argument, and that would be too convoluted, just made more sense to add a Utils file, plus I may add more functions to this someday, and having a utils file just makes sense. The directions don't change much, just put the ModTools folder (which contains ModTools.py and ModToolsUtils.py) in your mod's python folder, and you'll be good to go.
 
Top Bottom