• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

Lua help for city banner original city owner info

Joined
Apr 11, 2015
Messages
438
I'm trying to get the game to display cities' original owner info in the city icon's tooltip infobox in the city banner.

So, in the following screenshot, I would want it to say, underneath "City of Mongolia", "Original city of Bandar Brunei (city-state)".

Dx540Ff.png


There are some clues about how to do it in the section of code that tells the game to add a captured capital icon, saying "Original capital of [Civilization] (captured)".

Here's a section of code from the CityBannerManager.lua file. I've inserted a gap where I think the new code is going to need to go. At the end of the code is the section ORIGINAL OWNER CAPITAL ICON, which could be useful in showing how to do it.
Code:
        -- CAPITAL ICON
        if pPlayer then
            local instance:table = self.m_InfoIconIM:GetInstance();
            local tooltip:string = "";

            if pPlayer:IsMajor() then
                if pCity:IsOriginalCapital() and pCity:GetOriginalOwner() == pCity:GetOwner() then
                    if pCity:IsCapital() then
                        -- Original capitial still owned by original owner
                        instance.Icon:SetIcon("ICON_CITY_CAPITAL");
                    else
                        -- Former original capital
                        instance.Icon:SetIcon("ICON_FORMER_CAPITAL");
                    end
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                elseif pCity:IsCapital() then
                    -- New capital
                    instance.Icon:SetIcon("ICON_NEW_CAPITAL");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_NEW_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                else
                    -- Other cities
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_OTHER_CITY_TT", pPlayerConfig:GetCivilizationShortDescription());
                end








                if GameCapabilities.HasCapability("CAPABILITY_ESPIONAGE") then           
                    if Game.GetLocalPlayer() == playerID or HasEspionageView(playerID, cityID) then
                        tooltip = tooltip .. Locale.Lookup("LOC_ESPIONAGE_VIEW_ENABLED_TT");
                    else
                        tooltip = tooltip .. Locale.Lookup("LOC_ESPIONAGE_VIEW_DISABLED_TT");
                    end
                end

            elseif pPlayer:IsFreeCities() then
                instance.Icon:SetIcon("ICON_CIVILIZATION_FREE_CITIES");
                tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_FREE_CITY_TT");
            else
                instance.Icon:SetIcon("ICON_CITY_STATE");
                tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_CITY_STATE_TT");
            end

            instance.Button:SetTexture("Banner_TypeSlot");
            instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
            instance.Button:SetVoid1(playerID);
            instance.Button:SetVoid2(cityID);
            instance.Button:SetToolTipString(tooltip);

            -- ORIGINAL OWNER CAPITAL ICON
            if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCapital() then
                local pOriginalOwner:table = Players[pCity:GetOriginalOwner()];
                -- Only show the captured capital icon for major civs
                if pOriginalOwner:IsMajor() then
                    local instance:table = self.m_InfoIconIM:GetInstance();
                    instance.Icon:SetIcon("ICON_CAPTURED_CAPITAL");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    instance.Button:SetToolTipString(Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription()));
                    instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
                    instance.Button:SetVoid1(pCity:GetOriginalOwner());
                    instance.Button:SetVoid2(cityID);
                end
            end
        end
 
Here's the first line of the ORIGINAL OWNER CAPITAL ICON section of code:
Code:
            if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCapital() then
For captured city-states, I wonder if the game will understand this:
Code:
            if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCityState() then
And, if that worked, then for captured cities that weren't city-states, the code might be:
Code:
            if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCityState() == false then
 
Actually, the different requirements for captured city-states and captured non city-state cities can be set further down, where it says:

if pOriginalOwner:IsMajor() then

A separate clause for captured city-states can be enabled by changing IsMajor to IsMinor

if pOriginalOwner:IsMinor() then

I just tested, and removing the "and pCity:IsOriginalCapital()" clause from the first line makes the captured capital icon appear in all captured non-city-state cities.

From:

if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCapital() then

To:

if pCity:GetOwner() ~= pCity:GetOriginalOwner() then
 
So the next thing to do is try and delete from the code the bit where it tells it to insert the icon "ICON_CAPTURED_CAPITAL", and just keep the part where it tells the game to insert the description, which, in the captured capitals code, is directed to "LOC_CITY_BANNER_CAPTURED_CAPITAL_TT"

Perhaps the following deletions are correct?

