Upon city capture, need to transfer city ownership

Austindud518

Chieftain
Joined
Apr 4, 2011
Messages
18
I have a cold war scenario that I am working on. I am making a LUA script that fires when ever a West or East German city is captured. What the script is supposed to do is to check and see who owns the city and who is capturing it. If the conqueror is a NATO member capturing an East German city, the script needs to transfer the city to West German ownership after it has been captured by the NATO ally. The opposite needs to happen when the Warsaw Pact captures a West German city; that city must be transferred to East Germany ownership. I have a basic script implemented, but it crashes when I try to locally define East and West Germany.

Ignore the print() functions, they are there for testing purposes. There is a UI popup that I intend to use to inform the player about city ownership changes, but I have commented it out for testing purposes. If successful, I plan to use the things I learned with this script to change city ownership when events fire (ex. Breakup of Yugoslavia) or when certain conditions are met (ex. the Soviet Union loses certain cities if they become a Capitalist nation)

The crash happens on this line:


print(eGermany:GetCivilizationDescription());

I have also commented on the error in the following code:

Code:
function OnCityCaptured (hexPos, playerID, cityID, newPlayerID)
	
	local pPlayer = Players[newPlayerID];
	print("Got aggressor!");
	print(pPlayer);
	local iPlayer = Players[playerID];
	print("Got defender!");
	print(iPlayer);
	local civTypeAggressor = pPlayer:GetCivilizationDescription();
	print("Got aggressor civ type!");
	print(civTypeAggressor);
	local civTypeDefender = iPlayer:GetCivilizationDescription();
	print("Got defender civ type!");
	print(civTypeDefender);
	local iTeam;
			iTeam = Teams[pPlayer:GetTeam()];
			print("Got aggressor team!");
			print(iTeam:GetName());

	local pTeam
			pTeam = Teams[iPlayer:GetTeam()];
			print("Got defender team!");
			print(pTeam:GetName());

	local pCity = pPlayer:GetCityByID(cityID);
	print("Got city ID!");
	print(pCity);

	local pCityName = pCity:GetName();
	print("Got City Name!");
	print(pCityName);

	local wid = GameInfo.Civilizations{Type="CIVILIZATION_WGERMANY"}().ID
	local eid = GameInfo.Civilizations{Type="CIVILIZATION_EGERMANY"}().ID

	local eGermany = Players[eid];
		print("East Germany has been defined locally!");
                -Error occurs on the line below this one
		print(eGermany:GetCivilizationDescription());
	local wGermany = Players[wid];
		print("West Germany has been defined locally!");
		print(wGermany:GetCivilizationDescription());

	local pAct = Teams[eGermany:GetTeam()];

	local nAto = Teams[wGermany:GetTeam()];

	--local popupInfo = {
		--Data1 = 500,
		--Type = ButtonPopupTypes.BUTTONPOPUP_TEXT,
	--}
	
	print("Checking who captured the city...");
	print("NATO Team ID:")
	print(nAto:GetID())
	print("PACT Team ID:")
	print(pAct:GetID())
	print("Aggressor Team ID:")
	print(pTeam:GetID())
	print("Defender Team ID:")
	print(iTeam:GetID())
	print("West Germany ID:");
	print(GameInfo.Civilizations["CIVILIZATION_WGERMANY"].ID);
	print("East Germany ID:");
	print(GameInfo.Civilizations["CIVILIZATION_EGERMANY"].ID);
	-- Who Captured?
	if (pTeam:GetID() == pAct:GetID()) then

				if (iPlayer:GetID() == eGermany:GetID()) then

				eGermany:AcquireCity(pCity, false, true);
				print("East Germany acquires" + pCity:GetName() + "!");
				end
				
			end

	if (pTeam:GetID() == nAto:GetID()) then

				if (iPlayer:GetID() == wGermany:GetID()) then

				wGermany:AcquireCity(pCity, false, true);
				print("West Germany acquires" + pCity:GetName() + "!");
				end
				
			end

			--UI.AddPopup(popupInfo);
