Adding a custom trait to a civilization

Try something like this. It utilizes how the Palace and Big Ben work
Code:
<!--Also define the buiding(class) in the Buildings+Buildingclasses table like you would do with any other dummy building-->
<Building_HurryModifiers>
        <Row>
            <BuildingType>BUILDING_JARULA_CHEAP_HURRY</BuildingType>
            <HurryType>HURRY_GOLD</HurryType> <!--This is how the Big Ben is coded-->
            <HurryCostModifier>-25</HurryCostModifier>
        </Row>
    </Building_HurryModifiers>
<Civilization_FreeBuildingClasses>
        <Row>
            <CivilizationType>CIVILIZATION_JARULA_CIV_WITH_CHEAP_HURRY</CivilizationType>
            <BuildingClassType>BUILDINGCLASS_JARULA_CHEAP_HURRY</BuildingClassType><!--This is how the Palace works-->
        </Row>
    </Civilization_FreeBuildingClasses>
I'm unsure whether Civilization_FreeBuildingClasses adds the buildingclass in just the Capital, or in every city. If the latter, try adding <Capital>true</Capital> to your buildings-entry of your dummy building, as that's also in the building-defintion of the palace. (I suspect it will get placed in every city without <Capital>true</Capital>, but I haven't tested this, and have never used it before myself)
EDIT: Don't add <Capital> to any building ever. See LeeS description below
 
Last edited:
<Capital> makes the city where the building is constructed (or otherwise placed) the empire's capital. You should never use it for any building other than a Palace unique replacement.

Entries in <Civilization_FreeBuildingClasses> are only added to the capital city. But if you move the empire's capital by the <Capital> mechanic I believe the Palace and any other buildings listed in table <Civilization_FreeBuildingClasses> are not moved along with the "capital" status.

You're probably better off in this case to give a free dummy policy that has the Hurry Modifier as is done with Mercantilism
Code:
	<Policy_HurryModifiers>
		<Row>
			<PolicyType>POLICY_MERCANTILISM</PolicyType>
			<HurryType>HURRY_GOLD</HurryType>
			<HurryCostModifier>-25</HurryCostModifier>
		</Row>
	</Policy_HurryModifiers>
 
<Capital> makes the city where the building is constructed (or otherwise placed) the empire's capital. You should never use it for any building other than a Palace unique replacement.
Ah, that's what it does!

Entries in <Civilization_FreeBuildingClasses> are only added to the capital city. But if you move the empire's capital by the <Capital> mechanic I believe the Palace and any other buildings listed in table <Civilization_FreeBuildingClasses> are not moved along with the "capital" status.
Whenever your Capital gets captured, the palace moves to another one of your cities, essentially 'moving your capital'. I however don't know how buildings in Civilization_FreeBuildingClasses interact with this. I.e. do they move towards this 'new capital' as well, or is it just the <Capital>-building that moves? I'll probably do a test run this evening, so you can expect an EDIT.

EDIT: It seems that only the Capital gets moved if your Original Capital gets captured (and moved back when you recapture your original capital). Other buildings in Civilization_FreeBuildingClasses never move (or get re-added if they have <NeverCapture>true</NeverCapture>).

It seems like the Palace is a (presumably hardcoded) exception

Spoiler :

Pre-Capital Capture:



Post-Capital Capture:


Capital-Recapture: no image (forgot to screenshot :cringe:) but the building isn't there in the original capital (nor the 2nd city)
 
Last edited:
I'm kinda confused on how you get lua to execute for a trait. So if I have a .lua file, how do I get it so that it's used by the trait.xml file?
So for example I have this code here that I made:
Code:
function WLTKDforConversions()
    local pPlayer = Players[Game.GetActivePlayer()]
    local playerReligion = pPlayer:GetReligionCreatedByPlayer();
    NumCitiesFollowing = Game.GetNumCitiesFollowing(playerReligion);
    if (NumCitiesFollowing == 4) then
        for pCity in pPlayer:Cities() do
            pCity:ChangeWeLoveTheKingDayCounter(2);
        end
    end
So when the function is called, the active player gets 2 turns of WLTKD in all cities if they have 4 cities following their religion (just an example). How would I make it so that this lua function is called for my unique trait?
 
Your lua code actually has nothing to do with anything in table <Traits> in an XML file.

In order to make a custom trait via an lua script you generally use an lua function to determine (a) is Leader or Civilization X even a part of the current game, and if so, (b) determine which player is the one running under that leader or civilization. The simplest way to do this for the novice at lua is like the following
Code:
function PlayerTurnStart(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_ROME then
		-- do stuff for that civilization
	end
end
GameEvents.PlayerDoTurn.Add(PlayerTurnStart)
You just replace "CIVILIZATION_ROME" with the correct XML name of the civilization you want. The PlayerDoTurn event fires at the beginning of every turn for each civilization (in lua jargon: "Player") that is taking part in a given game as they take their turn.

Game.GetActivePlayer() will always be the human player in a Single Player game regardless of the civilization or leader the human is playing as, and will be the player currently in the Hotseat in a HotSeat Multuiplayer Game. I can't remember for sure anymore but I think for a "regular" Multiplayer game Game.GetActivePlayer() is always the host of the match.
 
Last edited:
Well if you were using the code you posted it would only work in the one case where the number of cities following the religion was 4. Any other number of cities following the religion would not execute.
 
Top Bottom