Unit Names

SK138

Warlord
Joined
Dec 16, 2002
Messages
230
Location
Hilliard, OH
This was an idea WaxonWaxov had and I am trying to do it but I need some help. What I want to do is mounted units when produced will be renamed to 1st Calvary or 2nd Calvary... Defenders will be 1st Militia possibly, and there will be Artillery and stuff like that. I am going by TheLopez's random names mod to basically get set up but after that I am lost. I need a way to find out what unit was produced so I know what to assign it as and I need to figure out a way to count up and possibly go back say if the 3rd Calvary died, a new one could be made. Also, when I count up, I need to make sure I get 33rd or 32nd not 33th or 32th. Any ideas on how to accomplish this?
 
Hmmm - if you have no experience with python this is going to be a tricky one for you to do. There are several things involving storing of data and suchlike to overcome. If you like I can quickly bash together something that would work. I'll try to put as much flexablilty into it is possible.
 
TGA, I'm already planning to do something like this :p, Unit titles mod. It will just take a bit since I have about 8-9 mod comps to either fix, implement, etc. a head of it.
 
This is really pretty easy to do, if someone wanted to do it before TheLopez gets around to it. A simple counter (or sweep, even) of the player's units when a unit gets created (checking the scriptdata of the player for the counter, or of each unit's scriptdata--Why parse the name?--if you want to reuse lost unit's names). Then use the renaming algorithm from the rename dialog apply function (I think it's just.. setName), combined with a little test against the unit's combat type using getUnitCombatType() and gc.getInfoTypeFor("UNITCOMBAT_MOUNTED") etc.. And there you go.

This is a great first project for someone getting into the Python side of modding.
 
I agree, Belizan, and if someone does it before me, then good.
Otherwise, I'll do it when I have some free time. :)
 
What does getUnitCombatType() and gc.getInfoTypeFor("UNITCOMBAT_MOUNTED") return? Also, when I make an array like array = ["1st", "2nd", "3rd"] will array[1] = 1st?
 
array = ["1st", "2nd", "3rd"] makes a list. Its not called an array but pretty much the same thing.

The indexing starts at 0 so array[0]="1st".
 
How can I get the "getUnitCombatType()" command to return the value of the newly built unit? I think I might need to have something in the (). My main problem I am having right now is that I can't figure out how to use python to figure out what the newly created unit is?

I have "if(gc.getUnitCombatType() == 3):" and 3 stands for melee units but getUnitCombatType needs a string in the () but how do I get python to get that string?
 
Step 1, learn a little about Python before trying to do any of this. Try going through the first... 5 or 6 (or all 11 if you are a total programming newbie) of the Python Tutorials in the sticky thread here. Alternatively you could try this one, but I haven't looked at it, myself.

Then, take a second to glance over the modder tutorial forums and learn the proper way to make a mod folder.

Then, take a look at the Python API here. You don't have to read it all by any stretch, but you'll want to look at CyUnit (which is a unit object).

Then, go into you Civ4 Assets\Python folder and copy CvEventManager.py to somewhere else and take a look at the events it lets you capture. There is a description of them in brief here.

Then, take a look at the mods the game comes with. In particularly, when I was starting out, I looked at GreekWorld alot. Try to understand what it is doing and how it is doing it. Use the Python API page as a reference. If you like, you can download some other people's mods, smaller are better to start out with, and take a look at what they've done. It's a great way to learn.

Get a grep tool.

Get a diff tool.

By this point you should be ready to enter the wonderful world of Python modding in Civ4, with near limitless capabilities. Also, at this point, our pointers above will be readily meaningful to you.

Finally there is a kitchen sink overview here. All of these have been posted about in the tutorials section. You should take a look, the information you want is already there.
 
I have done all of that and I am using TheLopez random names mod as a reference to get mine set up. I understand most of the commands I need to do, I just can't figure out how I can get a value from "gc.getUnitCombatType()" to return the integer of the combat type. I already have the event stuff set up so the mod starts working when a new unit is built. I can even get it to rename a unit to the name I want, but now I just need to do the check to see what the unit is.
 
Back
Top Bottom