if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCapital() then
local pOriginalOwner:table = Players[pCity:GetOriginalOwner()];
-- Only show the captured capital icon for major civs
if pOriginalOwner:IsMajor() then
local instance:table = self.m_InfoIconIM:GetInstance();
instance.Icon:SetIcon("ICON_CAPTURED_CAPITAL");

local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
instance.Button:SetToolTipString(Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription()));
instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
instance.Button:SetVoid1(pCity:GetOriginalOwner());
instance.Button:SetVoid2(cityID);
end
end
 
I inserted the following code (linking to the CAPTURED_CAPITAL text description for now):
Code:
            if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                end
It's appearing where I want it to - i.e. in captured cities - and also in the right infobox - i.e. City Icon. However, it's appearing on the same line as the first text description ("City of..."). It's also not stating the right Original owner (should be Mali in the screenshot).
0YXqbMt.png
 
What's your actual code in all this ?
 
What's your actual code in all this ?
I just inserted those four lines of code. Here's the section of the CityBannerManager.lua file:
Code:
        -- CAPITAL ICON
        if pPlayer then
            local instance:table = self.m_InfoIconIM:GetInstance();
            local tooltip:string = "";

            if pPlayer:IsMajor() then
                if pCity:IsOriginalCapital() and pCity:GetOriginalOwner() == pCity:GetOwner() then
                    if pCity:IsCapital() then
                        -- Original capitial still owned by original owner
                        instance.Icon:SetIcon("ICON_CITY_CAPITAL");
                    else
                        -- Former original capital
                        instance.Icon:SetIcon("ICON_FORMER_CAPITAL");
                    end
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                elseif pCity:IsCapital() then
                    -- New capital
                    instance.Icon:SetIcon("ICON_NEW_CAPITAL");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_NEW_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                else
                    -- Other cities
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_OTHER_CITY_TT", pPlayerConfig:GetCivilizationShortDescription());
                end




            if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                end




                if GameCapabilities.HasCapability("CAPABILITY_ESPIONAGE") then          
                    if Game.GetLocalPlayer() == playerID or HasEspionageView(playerID, cityID) then
                        tooltip = tooltip .. Locale.Lookup("LOC_ESPIONAGE_VIEW_ENABLED_TT");
                    else
                        tooltip = tooltip .. Locale.Lookup("LOC_ESPIONAGE_VIEW_DISABLED_TT");
                    end
                end
 
           elseif pPlayer:IsFreeCities() then
                instance.Icon:SetIcon("ICON_CIVILIZATION_FREE_CITIES");
                tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_FREE_CITY_TT");
            else
                instance.Icon:SetIcon("ICON_CITY_STATE");
                tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_CITY_STATE_TT");
            end

            instance.Button:SetTexture("Banner_TypeSlot");
            instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
            instance.Button:SetVoid1(playerID);
            instance.Button:SetVoid2(cityID);
            instance.Button:SetToolTipString(tooltip);

            -- ORIGINAL OWNER CAPITAL ICON
            if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCapital() then
                local pOriginalOwner:table = Players[pCity:GetOriginalOwner()];
                -- Only show the captured capital icon for major civs
                if pOriginalOwner:IsMajor() then
                    local instance:table = self.m_InfoIconIM:GetInstance();
                    instance.Icon:SetIcon("ICON_CAPTURED_CAPITAL");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    instance.Button:SetToolTipString(Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription()));
                    instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
                    instance.Button:SetVoid1(pCity:GetOriginalOwner());
                    instance.Button:SetVoid2(cityID);
                end
            end
        end
 
you'll have to add and use
Code:
local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
in your code, and add a newline tag as I suppose LOC_CITY_BANNER_CAPTURED_CAPITAL_TT is meant to be used alone, not in a merged tooltip

Code:
                  if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
 
Last edited:
you'll have to add and use
Code:
local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
in your code, and add a newline tag as I suppose LOC_CITY_BANNER_CAPTURED_CAPITAL_TT is meant to be used alone, not in a merged tooltip

Code:
                  if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. [NEWLINE]..Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
I needed to add quotation marks around [NEWLINE], but it's worked!

Thanks!

WiPAQbY.png
 
What's the difference between

~=

and

==

?

For example, in:

pCity:GetOriginalOwner() == pCity:GetOwner()
pCity:GetOwner() ~= pCity:GetOriginalOwner()

EDIT: According to maths on the internet, ~= means "does not equal".

So I guess:

== means "equals"

and

~= means "does not equal"

So I understand

pCity:GetOriginalOwner() == pCity:GetOwner()

as meaning "(If) the original owner is the current owner", and