end
Events.SerialEventCityCaptured.Add( OnCityCaptured );

Here is my most recent Lua.log:

Code:
[794422.065] Initializing Lua 5.1.4
[794503.825] InstalledPanel: Refreshing Mods
[794503.825] InstalledPanel: GetModBrowserListings()
[794504.012] InstalledPanel: Refreshing Mods
[794504.012] InstalledPanel: GetModBrowserListings()
[794544.183] InstalledPanel: Refreshing Mods
[794544.183] InstalledPanel: GetModBrowserListings()
[794554.323] InstalledPanel: Refreshing Mods
[794554.323] InstalledPanel: GetModBrowserListings()
[794614.040] SelectCivilization: table: 16D2A2F0
[794620.951] SelectCivilization: select civ
[794630.311] CivilopediaScreen: SetSelectedCategory(12)
[794630.311] CivilopediaScreen: CivilopediaCategory[CategoryTerrain].DisplayList
[794630.389] CivilopediaScreen: SetSelectedCategory(1)
[794630.389] CivilopediaScreen: CivilopediaCategory[CategoryHomePage].DisplayList
[794632.354] Tutorial: Loaded Additional Tutorial checks - Assets\DLC\Expansion2\Tutorial\Lua\TutorialInclude_Expansion2.lua
[794632.354] Tutorial: Loaded Additional Tutorial checks - Assets\DLC\Expansion\Tutorial\lua\TutorialInclude_Expansion1.lua
[794634.242] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\DeclareWarPlunderTradeRoutePopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\NetworkKickedPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\CityPlotManagementPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCommandPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivEnterTerritoryPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\LiberateMinorPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ReturnCivilianPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\AnnexCityPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\BarbarianRansomPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmGiftPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCityTaskPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmPolicyBranchPopup.lua
[794634.242] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivGoldPopup.lua
[794635.474] EconomicGeneralInfo: Total Units - 9
[794635.474] EconomicGeneralInfo: Maint Free Units - 1
[794635.474] EconomicGeneralInfo: Paid Units - 8
[794635.490] EconomicGeneralInfo: Total Units - 9
[794635.490] EconomicGeneralInfo: Maint Free Units - 1
[794635.490] EconomicGeneralInfo: Paid Units - 8
[794636.925] ChoosePantheonPopup: 4
[794636.925] ChoosePantheonPopup: 963
[794636.925] ChoosePantheonPopup: 967
[794637.253] EspionageOverview: Refreshing My Cities
[794637.877] ChooseIdeologyPopup: 4
[794637.877] ChooseIdeologyPopup: 963
[794637.877] ChooseIdeologyPopup: 967
[794639.312] AdvisorInfoPopup: Closing Advisor Info
[794639.312] Demographics: Dequeuing demographics
[794639.312] Demographics: Dequeuing demographics
[794688.359] InGame: OnInterfaceModeChanged
[794688.359] InGame: oldInterfaceMode: 1
[794688.359] InGame: newInterfaceMode: 3
[794689.357] InGame: OnInterfaceModeChanged
[794689.357] InGame: oldInterfaceMode: 3
[794689.357] InGame: newInterfaceMode: 1
[794692.851] InGame: OnInterfaceModeChanged
[794692.851] InGame: oldInterfaceMode: 1
[794692.851] InGame: newInterfaceMode: 11
[794693.928] InGame: OnInterfaceModeChanged
[794693.928] InGame: oldInterfaceMode: 11
[794693.928] InGame: newInterfaceMode: 1
[794703.444] DiscussionDialog: DiploUIStateTypes.DIPLO_UI_STATE_WAR_DECLARED_BY_HUMAN
[794703.444] DiscussionDialog: DiploUIStateTypes.DIPLO_UI_STATE_WAR_DECLARED_BY_HUMAN NOT activated in DiscussionDialog
[794703.460] LeaderHeadRoot: Handling LeaderMessage: 1, You fool. You have made a terrible mistake.
[794703.460] CityBannerManager: CityBanner CombatBegin
[794707.282] InGame: OnInterfaceModeChanged
[794707.282] InGame: oldInterfaceMode: 1
[794707.282] InGame: newInterfaceMode: 11
[794708.108] InGame: OnInterfaceModeChanged
[794708.108] InGame: oldInterfaceMode: 11
[794708.108] InGame: newInterfaceMode: 1
[794709.715] CityBannerManager: CityBanner CombatEnd
[794709.731] CityBannerManager: CityBanner CombatBegin
[794714.364] CityBannerManager: CityBanner CombatEnd
[794730.916] CityBannerManager: CityBanner CombatBegin
[794735.939] CityBannerManager: CityBanner CombatEnd
[794738.981] CityBannerManager: CityBanner CombatBegin
[794740.806] CityBannerManager: CityBanner CombatEnd
[794742.850] CityBannerManager: CityBanner CombatBegin
[794747.343] CityBannerManager: CityBanner CombatEnd
[794747.358] CityBannerManager: CityBanner CombatBegin
[794751.991] CityBannerManager: CityBanner CombatEnd
[794760.634] CityBannerManager: CityBanner CombatBegin
[794764.004] CityBannerManager: CityBanner CombatEnd
[794774.471] CityBannerManager: CityBanner CombatBegin
[794776.858] CityBannerManager: CityBanner CombatEnd
[794783.972] CityBannerManager: CityBanner CombatBegin
[794786.967] CityBannerManager: CityBanner CombatEnd
[794789.166] CityBannerManager: CityBanner CombatBegin
[794792.552] CityBannerManager: CityBanner CombatEnd
[794797.310] CityBannerManager: CityBanner CombatBegin
[794800.586] CityBannerManager: CityBanner CombatEnd
[794802.754] CityBannerManager: CityBanner CombatBegin
[794804.330] CityBannerManager: CityBanner CombatEnd
[794808.620] CityBannerManager: CityBanner CombatBegin
[794809.759] CityBannerManager: CityBanner CombatEnd
[794818.323] NotificationPanel: Unknown Notification, Adding generic 53
[794819.337] TurnProcessing: Hiding TurnProcessing
[794824.048] InGame: OnInterfaceModeChanged
[794824.048] InGame: oldInterfaceMode: 1
[794824.048] InGame: newInterfaceMode: 11
[794824.875] InGame: OnInterfaceModeChanged
[794824.875] InGame: oldInterfaceMode: 11
[794824.875] InGame: newInterfaceMode: 1
[794824.891] CityBannerManager: CityBanner CombatBegin
[794826.654] InGame: OnInterfaceModeChanged
[794826.654] InGame: oldInterfaceMode: 1
[794826.654] InGame: newInterfaceMode: 11
[794827.558] InGame: OnInterfaceModeChanged
[794827.558] InGame: oldInterfaceMode: 11
[794827.558] InGame: newInterfaceMode: 1
[794827.668] CityBannerManager: CityBanner CombatEnd
[794827.683] CityBannerManager: CityBanner CombatBegin
[794830.491] CityBannerManager: CityBanner CombatEnd
[794832.316] CityBannerManager: CityBanner CombatBegin
[794836.887] CityBannerManager: CityBanner CombatEnd
[794837.886] CityBannerManager: CityBanner CombatBegin
[794843.112] CityBannerManager: CityBanner CombatEnd
[794843.158] CorrectCityCapture: Got aggressor!
[794843.158] CorrectCityCapture: table: 1712EAF8
[794843.158] CorrectCityCapture: Got defender!
[794843.158] CorrectCityCapture: table: 1712FF70
[794843.158] CorrectCityCapture: Got aggressor civ type!
[794843.158] CorrectCityCapture: Czechoslovak Socialist Republic
[794843.158] CorrectCityCapture: Got defender civ type!
[794843.158] CorrectCityCapture: Federal Republic of Germany
[794843.158] CorrectCityCapture: Got aggressor team!
[794843.158] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[794843.158] CorrectCityCapture: Got defender team!
[794843.158] CorrectCityCapture: Ronald Reagan/Margaret Thatcher/Willy Brandt/Charles de Gaulle/Einar Gerhardsen/Urho Kekkonen/Sandro Pertini
[794843.158] CorrectCityCapture: Got city ID!
[794843.158] CorrectCityCapture: table: 5D4B6298
[794843.158] CorrectCityCapture: Got City Name!
[794843.158] CorrectCityCapture: West Berlin
[794843.158] CorrectCityCapture: East Germany has been defined locally!
 
