Need help making mod civ's trait that is based on ideology

Deeakron

Chieftain
Joined
Jul 9, 2015
Messages
20
I'm trying to make a mod that adds a civ that has a trait that gives happiness for having the Freedom Ideology, and unhappiness for the other ideologies. Since I'm new to modding for Civ V, I don't know where to start. I asked on the Steam forums and someone suggested I use lua to detect the ideology and have it give a policy or building based on that. But, since I'm new to modding, as I said, I'm not sure how to do that. Can someone please help?
 
That was probably me.

I don't really have much time tonight to respond in any detail, so unless someone else from here makes a more substantial response before then I'll try to make one sometime tomorrow morning or early afternoon my time (USA Midwest time-zone).
 
A few prepratory questions 1st since I don't know how far along you are in learning how to mod or in trying to create your new civilization. I need you to look through the following and "fill-in" the survey so I have a better idea of where I need to start:
  1. Have you downloaded from Steam the SDK package for Civ5?
  2. If so, have you created a mod that has your new civilization defined, but you are just not sure about how to create the Happiness/Unhappiness effects for the UA part of it?
    • Because lua is a mystery, or
    • You don't know how to impliment a completed lua program in ModBuddy so your mod can use it
    • Both 'a' and 'b' are true
  3. Have you ever tried editing the code of someone else's mod that you have downloaded or subscribed to?
    • If so, where you successful at making small edits to someone else's mod?
  4. Are you completely new and really have no idea where to start because you have not ever created a mod before?

Note that if you have no real mod-creating experience, that's fine -- I will just walk you through making a simple mod or two 1st before returning to what you are really after, because it is necessary to walk before running, and to run before trying to compete in the long jump.

If you already have a partially-completed mod for your civilization, you can attach the built version of it to a post. This will give me an even better idea of where you are in terms of creating mods for Civ5. whoward69's zip your mods and attach tutorial Even if your mod is currently not working, creating wierd errors when you try to run it, etc., post the version (as whoward directs you to in that tutorial) that is in the My Games/Sid Meier's Civilization 5/MODS/ folder.
 
1. Yes.
2. I can do everything but the lua part because I don't really know how to code with lua.
3. I tried finding something, but of all the mods I have, none really have something based on ideology.
4. I'm new to lua coding, but I have done modding before.

I'm going to be busy for the next week, so I won't be able to see your response until afterwards. Thanks for helping!
 
OK, I'll put something together in the next two or three days for the code you would need, and the steps necessary to properly activate it in ModBuddy.