pCity:GetOwner() ~= pCity:GetOriginalOwner()

as meaning "(If) the current owner is not the original owner"
 
Last edited:
Here's some code I've rustled up for specifying new City Icons and descriptions. There will be a captured city-state icon/description and a captured other city icon/description.

The new code is between the gaps in the following code:
Code:
        -- CAPITAL ICON
        if pPlayer then
            local instance:table = self.m_InfoIconIM:GetInstance();
            local tooltip:string = "";

            if pPlayer:IsMajor() then
                if pCity:IsOriginalCapital() and pCity:GetOriginalOwner() == pCity:GetOwner() then
                    if pCity:IsCapital() then
                        -- Original capitial still owned by original owner
                        instance.Icon:SetIcon("ICON_CITY_CAPITAL");
                    else
                        -- Former original capital
                        instance.Icon:SetIcon("ICON_FORMER_CAPITAL");
                    end
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
                elseif pCity:IsCapital() then
                    -- New capital
                    instance.Icon:SetIcon("ICON_NEW_CAPITAL");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_NEW_CAPITAL_TT", pPlayerConfig:GetCivilizationShortDescription());
               





elseif pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    if pOriginalOwner:IsMajor() then
                        instance.Icon:SetIcon("ICON_CAPTURED_OTHER_CITY");
                        tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_CAPTURED_OTHER_CITY_TT", pPlayerConfig:GetCivilizationShortDescription());
                    elseif pOriginalOwner:IsMinor() then
                        instance.Icon:SetIcon("ICON_CAPTURED_CITY_STATE");
                        tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_ICON_CAPTURED_CITY_STATE_TT", pPlayerConfig:GetCivilizationShortDescription());






                else
                    -- Other cities
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_OTHER_CITY_TT", pPlayerConfig:GetCivilizationShortDescription());
                end
 
               if GameCapabilities.HasCapability("CAPABILITY_ESPIONAGE") then          
                    if Game.GetLocalPlayer() == playerID or HasEspionageView(playerID, cityID) then
                        tooltip = tooltip .. Locale.Lookup("LOC_ESPIONAGE_VIEW_ENABLED_TT");
                    else
                        tooltip = tooltip .. Locale.Lookup("LOC_ESPIONAGE_VIEW_DISABLED_TT");
                    end
                end

            elseif pPlayer:IsFreeCities() then
                instance.Icon:SetIcon("ICON_CIVILIZATION_FREE_CITIES");
                tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_FREE_CITY_TT");
            else
                instance.Icon:SetIcon("ICON_CITY_STATE");
                tooltip = tooltip .. Locale.Lookup("LOC_CITY_BANNER_CITY_STATE_TT");
            end
            instance.Button:SetTexture("Banner_TypeSlot");
            instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
            instance.Button:SetVoid1(playerID);
            instance.Button:SetVoid2(cityID);
            instance.Button:SetToolTipString(tooltip);
            -- ORIGINAL OWNER CAPITAL ICON
            if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pCity:IsOriginalCapital() then
                local pOriginalOwner:table = Players[pCity:GetOriginalOwner()];
                -- Only show the captured capital icon for major civs
                if pOriginalOwner:IsMajor() then
                    local instance:table = self.m_InfoIconIM:GetInstance();
                    instance.Icon:SetIcon("ICON_CAPTURED_CAPITAL");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    instance.Button:SetToolTipString(Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription()));
                    instance.Button:RegisterCallback(Mouse.eLClick, OnCapitalIconClicked);
                    instance.Button:SetVoid1(pCity:GetOriginalOwner());
                    instance.Button:SetVoid2(cityID);
                end
            end
        end
 
In scripting languages that use == this is indeed specifying "is equal to"
~= specifies "is not equal to"

lua uses these
Code:
==   equal to
~=   not equal to
<=   less than or equal to
>=   greater than or equal to
<   less than
>   greater than
The last four can only be used in lua to compare two numerical values, because for example the text string "Cheeseburgers" cannot be evaluated as being less than or greater than the text-string "Hamburgers".

The equal-to and not-equal-to evaluations can be used to compare two text strings to each other, or two Booleans, or two "object" variables, etc., but in some cases lua will not allow mixing and matching between data TYPES. You can do this for example
Code:
if "Cheeseburgers" == "Hamburgers" then
or
Code:
if "Cheeseburgers" == 1 then
But as a general rule lua does not like to compare Boolean values against integer values in a "==" comparison though it will generally allow comparing a Boolean against an integer in a not-equal-to (~=) evaluation. [edit] Most of the time these sorts of Boolean to Integer evaluations are accepted but occasionally you will get runtime errors spit into the lua log rather than proper execution of the code, so you should bear this possibility in mind when mix-matching data types in an evaluation.

