GameEvents.SetAlly (Civ5 API)

From Civilization Modding Wiki
Revision as of 20:28, 19 September 2012 by DonQuich (talk | contribs) (Bot update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 when the ally of a City-State changes (whether it changes from none or from another player).


Usage

void GameEvents.SetAlly(PlayerID cSPlayer, PlayerID oldAlly, PlayerID newAlly)


Event Type

Unknown

Parameters

cSPlayer: The City-State player in question
oldAlly: The former ally of the City-State; presumably nil or similar if the CS did not have an ally
newAlly: The new ally of the City-State


Source code samples

Too many occurences. Only 50 out of 2 are listed.

TurnsRemaining.lua - DLC_04 DLC

DLC/DLC_04/Scenarios/1066Scenario/TurnsRemaining.lua
0135
GameEvents.SetAlly.Add(function(iCSPlayer, iOldAlly, iNewAlly)
0137
print ("SetAlly called, params: " .. tostring(iCSPlayer) .. ", " .. tostring(iOldAlly) .. ", " .. tostring(iNewAlly));
0139
if (iNewAlly == -1) then
0140
local pPlayer = Players[iOldAlly];
0141
for unit in pPlayer:Units()
0142
   do
0143
   if (unit:IsCombatUnit() and unit:GetOriginalOwner() == iCSPlayer) then
0144
   ChangeOwner(unit, iCSPlayer, -1);
0145
   end
0146
   end
0147
   else
0148
   local pPlayer = Players[iCSPlayer];
0149
   for unit in pPlayer:Units()
0150
   do
0151
   if (unit:IsCombatUnit()) then
0152
   ChangeOwner(unit, iNewAlly, iCSPlayer);
0153
   end
0154
   end
0155
   end
0157
   if (iNewAlly == -1) then
0158
   if (iOldAlly == Game.GetActivePlayer())   then
0160
   local strPlayerKey = Players[iCSPlayer]:GetCivilizationShortDescriptionKey();
0162
   -- Put up dialog box
0163
   local popupInfo = {
0164
   Data1 = 500,
0165
   Type = ButtonPopupTypes.BUTTONPOPUP_TEXT,
0166
   Text = Locale.ConvertTextKey("TXT_KEY_1066_SCENARIO_ALLY_LOST", strPlayerKey);
0167
   }
0169
   UI.AddPopup(popupInfo);
0170
   end
0171
   else
0172
   if (iNewAlly == Game.GetActivePlayer())   then
0174
   local strPlayerKey = Players[iCSPlayer]:GetCivilizationShortDescriptionKey();
0176
   -- Put up dialog box
0177
   local popupInfo = {
0178
   Data1 = 500,
0179
   Type = ButtonPopupTypes.BUTTONPOPUP_TEXT,
0180
   Text = Locale.ConvertTextKey("TXT_KEY_1066_SCENARIO_ALLY_GAINED", strPlayerKey);
0181
   }
0183
   UI.AddPopup(popupInfo);
0184
   end
0185
   end
0187
   end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/MedievalScenario/TurnsRemaining.lua
0331
GameEvents.SetAlly.Add(function(iMinor, iOldAlly, iNewAlly)
0333
local iMeccaPlayer = GetPersistentProperty("MeccaPlayer");
0334
local iVaticanPlayer = GetPersistentProperty("VaticanPlayer");
0335
local iProtestantPlayer = GetPersistentProperty("ProtestantHolyCityPlayer")
0337
if (iNewAlly == -1) then
0338
if (iMinor == iMeccaPlayer) then
0339
Game.SetFounder(GameInfoTypes["RELIGION_ISLAM"], iMeccaPlayer);
0340
elseif (iMinor == iVaticanPlayer) then
0341
Game.SetFounder(GameInfoTypes["RELIGION_CHRISTIANITY"], iVaticanPlayer);
0342
end
0344
else
0345
local civType = Players[iNewAlly]:GetCivilizationType();
0347
if (iMinor == iMeccaPlayer) then
0348
if (civType == GameInfo.Civilizations["CIVILIZATION_SONGHAI"].ID or
0349
civType == GameInfo.Civilizations["CIVILIZATION_OTTOMAN"].ID or
0350
civType == GameInfo.Civilizations["CIVILIZATION_ARABIA"].ID) then
0351
Game.SetFounder(GameInfoTypes["RELIGION_ISLAM"], iNewAlly);
0352
else
0353
Game.SetFounder(GameInfoTypes["RELIGION_ISLAM"], iMeccaPlayer);
0354
end
0356
elseif (iMinor == iVaticanPlayer) then
0357
if (MyCurrentReligion(iNewAlly) == 2 and
0358
(civType == GameInfo.Civilizations["CIVILIZATION_FRANCE"].ID or
0359
civType == GameInfo.Civilizations["CIVILIZATION_CELTS"].ID or
0360
civType == GameInfo.Civilizations["CIVILIZATION_ENGLAND"].ID or
0361
civType == GameInfo.Civilizations["CIVILIZATION_SPAIN"].ID or
0362
civType == GameInfo.Civilizations["CIVILIZATION_NETHERLANDS"].ID or
0363
civType == GameInfo.Civilizations["CIVILIZATION_AUSTRIA"].ID or
0364
civType == GameInfo.Civilizations["CIVILIZATION_SWEDEN"].ID)) then
0365
Game.SetFounder(GameInfoTypes["RELIGION_CHRISTIANITY"], iNewAlly);
0366
else
0367
Game.SetFounder(GameInfoTypes["RELIGION_CHRISTIANITY"], iVaticanPlayer);
0368
end
0370
elseif (iMinor == GetPersistentProperty("ProtestantHolyCityPlayer")) then
0371
if (MyCurrentReligion(iNewAlly) == 13 and
0372
(civType == GameInfo.Civilizations["CIVILIZATION_FRANCE"].ID or
0373
civType == GameInfo.Civilizations["CIVILIZATION_CELTS"].ID or
0374
civType == GameInfo.Civilizations["CIVILIZATION_ENGLAND"].ID or
0375
civType == GameInfo.Civilizations["CIVILIZATION_SPAIN"].ID or
0376
civType == GameInfo.Civilizations["CIVILIZATION_NETHERLANDS"].ID or
0377
civType == GameInfo.Civilizations["CIVILIZATION_AUSTRIA"].ID or
0378
civType == GameInfo.Civilizations["CIVILIZATION_SWEDEN"].ID)) then
0379
Game.SetFounder(GameInfoTypes["RELIGION_PROTESTANTISM"], iNewAlly);
0380
else
0381
Game.SetFounder(GameInfoTypes["RELIGION_PROTESTANTISM"], iProtestantPlayer);
0382
end
0384
end
0385
end
0387
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.