UltraRobPrime
Chieftain
- Joined
- Nov 24, 2012
- Messages
- 57
My game crashes whenever the game configures the game data after I hit the next button in the mod menu. How do I fix this? I have never had any problems with this mod until now.
For example I wanted it to be like it was kind of IRL
Just wanted to thank you for this response, I was wanting to alter the traits for some civ's so this is great!Find the mod's folder, and find a file called SetLeaderTraitPolicy.lua. It can be opened with a text editor like notepad.
For each civilization, you should see a block of code that looks something like this (In this case, it's the code for America):
Code:function SetLeaderTraitAmerica (playerID) local player = Players[playerID] if player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_AMERICA then if not player:HasPolicy(GameInfoTypes["POLICY_EXPANSIVE_X"]) then player:SetNumFreePolicies(1) player:SetNumFreePolicies(0) player:SetHasPolicy(GameInfoTypes["POLICY_EXPANSIVE_X"], true) if player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_AMERICA then if not player:HasPolicy(GameInfoTypes["POLICY_CHARISMATIC_X"]) then player:SetNumFreePolicies(1) player:SetNumFreePolicies(0) player:SetHasPolicy(GameInfoTypes["POLICY_CHARISMATIC_X"], true) end end end end end GameEvents.PlayerDoTurn.Add(SetLeaderTraitAmerica);
It is, ultimately, these lines:
...that define America's traits.Code:... player:SetHasPolicy(GameInfoTypes["POLICY_EXPANSIVE_X"], true) ... player:SetHasPolicy(GameInfoTypes["POLICY_CHARISMATIC_X"], true) ...
Where you see POLICY_SOMETHING_X, you'll need to replace that with the exact name of the replacement trait you want, which can be found in the Traits.xml file. e.g. Charismatic would correspond to POLICY_CHARISMATIC_X.
You must type the trait name in with exactness, in all caps and not forgetting the _X at the end, or it will not work.
Repeat for all other civilizations that you want to change the traits of. Save, and done.
local num_traits = 2 -- the amount of traits every leader should get
local traits = {"POLICY_AGGRESSIVE_X", "POLICY_CHARISMATIC_X", "POLICY_CREATIVE_X", "POLICY_DIPLOMATIC_X",
"POLICY_EXPANSIVE_X", "POLICY_FINANCIAL_X", "POLICY_IMPERIALISTIC_X", "POLICY_INDUSTRIOUS_X",
"POLICY_INVENTIVE_X", "POLICY_MERCANTILE_X", "POLICY_PHILOSOPHICAL_X", "POLICY_PROTECTIVE_X",
"POLICY_SEAFARING_X", "POLICY_SPIRITUAL_X"}
local trait_icons = {["POLICY_AGGRESSIVE_X"]="[ICON_WAR]", ["POLICY_CHARISMATIC_X"]="[ICON_HAPPINESS_1]", ["POLICY_CREATIVE_X"]="[ICON_CULTURE]", ["POLICY_DIPLOMATIC_X"]="[ICON_INFLUENCE]",
["POLICY_EXPANSIVE_X"]="[ICON_FOOD]", ["POLICY_FINANCIAL_X"]="[ICON_TRADE]", ["POLICY_IMPERIALISTIC_X"]="[ICON_CITY_STATE]", ["POLICY_INDUSTRIOUS_X"]="[ICON_PRODUCTION]",
["POLICY_INVENTIVE_X"]="[ICON_RESEARCH]", ["POLICY_MERCANTILE_X"]="[ICON_GOLD]", ["POLICY_PHILOSOPHICAL_X"]="[ICON_GREAT_PEOPLE]", ["POLICY_PROTECTIVE_X"]="[ICON_STRENGTH]",
["POLICY_SEAFARING_X"]="[ICON_GREAT_EXPLORER]", ["POLICY_SPIRITUAL_X"]="[ICON_PEACE]"}
function Distribute_Random_Traits()
print("Distribute_Random_Traits")
local done = false
for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
local pPlayer = Players[iPlayer]
if pPlayer.GrantPolicy==nil then
print("ERROR CivIV Traits Mod: You are missing a mod dll with the dummy policy fix from whoward?! No GrantPolicy function")
else
if pPlayer~=nil and pPlayer:IsEverAlive() then
local traitsassigned = 0
local failsafe = 0
while traitsassigned<num_traits and failsafe<num_traits*25 do -- 50 tries should be enough
failsafe = failsafe + 1
local randchoice = Game.Rand(#traits,"RandomCivIV_Trait") + 1
local pTrait = GameInfo.Policies[traits[randchoice]]
local assigned = false
if pTrait~=nil then
assigned = pPlayer:GrantPolicy(pTrait.ID, true)
if assigned then
traitsassigned = traitsassigned + 1
done = true -- traits were assigned to at least one player, so we consider this a success I guess
end
end
print("giving " .. pPlayer:GetName() .. " " .. traits[randchoice] .. ", success:"..tostring(assigned))
end
end
end
end
return done
end
-- reflect the assigned traits in leader names
function UpdateLeaderNames() -- of course this will display wrong icons, if we have the same leader more than once! but I guess tere is no solution for it, so simply dont play with the same leader twice
print("UpdateLeaderNames")
local localelanguage = "Language_" ..Locale.GetCurrentLanguage().Type;
local You = Locale.ConvertTextKey("TXT_KEY_YOU")
local tquery = {}
local iActivePlayer = Game.GetActivePlayer()
for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
local pPlayer = Players[iPlayer]
if pPlayer~=nil and pPlayer:IsEverAlive() then
local icons = ""
for traitpolicy, icon in pairs(trait_icons) do
local pPoliciy = GameInfo.Policies[traitpolicy]
if pPoliciy~=nil and pPlayer:HasPolicy(pPoliciy.ID) then
icons = icons .. icon
end
end
if icons~="" then
local leaderinfo = GameInfo.Leaders[pPlayer:GetLeaderType()]
local leadertype = leaderinfo.Type
local leadername = Locale.ConvertTextKey(leaderinfo.Description)
table.insert(tquery,"UPDATE "..localelanguage.." SET Text = '".. leadername..icons .."' WHERE Tag = 'TXT_KEY_"..leadertype.."'")
if iPlayer==iActivePlayer then -- not sure if the "you" txt key also should be updated...
table.insert(tquery,"UPDATE "..localelanguage.." SET Text = '".. You..icons .."' WHERE Tag = 'TXT_KEY_YOU'")
end
end
end
end
for i, iQuery in pairs(tquery) do
print ("Changing Leadernames: " .. i .. "/" .. #tquery );
for result in DB.Query(iQuery) do
end
end
Locale.SetCurrentLanguage( Locale.GetCurrentLanguage().Type )
end
local g_SaveData = Modding.OpenSaveData();
function OnSequenceGameInitComplete()
print("OnSequenceGameInitComplete")
Events.SequenceGameInitComplete.Remove(OnSequenceGameInitComplete); -- only call this once
local bInit = g_SaveData.GetValue("CivIVRandomTraits_Distributed");
if not bInit then
g_SaveData.SetValue("CivIVRandomTraits_Distributed", Distribute_Random_Traits());
end
UpdateLeaderNames() -- update the leader names. this has to be done after every game load, so we dont check bInit for it.
end
Events.SequenceGameInitComplete.Add( OnSequenceGameInitComplete );