zulu9812
The Newbie Nightmare
Cheers for that. It seems to be working now. What was the problem in the end?
I tried to use this code, but I can't find unit name, how can I know if my unit with name?Porges said:Here's one that works with SimCutie's event manager:
Code:#import utility functions from CvPythonExtensions import * import pickle def getCityNumber(city): cityDict = pickle.loads( city.getScriptData() ) cityDict['unitNumber'] = cityDict['unitNumber'] + 1 city.setScriptData( pickle.dumps(cityDict) ) return cityDict['unitNumber'] def onUnitBuilt(argsList): city = argsList[0] unit = argsList[1] unit.setName(findOrdinal(getCityNumber(city)) + " " + unit.getName() + " of " + city.getName()) return 0 def onCityBuilt(argsList): city = argsList[0] cityDict = {'unitNumber':0} city.setScriptData( pickle.dumps(cityDict) ) return 0 def findOrdinal(num): t = 'th st nd rd th th th th th th'.split() if num % 100 in (11, 12, 13): #special case return '%dth' % num return str(num) + t[num % 10] def EventHandlerRegister(eventManager,unused = None): return {'unitBuilt-':onUnitBuilt,'cityBuilt-':onCityBuilt}
Sets the names like "1st Worker of Moscow", "2nd Warrior of Moscow". The number is dependant upon all units built in the city.
def onUnitBuilt(argsList):
city = argsList[0]
unit = argsList[1]
#unit.setName(findOrdinal(getCityNumber(city)) + " " + unit.getName() + " of " + city.getName())
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
#unit.setName(RandomNameUtils.getRandomName())
return 0
Without sounding rude... why? IMO SimCutie's is better - it does a similar job, and is alot more pluggable. The only reason against using it may be because it isn't as mainstream as Doc Jiggle's. I personally work with SCs, as I find it easier to use.TheLopez said:Mike, why are you using simcutie's event manager with this mod? You should use Dr. Elmer Jiggle's event manager.
def onUnitCreated(self, argsList):
'Unit Completed'
unit = argsList[0]
cityname = PyPlayer(unit.getOwner()).getCivilizationShortDescription()
zsName = getUnitNameWithCity(cityname, unit)
unit.setName(zsName)
def onUnitBuilt(self, argsList):
'Unit Completed'
city = argsList[0]
unit = argsList[1]
cityname = city.getName()
if (len(unit.getNameNoDesc()) > 0):
cityunitS = PyPlayer(unit.getOwner()).getCivilizationShortDescription() + PyInfo.UnitInfo(unit.getUnitType()).getDescription()
unitCount = sdGetVal(zsModName, cityunitS, "Cnt")
unitCount = unitCount - 1
sdSetVal(zsModName, cityunitS, "Cnt", unitCount)
zsName = getUnitNameWithCity(cityname, unit)
unit.setName(zsName)
CvAdvisorUtils.unitBuiltFeats(city, unit)
def onUnitCreated(self, argsList):
'Unit Completed'
unit = argsList[0]
if (len(unit.getNameNoDesc()) > 0):
return
prefix = PyPlayer(unit.getOwner()).getCivilizationShortDescription()
zsName = getUnitNameWithCity(prefix, unit)
unit.setName(zsName)
TheLopez said:Random Unit Names Mod
By: TheLopez
Last Updated 06/09/06
Version: v0.5.2
Patch Compatibility: v1.52, 1.61
MP Compatible: ?
Download Mod v0.5.2
Description:
This mod will give any unit created in the game a unique name. The current
version of this mod can generate over well to many names to count. There are
two ways to use this mod. The first is to just call the getRandomName method
which will return just that, a random name. The second and new way to use this
mod is to use the getRandomCivilizationName passing in the civilization type ID
number. This mod should NOT be used as a stand-alone mod. You should just use
the RandomNameUtils.py file instead. The other files are just used to show
how the RandomNameUtils.py can be used.
Installation Instructions:
1) Unzip this into the "civ4_install_folder\Mods\" folder.
2) Open the CivilizationIV.ini configuration file
3) Change the Mod line to read: Mod = Mods\Random Unit Names
4) Load the game.
5) Then play as normal.
-----Version Information-----
-----v0.5.x------
- Tweaked the Japan names so they don't always produce really long names
- Added random name generation support for all of the original civilizations
included in the original game. If someone wants to add other names they will
have to do it themselves.
Spoiler :
-----v0.4------
- Forked off the mercenaries mod random name generation code
- Stripped the mercenary specific code from the mod
-----===Credits & Thanks===-----
- Exavier
Composite Mod - readme.txt format
If someone wants to add other names they will have to do it themselves.
Personally, I would like a mod that numbers units by type,
For example, the first archer you build would be named "1st Militia"
Militia would be city defense units.
Infantry would be walking attack units (Swordsman, etc)
Cavalry would be mounted units.
etc etc.
So the idea is early in the game you create a Horse Archer which gets named "5th Cavalry"
Eventually, that unit could upgrade into a gunship, but would have the historical name "5th Cavalry"
Just like the Scottish Black Watch used to use muskets, now they use Armoured Personnel Carriers.
Hey Lopez, give me insight as to how you did this one and maybe I'll do my idea myself.
Hmmm..... well that is a very interesting idea. When I put out the random unit names mod I just ripped out the code from my Merc. Mod and made it available since someone had requested it. I am planning to extend it by making the random names a bit more specific depending on the civilization for the unit. Though I could introduce an option to do the type of naming that you are asking for as well. Let me mull this over and I'll see what I can do after I release my Merc. mod.
Well, you can download the mod and see for yourself how I did it.
This discussion was last winter. Did anyone make progress on it?
I try to do something similar manually when I play, but bog down when I have to mobilize for a big war.
![]()