Advertisement
Civilization Fanatics' Center  

Welcome to Civilization Fanatics' Center.

You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support.

Go Back   Civilization Fanatics' Forums > CIVILIZATION V > Civ5 - Creation & Customization > Civ5 - SDK / LUA

Notices

Reply
 
Thread Tools
Old Aug 19, 2012, 01:35 AM   #1
Craig_Sutter
Emperor
 
Join Date: Aug 2002
Location: Seoul, South Korea
Posts: 1,277
[LUA] Working as intended?

In my mod, several civilizations start with no cities.

When playtesting, I found that they were puppeting their newly acquired capital cities and well as others.

I have added a courthouse effect to the palace, and so, I don't want the capitals to be puppets.

I used the following code to do so:

Code:
function UnPuppetTurnStart ()
	for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
		local player=Players [iPlayer];
		if (player:IsAlive () and not player:IsHuman()) then
		local pCity = player:GetCapitalCity()
			for pCity in player:Cities () do
				if (pCity:IsPuppet ()) then
					pCity:SetPuppet (false);
				end
			end
		end
	end
end

Events.ActivePlayerTurnStart.Add (UnPuppetTurnStart);
It works in that the capital cities are no longer puppets; however, I suspect that the code is actually doing more and forcing all AI cities that are conquered to be annexed. I not certain this is the case, but it seems to be so as I no longer see puppets in my testing.

Could someone who is familiar with lua look at my code and verify if it is acting as I wish? Or have some unintentional results occured?
__________________
Visit my Viking Age scenario at:
http://forums.civfanatics.com/showthread.php?t=228787
And my Europe map for European Medieval Mod at:
http://forums.civfanatics.com/showthread.php?t=229384
Craig_Sutter is offline   Reply With Quote
Old Aug 19, 2012, 09:44 AM   #2
Gedemon
Moderator
 
Gedemon's Avatar
 
Join Date: Oct 2004
Location: France
Posts: 3,668
the "for pCity in player:Cities () do..." is not needed, if you do that, you'll loop all the player cities at each turn.
Gedemon is online now   Reply With Quote
Old Aug 19, 2012, 04:44 PM   #3
Craig_Sutter
Emperor
 
Join Date: Aug 2002
Location: Seoul, South Korea
Posts: 1,277
I got rid of the city loop, but then I run into the problem that pCity becomes a "nil" value, and I get an error. I was not skilled enough to fix it though I tried a number of solutions.

In any case, I've found an alternative solution that works (although it is somewhat clunky):

Code:
function UnPuppetYork()

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

	local pNorthumbria = Players[iPlayer]

	if (GameInfo.Civilizations.CIVILIZATION_RUSSIA.ID == pNorthumbria:GetCivilizationType()) then
		if(pNorthumbria:IsAlive() and not pNorthumbria:IsHuman()) then 
			
			-- Enumerate cities
			
			for cityIndex = 0, pNorthumbria:GetNumCities() - 1, 1 do
    			local pCity = pNorthumbria:GetCityByID(cityIndex)

				-- City exists and has the proper name?

    			if pCity ~= nil and pCity:GetName() == "York" then
				pCity:SetPuppet (false);
				end
			end
		end
	end
end
end
									
Events.ActivePlayerTurnStart.Add (UnPuppetYork);
It is not very flexible in its application as it is specific to a particular city, but as it is for a scenario, it is good enough.

(although I would still like to get the previous code working properly, as it would be a more elegant solution).
__________________
Visit my Viking Age scenario at:
http://forums.civfanatics.com/showthread.php?t=228787
And my Europe map for European Medieval Mod at:
http://forums.civfanatics.com/showthread.php?t=229384
Craig_Sutter is offline   Reply With Quote
Old Aug 19, 2012, 06:08 PM   #4
Gedemon
Moderator
 
Gedemon's Avatar
 
Join Date: Oct 2004
Location: France
Posts: 3,668
try:

Code:
function UnPuppetTurnStart ()
	for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
		local player=Players [iPlayer];
		if (player:IsAlive () and not player:IsHuman()) then
			local pCity = player:GetCapitalCity()
			if pCity and pCity:IsPuppet () then
				pCity:SetPuppet (false);
			end
		end
	end
end

Events.ActivePlayerTurnStart.Add (UnPuppetTurnStart);
Lua check "and" starting with the left element, if it's nil it won't try the right element...
Gedemon is online now   Reply With Quote
Old Aug 20, 2012, 07:47 AM   #5
Craig_Sutter
Emperor
 
Join Date: Aug 2002
Location: Seoul, South Korea
Posts: 1,277
Thank-you... that worked perfectly.
__________________
Visit my Viking Age scenario at:
http://forums.civfanatics.com/showthread.php?t=228787
And my Europe map for European Medieval Mod at:
http://forums.civfanatics.com/showthread.php?t=229384
Craig_Sutter is offline   Reply With Quote
Reply

Bookmarks

Go Back Civilization Fanatics' Forums > CIVILIZATION V > Civ5 - Creation & Customization > Civ5 - SDK / LUA > [LUA] Working as intended?

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Advertisement

All times are GMT -6. The time now is 03:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
This site is copyright © Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR