Population Trait Lua Help

Carloso

Warlord
Joined
Jan 30, 2014
Messages
162
Location
Ireland
I need help with a trait for a civilization. It goes like this,

Receive +1 :c5citizen: Population in every city when you advance to the next era.

Anything would be greatly appreciated!
 
Untested (especially in that as this is a "SerialEvent" it may only work for human players and not the AI), but it'll be something like

Code:
local iMySpecialCiv = GameInfoTypes.CIVILIZATION_ENGLAND

Events.SerialEventEraChanged.Add(function(iEra, iPlayer)
  local pPlayer = Players[iPlayer]
  
  if (pPlayer:GetCivilizationType() == iMySpecialCiv) then
    for pCity in pPlayer:Cities() do
      pCity:ChangePopulation(1, true)
    end
  end
end)
 
I did some testing on the SerialEventEraChanged awhile back and it works for AI players. It did seem to be tied to when the art style of a player's cities changed, so if a player got a tech and advanced to the next age in the middle of a turn (say via Great Scientist slingshot) than the SerialEvent wouldn't fire until the start of that player's next turn.

I have an algorithm that detects era changes using the tech finished event, so it does not have the above limitation. However, I didn't implement it after I realized that the SerialEvent was almost as good and required less work.
 
Untested (especially in that as this is a "SerialEvent" it may only work for human players and not the AI), but it'll be something like

Code:
local iMySpecialCiv = GameInfoTypes.CIVILIZATION_ENGLAND

Events.SerialEventEraChanged.Add(function(iEra, iPlayer)
  local pPlayer = Players[iPlayer]
  
  if (pPlayer:GetCivilizationType() == iMySpecialCiv) then
    for pCity in pPlayer:Cities() do
      pCity:ChangePopulation(1, true)
    end
  end
end)

Hang on, what would that be if the civilization is lets say Uruguay under the leadership of Rivera?
 
Just change the ["CIVILIZATION_ENGLAND"] to ["CIVILIZATION_URUGUAY"] or something.
Theres also the iMySpecialCiv Whoward added in but I'm unsure whether its iuruguay, iUruguay or uruguay.

Mesa new to lua.
 
In your mod that adds the new civ, you added a CIVILIZATION_XYZ entry, just do as Viregel says and change CIVILIZATION_ENGLAND to whatever you added as CIVILIZATION_XYZ there is no need to change anything else. You will obviously need to actually add the code into your mod and activate it - see the File attributes link in my sig for how to activate it
 
Thanks Whoward, it worked!

It seems your right Machiavelli. It only changes when the art-style does.
 
Back
Top Bottom