Code:
pCity:GetOwner()
and
Code:
pCity:GetOriginalOwner()
both return integer ID numbers, so comparing these against each other is comparing one number against another, even though to the lua initiate it may seem like they are comparing two object values against each other.
 
Last edited:
Thanks.

Do blank lines matter in Lua (i.e. hitting Return a few times between lines)? I've got two lua files that are identical except that one has some blank lines and one works and the other doesn't.
 
you'll have to add and use
Code:
local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
in your code, and add a newline tag as I suppose LOC_CITY_BANNER_CAPTURED_CAPITAL_TT is meant to be used alone, not in a merged tooltip

Code:
                  if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end


This is driving me nuts. This code isn't working any more:
Code:
                if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end

ETA: This is weird. It's happened a couple of times now. I try to modify the code, the city banner doesn't appear in-game. Then I put the original file back in and load the game and the city banner has not reappeared. I've even verified my game files with Steam. Then I tried it again and the same thing happened.

Is there some sort of game cache that's storing settings?
 
Last edited:
Blank lines don't matter in lua

Spaces don't generally matter either except in the specific case where a variable name might be confused with something else or when using the pre-provided methods like CityObject:IsOriginalCapital()

There is some caching to which we don't really have access but it is mostly to do with lists of enabled mods, etc., rather than anything that happens once you are In-Game.

But what you are experiencing is one reason why it is always best to not directly edit the game's original files. You can make a copy of the game's original version of CityBannerManager.lua and then paste this into a mod. Edit the copy you have made and added into the mod, and then create an InGame Action of "ImportFiles" and list the altered version of CityBannerManager.lua from the mod. Make sure NOT to change the name of the lua file. This causes your custom version of the lua file to completely replace the game's original version once you are In-Game but does not actually affect the original game file in any way.

Completely exiting the game and then reloading from scratch will often "reset" any caching issues that might be occurring from returning to the main menu and then reloading a save, etc. Though usually these sorts of issues don't apply to anything that happens after you click "Start Game" or "Load Saved Game".

If you are already Importing the file from a mod, but have no LoadOrder setting for the ImportFiles action, then standard loading order rules apply, and these are different when starting a new game from reloading a saved game. If you have another mod active that is also re-writing the same lua file, you can get two different orders in which the different versions of CityBannerManager.lua (or any lua file for that matter) load into the game and it is always the final version that loads for any game-session that is used In-Game.

---------

If you have inadvertently created a fatal syntax error in the text of CityBannerManager.lua you ought to see an error message in lua log for this -- and the game will not be able to execute the interface for the CityBannerManager because it cannot implement an lua User Interface fie that has failed to load properly because of syntax errors.
 
Blank lines don't matter in lua

Spaces don't generally matter either except in the specific case where a variable name might be confused with something else or when using the pre-provided methods like CityObject:IsOriginalCapital()

There is some caching to which we don't really have access but it is mostly to do with lists of enabled mods, etc., rather than anything that happens once you are In-Game.

But what you are experiencing is one reason why it is always best to not directly edit the game's original files. You can make a copy of the game's original version of CityBannerManager.lua and then paste this into a mod. Edit the copy you have made and added into the mod, and then create an InGame Action of "ImportFiles" and list the altered version of CityBannerManager.lua from the mod. Make sure NOT to change the name of the lua file. This causes your custom version of the lua file to completely replace the game's original version once you are In-Game but does not actually affect the original game file in any way.

Completely exiting the game and then reloading from scratch will often "reset" any caching issues that might be occurring from returning to the main menu and then reloading a save, etc. Though usually these sorts of issues don't apply to anything that happens after you click "Start Game" or "Load Saved Game".

If you are already Importing the file from a mod, but have no LoadOrder setting for the ImportFiles action, then standard loading order rules apply, and these are different when starting a new game from reloading a saved game. If you have another mod active that is also re-writing the same lua file, you can get two different orders in which the different versions of CityBannerManager.lua (or any lua file for that matter) load into the game and it is always the final version that loads for any game-session that is used In-Game.

---------

If you have inadvertently created a fatal syntax error in the text of CityBannerManager.lua you ought to see an error message in lua log for this -- and the game will not be able to execute the interface for the CityBannerManager because it cannot implement an lua User Interface fie that has failed to load properly because of syntax errors.
Thanks.

