GameEvents.SetPopulation (Civ5 API)

From Civilization Modding Wiki
Jump to navigationJump to search

This page is a part of the Lua and UI Reference (Civ5).


Function.png This function is a member of GameEvents.

This is a static method, invoke it with a dot.


Triggered whenever any city changes population. At least, as far as we know. Information provided by User:Sseckman calls this CitySetPopulation, but the scenario Lua files refer to SetPopulation.


Usage

void GameEvents.SetPopulation(int x, int y, unknown oldPopulation, int newPopulation)


Event Type

Unknown

Parameters

x: Location of city with change in population
y: No description available.
oldPopulation: The population of the city before the change
newPopulation: The population of the city after the change


Source code samples

TurnsRemaining.lua - DLC_02 DLC

DLC/DLC_02/Scenarios/NewWorldScenario/TurnsRemaining.lua
0052
GameEvents.SetPopulation.Add(function(iX, iY, oldPopulation, newPopulation)
0054
local plot = Map.GetPlot(iX, iY);
0055
local city = plot:GetPlotCity();
0057
if (city:IsRazing()) then
0059
if (newPopulation > 0) then
0061
if (GenerateTreasureFromRazedCity(Game:GetHandicapType(), city:GetOwner(), city:GetPreviousOwner())) then
0062
local player = Players[city:GetOwner()];
0063
local iUnitID;
0064
iUnitID = GameInfoTypes["UNIT_TREASURE"];
0065
player:InitUnit (iUnitID, iX, iY);
0067
local text;
0068
local heading;
0069
text = Locale.ConvertTextKey("TXT_KEY_NEWWORLD_SCENARIO_TREASURE_RAZED_CITY", city:GetName());
0070
heading = Locale.ConvertTextKey("TXT_KEY_NEWWORLD_SCENARIO_TREASURE_FOUND");
0071
player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, heading);
0072
end
0073
end
0074
end
0076
return true;
0077
end);



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.