eid is the id of CIVILIZATION_EGERMANY in the database NOT the player id of the East German player

First up
Code:
local eid = GameInfo.Civilizations{Type="CIVILIZATION_EGERMANY"}().ID

can be written a lot more succinctly and efficiently as
Code:
local eid = GameInfoTypes.CIVILIZATION_EGERMANY
as these will never change during the game, you can make them global (ie place them outside of all functions, typically at the top of the lua file)

Once you have the civilisation id you'll need to loop all active players to find the player who is playing as that civilization, eg in the following helper function

Code:
function FindCivilizationPlayer(iCivilization)
  for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local pPlayer = Players[iPlayer]

    if (pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iCivilization) then
      return pPlayer
    end
  end

  return nil
end

combining those, to locate the specific East German player, use
Code:
local eGermany = FindCivilizationPlayer(eid)
 
Thank you for the help! As you can tell, I am very new to LUA.

This fixes my problem, but causes another. When I capture West Berlin (a West German City) it gives that city to East Germany as planned. But when I capture Bremerhaven (a different West German city) it gives East Germany Bratislava (one of my cities)! Do you know what might be causing this?

EDIT: I have noticed that certain cities are getting confused by the game. I will capture one city, and it will show in the print statements that I am attacking a different one!

Code:
function OnCityCaptured (hexPos, playerID, cityID, newPlayerID)

	local pPlayer = Players[newPlayerID];
	print("Got aggressor!");
	print(pPlayer);
	local iPlayer = Players[playerID];
	print("Got defender!");
	print(iPlayer);
	local civTypeAggressor = pPlayer:GetCivilizationDescription();
	print("Got aggressor civ type!");
	print(civTypeAggressor);
	local civTypeDefender = iPlayer:GetCivilizationDescription();
	print("Got defender civ type!");
	print(civTypeDefender);
	local iTeam;
			iTeam = Teams[pPlayer:GetTeam()];
			print("Got aggressor team!");
			print(iTeam:GetName());

	local pTeam
			pTeam = Teams[iPlayer:GetTeam()];
			print("Got defender team!");
			print(pTeam:GetName());

	local pCity = pPlayer:GetCityByID(cityID);
	print("Got city ID!");
	print(pCity);

	local pCityName = pCity:GetName();
	print("Got City Name!");
	print(pCityName);

	local wid = GameInfoTypes.CIVILIZATION_WGERMANY
	local eid = GameInfoTypes.CIVILIZATION_EGERMANY

function FindCivilizationPlayer(iCivilization)
  for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local pPlayer = Players[iPlayer]

    if (pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iCivilization) then
      return pPlayer
    end
  end

  return nil
end

local eGermany = FindCivilizationPlayer(eid)
print("East Germany has been defined locally!");
print(eGermany:GetCivilizationDescription());

local wGermany = FindCivilizationPlayer(wid)
print("West Germany has been defined locally!");
print(wGermany:GetCivilizationDescription());

local pAct = Teams[eGermany:GetTeam()];
local nAto = Teams[wGermany:GetTeam()];

	print("Checking who captured the city...");
	print("NATO Team ID:")
	print(nAto:GetID())
	print("PACT Team ID:")
	print(pAct:GetID())
	print("Aggressor Team ID:")
	print(pTeam:GetID())
	print("Defender Team ID:")
	print(iTeam:GetID())
	print("West Germany ID:");
	print(GameInfo.Civilizations["CIVILIZATION_WGERMANY"].ID);
	print("East Germany ID:");
	print(GameInfo.Civilizations["CIVILIZATION_EGERMANY"].ID);
	-- Who Captured?
	if (iTeam:GetID() == pAct:GetID()) then

				if (iPlayer:GetID() == wGermany:GetID()) then

				eGermany:AcquireCity(pCity, false, true);
				print("East Germany acquires ", pCity:GetName(), "!");

				end
				
			end

	if (iTeam:GetID() == nAto:GetID()) then

				if (iPlayer:GetID() == eGermany:GetID()) then

				wGermany:AcquireCity(pCity, false, true);
				print("West Germany acquires " + pCity:GetName() + "!");
				
				end
				
			end
			
			print("The Correct City has be captured!");
end
Events.SerialEventCityCaptured.Add( OnCityCaptured );
 
Sorry for double post, my LUA.log:

Code:
[877636.165] CityBannerManager: CityBanner CombatEnd
[877636.181] CityBannerManager: CityBanner CombatBegin
[877638.957] CityBannerManager: CityBanner CombatEnd
[877639.082] CityBannerManager: CityBanner CombatBegin
[877642.639] CityBannerManager: CityBanner CombatEnd
[877642.686] CorrectCityCapture: Got aggressor!
[877642.686] CorrectCityCapture: table: 16136150
[877642.686] CorrectCityCapture: Got defender!
[877642.686] CorrectCityCapture: table: 16137BB8
[877642.686] CorrectCityCapture: Got aggressor civ type!
[877642.686] CorrectCityCapture: Czechoslovak Socialist Republic
[877642.686] CorrectCityCapture: Got defender civ type!
[877642.686] CorrectCityCapture: Federal Republic of Germany
[877642.686] CorrectCityCapture: Got aggressor team!
[877642.686] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[877642.686] CorrectCityCapture: Got defender team!
[877642.686] CorrectCityCapture: Ronald Reagan/Margaret Thatcher/Willy Brandt/Charles de Gaulle/Einar Gerhardsen/Urho Kekkonen/Sandro Pertini
[877642.686] CorrectCityCapture: Got city ID!
[877642.686] CorrectCityCapture: table: 5BE63DE8
[877642.686] CorrectCityCapture: Got City Name!
[877642.686] CorrectCityCapture: West Berlin
[877642.686] CorrectCityCapture: East Germany has been defined locally!
[877642.686] CorrectCityCapture: German Democratic Republic
[877642.686] CorrectCityCapture: West Germany has been defined locally!
[877642.686] CorrectCityCapture: Federal Republic of Germany
[877642.686] CorrectCityCapture: Checking who captured the city...
[877642.686] CorrectCityCapture: NATO Team ID:
[877642.686] CorrectCityCapture: 23
[877642.686] CorrectCityCapture: PACT Team ID:
[877642.686] CorrectCityCapture: 1
[877642.686] CorrectCityCapture: Aggressor Team ID:
[877642.686] CorrectCityCapture: 23
[877642.686] CorrectCityCapture: Defender Team ID:
[877642.686] CorrectCityCapture: 1
[877642.686] CorrectCityCapture: West Germany ID:
[877642.686] CorrectCityCapture: 57
[877642.686] CorrectCityCapture: East Germany ID:
[877642.686] CorrectCityCapture: 50
[877642.686] CorrectCityCapture: East Germany acquires 	West Berlin	!
[877642.686] CorrectCityCapture: The Correct City has be captured!
[877643.700] TextPopup: one
[877644.074] CorrectCityCapture: Got aggressor!
[877644.074] CorrectCityCapture: table: 16135F98
[877644.074] CorrectCityCapture: Got defender!
[877644.074] CorrectCityCapture: table: 16136150
[877644.074] CorrectCityCapture: Got aggressor civ type!
[877644.074] CorrectCityCapture: German Democratic Republic
[877644.074] CorrectCityCapture: Got defender civ type!
[877644.074] CorrectCityCapture: Czechoslovak Socialist Republic
[877644.074] CorrectCityCapture: Got aggressor team!
[877644.074] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[877644.074] CorrectCityCapture: Got defender team!
[877644.074] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[877644.074] CorrectCityCapture: Got city ID!
[877644.074] CorrectCityCapture: table: 5BE63DE8
[877644.074] CorrectCityCapture: Got City Name!
[877644.074] CorrectCityCapture: West Berlin
[877644.074] CorrectCityCapture: East Germany has been defined locally!
[877644.074] CorrectCityCapture: German Democratic Republic
[877644.074] CorrectCityCapture: West Germany has been defined locally!
[877644.074] CorrectCityCapture: Federal Republic of Germany
[877644.074] CorrectCityCapture: Checking who captured the city...
[877644.074] CorrectCityCapture: NATO Team ID:
[877644.074] CorrectCityCapture: 23
[877644.074] CorrectCityCapture: PACT Team ID:
[877644.074] CorrectCityCapture: 1
[877644.074] CorrectCityCapture: Aggressor Team ID:
[877644.074] CorrectCityCapture: 1
[877644.074] CorrectCityCapture: Defender Team ID:
[877644.074] CorrectCityCapture: 1
[877644.074] CorrectCityCapture: West Germany ID:
[877644.074] CorrectCityCapture: 57
[877644.074] CorrectCityCapture: East Germany ID:
[877644.074] CorrectCityCapture: 50
[877644.074] CorrectCityCapture: The Correct City has be captured!
[877645.868] TextPopup: one
[877674.807] CityBannerManager: CityBanner CombatBegin
[877676.944] CityBannerManager: CityBanner CombatEnd
[877682.560] CityBannerManager: CityBanner CombatBegin
[877687.318] CityBannerManager: CityBanner CombatEnd
[877687.318] CityBannerManager: CityBanner CombatBegin
[877692.076] CityBannerManager: CityBanner CombatEnd
[877698.097] CityBannerManager: CityBanner CombatBegin
[877701.685] CityBannerManager: CityBanner CombatEnd
[877701.701] CityBannerManager: CityBanner CombatBegin
[877704.868] CityBannerManager: CityBanner CombatEnd
[877704.883] CityBannerManager: CityBanner CombatBegin
[877708.253] CityBannerManager: CityBanner CombatEnd
[878327.265] CityBannerManager: CityBanner CombatBegin
[878330.042] CityBannerManager: CityBanner CombatEnd
[878339.464] CityBannerManager: CityBanner CombatBegin
[878344.425] CityBannerManager: CityBanner CombatEnd
[878345.892] CityBannerManager: CityBanner CombatBegin
[878350.462] CityBannerManager: CityBanner CombatEnd
[878354.565] CityBannerManager: CityBanner CombatBegin
[878357.748] CityBannerManager: CityBanner CombatEnd
[878357.857] CorrectCityCapture: Got aggressor!
[878357.857] CorrectCityCapture: table: 16136150
[878357.857] CorrectCityCapture: Got defender!
[878357.857] CorrectCityCapture: table: 16137BB8
[878357.857] CorrectCityCapture: Got aggressor civ type!
[878357.857] CorrectCityCapture: Czechoslovak Socialist Republic
[878357.857] CorrectCityCapture: Got defender civ type!
[878357.857] CorrectCityCapture: Federal Republic of Germany
[878357.857] CorrectCityCapture: Got aggressor team!
[878357.857] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[878357.857] CorrectCityCapture: Got defender team!
[878357.857] CorrectCityCapture: Ronald Reagan/Margaret Thatcher/Willy Brandt/Charles de Gaulle/Einar Gerhardsen/Urho Kekkonen/Sandro Pertini
[878357.857] CorrectCityCapture: Got city ID!
[878357.857] CorrectCityCapture: table: 5BE68E60
[878357.857] CorrectCityCapture: Got City Name!
[878357.857] CorrectCityCapture: Bratislava
[878357.857] CorrectCityCapture: East Germany has been defined locally!
[878357.857] CorrectCityCapture: German Democratic Republic
[878357.857] CorrectCityCapture: West Germany has been defined locally!
[878357.857] CorrectCityCapture: Federal Republic of Germany
[878357.857] CorrectCityCapture: Checking who captured the city...
[878357.857] CorrectCityCapture: NATO Team ID:
[878357.857] CorrectCityCapture: 23
[878357.857] CorrectCityCapture: PACT Team ID:
[878357.857] CorrectCityCapture: 1
[878357.857] CorrectCityCapture: Aggressor Team ID:
[878357.857] CorrectCityCapture: 23
[878357.857] CorrectCityCapture: Defender Team ID:
[878357.857] CorrectCityCapture: 1
[878357.857] CorrectCityCapture: West Germany ID:
[878357.857] CorrectCityCapture: 57
[878357.857] CorrectCityCapture: East Germany ID:
[878357.857] CorrectCityCapture: 50
[878357.872] CorrectCityCapture: East Germany acquires 	Bratislava	!
[878357.872] CorrectCityCapture: The Correct City has be captured!
[878358.808] TextPopup: one
[878359.074] CorrectCityCapture: Got aggressor!
[878359.074] CorrectCityCapture: table: 16135F98
[878359.074] CorrectCityCapture: Got defender!
[878359.074] CorrectCityCapture: table: 16136150
[878359.074] CorrectCityCapture: Got aggressor civ type!
[878359.074] CorrectCityCapture: German Democratic Republic
[878359.074] CorrectCityCapture: Got defender civ type!
[878359.074] CorrectCityCapture: Czechoslovak Socialist Republic
[878359.074] CorrectCityCapture: Got aggressor team!
[878359.074] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[878359.074] CorrectCityCapture: Got defender team!
[878359.074] CorrectCityCapture: Gustav Husak/Leonid Brezhnev/Edward Gierek/Walter Ulbricht/Nicolae Ceausescu/Janos Kadar/Todor Zhivkov
[878359.074] CorrectCityCapture: Got city ID!
[878359.074] CorrectCityCapture: table: 5AA1AAD8
[878359.074] CorrectCityCapture: Got City Name!
[878359.074] CorrectCityCapture: Ost Berlin
[878359.074] CorrectCityCapture: East Germany has been defined locally!
[878359.074] CorrectCityCapture: German Democratic Republic
[878359.074] CorrectCityCapture: West Germany has been defined locally!
[878359.074] CorrectCityCapture: Federal Republic of Germany
[878359.074] CorrectCityCapture: Checking who captured the city...
[878359.074] CorrectCityCapture: NATO Team ID:
[878359.074] CorrectCityCapture: 23
[878359.074] CorrectCityCapture: PACT Team ID:
[878359.074] CorrectCityCapture: 1
[878359.074] CorrectCityCapture: Aggressor Team ID:
[878359.074] CorrectCityCapture: 1
[878359.074] CorrectCityCapture: Defender Team ID:
[878359.074] CorrectCityCapture: 1
[878359.074] CorrectCityCapture: West Germany ID:
[878359.074] CorrectCityCapture: 57
[878359.074] CorrectCityCapture: East Germany ID:
[878359.074] CorrectCityCapture: 50
[878359.074] CorrectCityCapture: The Correct City has be captured!
 
Code:
iTeam = Teams[pPlayer:GetTeam()];
pTeam = Teams[iPlayer:GetTeam()];

why is the iTeam being created from the pPlayer (and vice-versa) bound to cause confusion

p or i or e or w :confused: - you need to pick a consistent naming convention and stick with it - if you've never heard of "Hungarian notation" avoid lower case single letters at the start of variables and just use meaningful names, eg "aggPlayer", "defPlayer", "aggTeam", "eastGermany", "westGermany", "nato", "pact", etc

Code:
function OnCityCaptured (hexPos, playerID, cityID, newPlayerID)
  local pPlayer = Players[newPlayerID];

  ... SNIP ...

  local pCity = pPlayer:GetCityByID(cityID);

cityID belongs to playerID not newPlayerID (and as cityID isn't unique per game but per player there is a very good chance that newPlayerID will have a city with that ID)
 
Thanks to everyone for their attention to the issue. It has now been fixed. I was laying awake last night thinking about how to resolve this, when it hit me. The CityID is just a simple integer! This means that each time a city is captured, it is added to a players list of cities, and occupies the last spot on that list. West Germany gave West Berlin a CityID of 3, and when Czechoslovakia captured West Berlin, it also have it a CityID of 3 because West Berlin was Czechoslovakia's third city. This is why the script would function the first time I captured a city, but not any other time.

Here is the functional and finished script:

Code:
function OnCityCaptured (hexPos, playerID, cityID, newPlayerID)

	local popupInfo = {
		Data1 = 500,
		Type = ButtonPopupTypes.BUTTONPOPUP_TEXT,
	} 	
popupInfo.Text = Locale.ConvertTextKey("TXT_KEY_TESTY_TEST");
UI.AddPopup(popupInfo);

	local pPlayer = Players[newPlayerID];
	local iPlayer = Players[playerID];
	local civTypeAggressor = pPlayer:GetCivilizationDescription();
	local civTypeDefender = iPlayer:GetCivilizationDescription();
	local pTeam;
	pTeam = Teams[pPlayer:GetTeam()];
	local iTeam
	iTeam = Teams[iPlayer:GetTeam()];
	local pCity = pPlayer:GetCityByID(pPlayer:GetNumCities()-1);
	local pCityName = pCity:GetName();
	local wid = GameInfoTypes.CIVILIZATION_WGERMANY
	local eid = GameInfoTypes.CIVILIZATION_EGERMANY

function FindCivilizationPlayer(iCivilization)
  for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local pPlayer = Players[iPlayer]

    if (pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iCivilization) then
      return pPlayer
    end
  end

  return nil
end

function IndexCivilizationCities()
  for pCity in pPlayer:Cities() do
	local pCityID = pCity:GetID()
	return pCityID
	end

  return nil
end

local eGermany = FindCivilizationPlayer(eid)
print("East Germany has been defined locally!");
print(eGermany:GetCivilizationDescription());

local wGermany = FindCivilizationPlayer(wid)
print("West Germany has been defined locally!");
print(wGermany:GetCivilizationDescription());

local pAct = Teams[eGermany:GetTeam()];
local nAto = Teams[wGermany:GetTeam()];

print("***************************************");
print("***********Summary Readout:************");
print("NATO Team ID:")
print(nAto:GetID())
print("PACT Team ID:")
print(pAct:GetID())
print("***************************************");
print("Aggressor Team ID:")
print(pTeam:GetID())
print("Defender Team ID:")
print(iTeam:GetID())
print("***************************************");
print("West Germany ID:");
print(GameInfo.Civilizations["CIVILIZATION_WGERMANY"].ID);
print("East Germany ID:");
print(GameInfo.Civilizations["CIVILIZATION_EGERMANY"].ID);
print("***************************************");
print("Got aggressor!");
print(pPlayer);
print("Got defender!");
print(iPlayer);
print("***************************************");
print("Got aggressor civ type!");
print(civTypeAggressor);
print("Got defender civ type!");
print(civTypeDefender);
print("***************************************");
print("Got aggressor team!");
print(pTeam:GetName());
print("Got defender team!");
print(iTeam:GetName());
print("***************************************");
print("Got city ID!");
print(pCity);
print("Got City Name!");
print(pCityName);
print("***************************************");
print("**********End Summary Readout**********");

	print("Checking who captured the city...");
	-- Who Captured?
	if (pTeam:GetID() == pAct:GetID()) then

				if (iPlayer:GetID() == wGermany:GetID()) then

				eGermany:AcquireCity(pCity, false, true);
				print("East Germany acquires ", pCity:GetName(), "!");
				end
				
			end

	if (pTeam:GetID() == nAto:GetID()) then

				if (iPlayer:GetID() == eGermany:GetID()) then

				wGermany:AcquireCity(pCity, false, true);
				print("West Germany acquires ", pCity:GetName(), "!");
				
				end
				
			end
			
			print("The Correct City has been captured!");
end
Events.SerialEventCityCaptured.Add( OnCityCaptured );
 
Back
Top Bottom