I'm not sure how to set it to make updates to a lua file yet, so I've been modifying the original files (after making backups, of course).

Anyway, the issue seems to have been that the lua filename had been changed. Now it's been reverted to the original, it's working again.
 
So here's that bit of code again, which works:
Code:
                if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    instance.Icon:SetIcon("ICON_OTHER_CITIES");
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_CITY_BANNER_CAPTURED_CAPITAL_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
I think the line
Code:
                     instance.Icon:SetIcon("ICON_OTHER_CITIES");
is not needed in this bit of the code, as this bit of code is not about specifying which icon to use, just displaying the original owner in infobox.

I tested it out with the line deleted and it still worked the same as before.

However, my attempt to expand this bit of code so that it does different things for captured Civ cities and captured city-states didn't work.

Here was my new code (1st attempt):
Code:
                if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    if pOriginalOwner:IsMajor() then
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CIV_CITY_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                    elseif pOriginalOwner:IsMinor() then
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CITY_STATE_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
2nd attempt:
Code:
                if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                     if pOriginalOwner:IsMajor() then
                        local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CIV_CITY_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                    elseif pOriginalOwner:IsMinor() then
                        local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CITY_STATE_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
3rd attempt:
Code:
                 if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pOriginalOwner:IsMajor() then
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CIV_CITY_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end

                if pCity:GetOwner() ~= pCity:GetOriginalOwner() and pOriginalOwner:IsMinor() then
                    local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                    tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CITY_STATE_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
The lua code was accompanied with the following XML code for the descriptions:
Code:
<GameData>
    <EnglishText>
        <Row Tag="LOC_CITY_BANNER_ORIGINAL_CIV_CITY_TT">
            <Text>Original city of {1_OriginalOwner}</Text>
        </Row>
        <Row Tag="LOC_CITY_BANNER_ORIGINAL_CITY_STATE_TT">
            <Text>Original city of {1_OriginalOwner} (city-state)</Text>
        </Row>
   </EnglishText>
</GameData>
 
Last edited:
Here's what the pertinent part of the modinfo file needs to look like when replacing a "main" User Interface file
Code:
    <ImportFiles id="LUA_Replacers">
      <Properties>
        <LoadOrder>150000</LoadOrder>
      </Properties>
      <File>LUA/Replacers/CityPanelOverview.lua</File>
      <File>LUA/Replacers/ProductionPanel.lua</File>
    </ImportFiles>
I'm using a really high LoadOrder value on purpose to make sure which version of the file gets used if I am running more than one mod in which I am replacing the original file. The mod I pulled this snippet from needs to have priority over all other versions from other mods I may have made and may be running, hence the high value for the LoadOrder.

In the modbuddy dropdown for selecting the type of action, you select ImportFiles instead of leaving the type of action as the default UpdateDatabase.

You can place the lua file anywhere within you mod that makes logical sense to you. What is important is that if you are editing lua file CityPanelOverview.lua, as in the example, that you keep the filename the same as the one the game uses.

--------------------------------------------

As far as your last-posted code, where are you defining object-variable pOriginalOwner ?

--------------------------------------------

From an examination of the game-files, there are three different versions of CityBannerManager.lua which is not how Firaxis have normally been doing this sort of thing.

The one used depends on the expansion. Make sure you are not using the wrong version of CityBannerManager.lua
 
Code:
               if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                     if pOriginalOwner:IsMajor() then
                        local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CIV_CITY_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                    elseif pOriginalOwner:IsMinor() then
                        local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CITY_STATE_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                end
This didn't work because you have a syntax error. See the extra needed end command below:
Code:
               if pCity:GetOwner() ~= pCity:GetOriginalOwner()  then
                     if pOriginalOwner:IsMajor() then
                        local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CIV_CITY_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                    elseif pOriginalOwner:IsMinor() then
                        local pOriginalOwnerConfig:table = PlayerConfigurations[pCity:GetOriginalOwner()];
                        tooltip = tooltip .. "[NEWLINE]"..Locale.Lookup("LOC_CITY_BANNER_ORIGINAL_CITY_STATE_TT", pOriginalOwnerConfig:GetCivilizationShortDescription());
                    end
                end
When an lua file does not do what you are trying to make it do the first place to look is in lua.log for syntax errors when the game attempts to load the file, and runtime errors when the game attempts to execute the contents of the file in real-time.
 
Last edited:
Back
Top Bottom