One more question: are you looking to create a specific amount of Happiness / Unhappiness, or are you looking to create a percentage adjustment to existing Happiness / Unhappiness in a manner similar to the way Forbidden Palace works ?
 
  1. Download the mod that is attached to this thread. It has the two needed files in it. I have tested and it works.
  2. Copy the two files in the attached mod into your mod for your civilization. Do this from inside ModBuddy using the Modbuddy File "Add > Existing File".
    • It does not really matter where in terms of folder-structure you place these two files within your mod, but I generally like to create a folder I call "LUA" within my mods, and I place all my lua stuff in there.
  3. The file called IdeologyPolicy.xml should be set-up within modbuddy as an "OnMOdActivated > UpDateDatabase" action under the mod's "Properties > Actions" tab.
  4. The file called PlayerAdoptPolicy.lua should be set-up within modbuddy as an "InGameUIAddin" under the mod's "Properties > Content" tab.
  5. The following is stuff about the code within the two files.
  6. I arbitrarily chose 10% as the percentage for extra happiness/unhappiness from choosing Freedom or for not choosing Freedom. To change this value to some other percentage you would change the two values of "10" and "-10" in the xml file IdeologyPolicy.xml where shown in the blue here:
    Code:
    <GameData>
    	<Policies>
    		<Row>
    			<Type>POLICY_NOTFREEDOM_EXTRA_UNHAPPYMOD</Type>
    			<Description>TXT_KEY_POLICY_NOTFREEDOM_EXTRA_UNHAPPYMOD</Description>
    			<PortraitIndex>24</PortraitIndex>
    			<IconAtlas>POLICY_ATLAS</IconAtlas>
    			<IconAtlasAchieved>POLICY_A_ATLAS</IconAtlasAchieved>
    			<UnhappinessMod>[color="blue"]10[/color]</UnhappinessMod>
    		</Row>
    		<Row>
    			<Type>POLICY_FREEDOM_EXTRA_HAPPYMOD</Type>
    			<Description>TXT_KEY_POLICY_FREEDOM_EXTRA_HAPPYMOD</Description>
    			<PortraitIndex>24</PortraitIndex>
    			<IconAtlas>POLICY_ATLAS</IconAtlas>
    			<IconAtlasAchieved>POLICY_A_ATLAS</IconAtlasAchieved>
    			<UnhappinessMod>-[color="blue"]10[/color]</UnhappinessMod>
    		</Row>
    	</Policies>
    	<Language_en_US>
    		<Replace Tag="TXT_KEY_POLICY_FREEDOM_EXTRA_HAPPYMOD" Text="Freedom Extra Happy Percent" />
    		<Replace Tag="TXT_KEY_POLICY_NOTFREEDOM_EXTRA_UNHAPPYMOD" Text="Not Freedom Extra UnHappy Percent" />
    	</Language_en_US>
    </GameData>
    Do not remove the "-" sign from the second policy. This is how choosing freedom makes more percentage Happiness in the empire, it actually reduces the amount of unhappiness, thereby giving a net effect of more happiness.
  7. I chose to test this using Rome as a test-case, so you will need to change one line of the code within PlayerAdoptPolicy.lua to change it to the name of the Civilization you are adding to the game. So, where highlighted in blue here, change CIVILIZATION_ROME to the correct name for your civilization.
    Code:
    iRequiredCiv = GameInfoTypes.[color="blue"]CIVILIZATION_ROME[/color]
    iIndustrialEra = GameInfoTypes.ERA_INDUSTRIAL
    iFreedomIdeology =  GameInfoTypes.POLICY_BRANCH_FREEDOM
    iHappinessPolicyForFreedom = GameInfoTypes.POLICY_FREEDOM_EXTRA_HAPPYMOD
    iUnhappinessPolicyForOther = GameInfoTypes.POLICY_NOTFREEDOM_EXTRA_UNHAPPYMOD
    
    
    function PlayerFreedomIdeologyChoice(iPlayer, iPolicyID)
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetNumFreePolicies() > 0 then
    		--print("player has outstanding free policies to select, exiting the AdoptPolicyListener function to avoid conflicts")
    		return
    	end
    	if pPlayer:GetCivilizationType() == iRequiredCiv and pPlayer:GetCurrentEra() >= iIndustrialEra then
    		if pPlayer:GetLateGamePolicyTree() ~= -1 then
    			print("pPlayer:GetLateGamePolicyTree() returns " .. tostring(pPlayer:GetLateGamePolicyTree()))
    			if pPlayer:GetLateGamePolicyTree() == iFreedomIdeology then
    				print("player has chosen Freedom as their Ideology")
    				if pPlayer:HasPolicy(iUnhappinessPolicyForOther) then
    					pPlayer:SetHasPolicy(iUnhappinessPolicyForOther, false)
    					pPlayer:SetHasPolicy(iHappinessPolicyForFreedom, true)
    				else
    					if not pPlayer:HasPolicy(iHappinessPolicyForFreedom) then
    						pPlayer:SetNumFreePolicies(1)
    						pPlayer:SetNumFreePolicies(0)
    						pPlayer:SetHasPolicy(iHappinessPolicyForFreedom, true)
    					end
    				end
    			else
    				print("player has NOT chosen Freedom as their Ideology")
    				if pPlayer:HasPolicy(iHappinessPolicyForFreedom) then
    					pPlayer:SetHasPolicy(iHappinessPolicyForFreedom, false)
    					pPlayer:SetHasPolicy(iUnhappinessPolicyForOther, true)
    				else
    					if not pPlayer:HasPolicy(iUnhappinessPolicyForOther) then
    						pPlayer:SetNumFreePolicies(1)
    						pPlayer:SetNumFreePolicies(0)
    						pPlayer:SetHasPolicy(iUnhappinessPolicyForOther, true)
    					end
    				end
    			end
    		else
    			print("pPlayer:GetLateGamePolicyTree() returns " .. tostring(pPlayer:GetLateGamePolicyTree()))
    			print("player has not yet adopted an Ideology")
    		end
    	end
    end
    GameEvents.PlayerAdoptPolicy.Add(PlayerFreedomIdeologyChoice)
    
    print("The PlayerFreedomIdeologyChoice PlayerAdoptPolicy loaded")
  8. Note that you can also unzip the attached mod, place it into your MODS folder, enable it, and experiment with the percentages, etc., using Rome as your test-civ in order to get a better feel for whether you want more or less percentage-value of happiness. Then simply apply whatever those changes in the percentage values were to the copy of the files you add to your civilization's mod. This way you do not have to have the "whole enchilada" of your new civilization working completely to test this one element of it to arrive at a "most-reasonable" number to use for the percentage happiness effects.
 

Attachments

Back
Top Bottom