Zebra 9
Emperor
Intro:
Lately I have been doing alot of small things with python, such as setting civics so they require religions and units that require a certain leader, that sort of thing. So I decided to make this Python Snippets Thread where anyone can come and find some realy cool, and realy simple, python code snippets.
Index:
First I will be doing several python snippets that work from the CvGameUtils.py file. From this file we can control the civics a player adopts, the units, buildings, and projects a city can build, a s well as allowing us to control the amount of money you get from capturing cities and pillaging.
Religious Civics<Back To Top>
The following snippet allows a player to adopt a civic only if they have the correct state religion. The code is as follows:
Now this code goes inside of the cannotDoCivic function, in an unMODed game this function looks like:
Place the snippet after eCivic = argsList[1] and before return False.
To set the required state religion place the religion's type tag after religion = , but remember the type tag must be inside of quote marks.
Next to set the civic that requires that religion, place the civic's type tag after civic = , again remember the type tag must be inside of quote marks.
If you follow those instructions you shouldn't have any problems.
Civic Specific Units<Back To Top>
The following snippet only allows a player to train a certain unit if they have adopted a certain civic:
Now this code goes inside of the cannotTrainUnit function, in an unMODed game this function looks like:
Place the snippet after bTestVisible = argsList[3] and before return False.
To set the required civic place the civic's type tag after civic = , but remember the type tag must be inside of quote marks.
Next to set the unit that requires that civic, place the unit's type tag after unit = , again remember the type tag must be inside of quote marks.
If you follow those instructions you shouldn't have any problems.
Civic Specific Buildings<Back To Top>
The following snippet only allows a player to construct a certain building if they have adopted a certain civic:
Now this code goes inside of the cannotConstruct function, in an unMODed game this function looks like:
Place the snippet after bIgnoreCost = argsList[4] and before return False.
To set the required civic place the civic's type tag after civic = , but remember the type tag must be inside of quote marks.
Next to set the building that requires that civic, place the building's type tag after building = , again remember the type tag must be inside of quote marks.
If you follow those instructions you shouldn't have any problems.
Leader Specific Units<Back To Top>
The following snippet only allows a player to train a certain unit if they have the correct leader:
Now this code goes inside of the cannotTrain function, in an unMODed game this function looks like:
Place the snippet after bTestVisible = argsList[3] and before return False.
To set the required leader place the leader's type tag after leader = , but remember the type tag must be inside of quote marks.
Next to set the unit that requires the leader, place the unit's type tag after unit = , again remember the type tag must be inside of quote marks.
If you follow those instructions you shouldn't have any problems.
Leader Specific Buildings<Back To Top>
The following snippet only allows a player to construct a certain building if they have the correct leader:
Now this code goes inside of the cannotConstruct function, in an unMODed game this function looks like:
Place the snippet after bIgnoreCost = argsList[4] and before return False.
To set the required leader place the leader's type tag after leader = , but remember the type tag must be inside of quote marks.
Next to set the building that requires the leader, place the building's type tag after building = , again remember the type tag must be inside of quote marks.
If you follow those instructions you shouldn't have any problems.
Lockable Civics<Back To Top>
The following snippet allows you to set a civic as locked. Once a player adopts a locked civic they are stuck with it (well at least until the UN):
Now this code goes inside of the cannotDoCivic function, in an unMODed game this function looks like:
Place the snippet after eCivic = argsList[1] and before return False.
To set the locked civic place the civic's type tag after civic = , but remember the type tag must be inside of quote marks.
If you follow those instructions you shouldn't have any problems.
City Max Unit Limit<Back To Top>
The following snippet allows you to set a certain amount of units that each city can support. For example if a civ has 5 cities and each city can support 3 units the civ can build only 15 units, but if they build a 6th city they can then build 18 units.:
Now this code goes inside of the cannotTrain function, in an unMODed game this function looks like:
Place the snippet after bTestVisible = argsList[1] and before return False.
To set the number of units supported by each city set numUnitsPerCity = to what ever you want.
If you follow those instructions you shouldn't have any problems.
Hope this helps alot of ya. I know I find these to be cool and useful.
<Back To Top>
Lately I have been doing alot of small things with python, such as setting civics so they require religions and units that require a certain leader, that sort of thing. So I decided to make this Python Snippets Thread where anyone can come and find some realy cool, and realy simple, python code snippets.
Index:
Religious Civics
Civic Specific Units
Civic Specific Buildings
Leader Specific Units
Leader Specific Buildings
Lockable Civics
City Max Unit Limit
Python Activated Always War/Peace (By Dale)
Civic Specific Units
Civic Specific Buildings
Leader Specific Units
Leader Specific Buildings
Lockable Civics
City Max Unit Limit
Python Activated Always War/Peace (By Dale)
Python Snippets For CvGameUtils.pyFirst I will be doing several python snippets that work from the CvGameUtils.py file. From this file we can control the civics a player adopts, the units, buildings, and projects a city can build, a s well as allowing us to control the amount of money you get from capturing cities and pillaging.
Note: If you are using these snippets you may have to make some changes to PythonCallbackDefines.xml. If you are not sure about how to make the change post your question here so I (or any other modder) can help get you on your way. I will be posting the tags that must be changed soon.
Religious Civics<Back To Top>
The following snippet allows a player to adopt a civic only if they have the correct state religion. The code is as follows:
Code:
religion = [U][I]Religion Type[/I][/U] ## The Religion
civic = [U][I]Civic Type[/I][/U] ## The Civic
## If The Civ Doesn't Have The Correct Religion Tell the SDK Not To Allow The Player To Chose This Civic
if eCivic == gc.getInfoTypeForString(civic):
if gc.getPlayer(ePlayer).getStateReligion() != gc.getInfoTypeForString(religion):
return True
Code:
def cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
return False
Code:
def cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
religion = [B]"[/B]RELIGION_JUDAISM[B]"[/B] ## The Religion
Code:
civic = [B]"[/B]CIVIC_HEREDITARY_RULE[B]"[/B] ## The Civic
Civic Specific Units<Back To Top>
The following snippet only allows a player to train a certain unit if they have adopted a certain civic:
Code:
civic = [U][I]Civic Type[/I][/U] ## The Civic
unit = [U][I]Unit Type[/I][/U] ## The Unit
## If The Civ Doesn't Have The Correct Civic Tell the SDK Not To Allow The Player To Train This Unit
if eUnit == gc.getInfoTypeForString(unit):
if not gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString(civic)):
return True
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
return False
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
civic = [B]"[/B]CIVIC_HEREDITARY_RULE[B]"[/B] ## The Civic
Code:
unit = [B]"[/B]UNIT_GUNSHIP[B]"[/B] ## The Unit
Civic Specific Buildings<Back To Top>
The following snippet only allows a player to construct a certain building if they have adopted a certain civic:
Code:
civic = [U][I]Civic Type[/I][/U] ## The Civic
building = [U][I]Building Type[/I][/U] ## The Building
## If The Civ Doesn't Have The Correct Civic Tell the SDK Not To Allow The Player To Costruct This Building
if eBuilding == gc.getInfoTypeForString(building):
if not gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString(civic)):
return True
Code:
def cannotConstruct(self,argsList):
pCity = argsList[0]
eBuilding = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
return False
Code:
def cannotConstruct(self,argsList):
pCity = argsList[0]
eBuilding = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
civic = [B]"[/B]CIVIC_HEREDITARY_RULE[B]"[/B] ## The Civic
Code:
building = [B]"[/B]BUILDIN_FORGE[B]"[/B] ## The Building
Leader Specific Units<Back To Top>
The following snippet only allows a player to train a certain unit if they have the correct leader:
Code:
leader = [U][I]Leader Type[/I][/U] ## The Leader
unit = [U][I]Unit Type[/I][/U] ## The Unit
## If The Civ Doesn't Have The Correct Leader Tell the SDK Not To Allow The Player To Construct This Building
if eUnit == gc.getInfoTypeForString(unit):
leaderType = gc.getLeaderHeadInfo(gc.getPlayer(pCity.getOwner()).getLeaderType()).getType()
if leaderType != gc.getInfoTypeForString(leader):
return True
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
return False
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
leader = [B]"[/B]LEADER_VICTORIAH[B]"[/B] ## The Leader
Code:
unit = [B]"[/B]UNIT_ENGLISH_READCOAT[B]"[/B] ## The Unit
Leader Specific Buildings<Back To Top>
The following snippet only allows a player to construct a certain building if they have the correct leader:
Code:
leader = [U][I]Leader Type[/I][/U] ## The Leader
building = [U][I]Building Type[/I][/U] ## The Building
## If The Civ Doesn't Have The Correct Leader Tell the SDK Not To Allow The Player To Construct This Building
if eBuilding == gc.getInfoTypeForString(building):
leaderType = gc.getLeaderHeadInfo(gc.getPlayer(pCity.getOwner()).getLeaderType()).getType()
if leaderType != gc.getInfoTypeForString(leader):
return True
Code:
def cannotConstruct(self,argsList):
pCity = argsList[0]
eBuilding = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
return False
Code:
def cannotConstruct(self,argsList):
pCity = argsList[0]
eBuilding = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
leader = [B]"[/B]LEADER_VICTORIAH[B]"[/B] ## The Leader
Code:
building = [B]"[/B]BUILDIN_FORGE[B]"[/B] ## The Building
Lockable Civics<Back To Top>
The following snippet allows you to set a civic as locked. Once a player adopts a locked civic they are stuck with it (well at least until the UN):
Code:
civic = [U][I]Leader Type[/I][/U] ## The Civic
pPlayer = gc.getPlayer(ePlayer)
civicType = gc.getCivicInfo(eCivic).getType()
civicOptType = gc.getCivicInfo(eCivic).getCivicOptionType()
testCivic = gc.getCivicInfo(pPlayer.getCivics(civicOptType)).getType()
if testCivic == civic and testCivic != civicType:
return True
Code:
def cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
return False
Code:
def cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
civic = [B]"[/B]CIVIC_HEREDITARY_RULE[B]"[/B] ## The Civic
City Max Unit Limit<Back To Top>
The following snippet allows you to set a certain amount of units that each city can support. For example if a civ has 5 cities and each city can support 3 units the civ can build only 15 units, but if they build a 6th city they can then build 18 units.:
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
pPlayer = gc.getPlayer(pCity.getOwner())
numUnitsPerCity = [U][I]Num Units Supported by one City[/I][/U] ## The Number Of Units A City Supports
maxUnits = pPlayer.getNumCities() * numUnitsPerCity
if pPlayer.getNumUnits() >= maxUnits:
return True
return False
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
return False
Code:
def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
[B]## Place Snippet Below Here[/B]
[B]## But Above Here[/B]
return False
Code:
numUnitsPerCity = [B]5[/B] ## The Number Of Units A City
Hope this helps alot of ya. I know I find these to be cool and useful.
<Back To Top>