C++/Lua Request Thread

You can actually set that in the Trait:

Code:
<GameData>
  <Traits>
    <Row>
      <Type>TRAIT_ORLAIS</Type>
      <Description>TXT_KEY_TRAIT_ORLAIS</Description>
      <ShortDescription>TXT_KEY_TRAIT_ORLAIS_SHORT</ShortDescription>
      <FreeBuildingOnConquest>BUILDING_ORLAIS_DUMMY</FreeBuildingOnConquest>
  </Traits>
</GameData>

Wow, that is so much easier. Thank you.
 
@DoktorApplejuce
That Lua looks suspiciously like JFD's code.

What? I don't know what you could possibly... er, yeah, it is. It's the same as the Kirkwall one above too. He is being credited in the special thanks section, as he suggested looking at his Lua to get that one working.
 
It had a mistake, I fixed it here:

Code:
<GameData>
<Traits>
<Row>
<Type>TRAIT_ORLAIS</Type>
<Description>TXT_KEY_TRAIT_ORLAIS</Description>
<ShortDescription>TXT_KEY_TRAIT_ORLAIS_SHORT</ShortDescription>
<FreeBuildingOnConquest>BUILDING_ORLAIS_DUMMY</FreeBuildingOnConquest>
</Row>
</Traits>
</GameData>
 
Does anybody have some code that deals with preplacing city states via lua?
 
Does anybody have some code that deals with preplacing city states via lua?

If by that you mean you want to place a specific city-state on a specific hex on a specific map, that actually can be done via XML. The mod "Yet (not) Another Earth Maps Pack" Contains a file under their XML folder that controls that.


Here's what they have:
Code:
<GameData>
	<MinorCiv_YagemStartPosition>
		<Row>
			<Type>MINOR_CIV_EDINBURGH</Type>
			<X>9</X>
			<Y>77</Y>
		</Row>
	</MinorCiv_YagemStartPosition>
</GameData>

Most of this is pretty obvious. The X and Y coordinates can be found by opening up the map you want to use in World Editor. The YagemStartPosition is probably defined somewhere else in their XML files, but I actually have to head out the door right now, so I don't have time to find where at the moment. I'd suggest looking for the mod I mentioned above. (Again, if this is what you're meaning)

If you mean something else, just go ahead and ignore me... I don't know a whole lot about Lua.
 
Is it possible to have a dynamic building info text?

For example I have unique granary that either gives +2/+3/+4/+5 Food depending Gamespeed. Is there a way to reflect this in the game text so when the player sees the correct tool tip?
 
Is there a way for a building to provide specific luxury resources resources depending on other resources around it? For example; I want to create a building, that if built in a city with access to wheat, provides a custom luxury resource, whiskey. But if built in a city with access to cocoa, the same building provides a copy of a custom luxury resource, Chocolate. (I hope that makes sense)
 
Is there a way for a building to provide specific luxury resources resources depending on other resources around it? For example; I want to create a building, that if built in a city with access to wheat, provides a custom luxury resource, whiskey. But if built in a city with access to cocoa, the same building provides a copy of a custom luxury resource, Chocolate. (I hope that makes sense)
If I were to do this:
  1. I would make two dummy buildings, one that gives Whiskey, and one that gives Chocolate.
  2. I would make a GameEvents.CityConstructed.Add(FancyBuildingCompleted) function in lua that would look for the primary 'real' building having been constructed. When constructed, I would have the function scan the city's plots for wheat and cocoa being near the city, improved, not-pillaged, and being worked by the city.
    • The City:IsHasResourceLocal() method pre-provided by Firaxis is unfortunately not really reliable because it gives too many false positives when two or more cities could work the same plot, and it gives false negatives in certain cases where one city is working a tile, but a different city from the same player is considered by the game to 'own' the tile.
    You could also make the code do an either/or sort of decision when a new copy of the building is constructed, such that if both wheat and cocoa are available to the city, and the player already has Chocolate, give the Whiskey luxury through the Whiskey Dummy Building. If the player has neither, then your code either defaults to Chocolate (for example), or 'flips a coin' to decide if it should give chocolate or whiskey.
  3. Because of issues related to new copies of a resource now being workable at some point later in the game, I would also tend to scan through a player's cities within a PlayerDoTurn looking for cities that have the building and have either lost access to the wheat/cocao or have added access to the wheat/cocoa. You might decide to only run the code-check-for-nearby-resources when the building is constructed, but this will ignore all the issues related to Barb-pillaging, Citadel culture-bombing, etc.
  4. The code itself for checking whether the resource is nearby when the building is constructed is not the hard part (at least for me), it is taking into consideration all these additional possibilities and making code to conform to them based on what you decide should happen when X happens long after the building is constructed.
  5. Also, unless the building is a World Wonder, National Wonder, or is limited in # a player can construct, there are going to be like 50 copies of the Chocolate and Whiskey resources available at some point in the game with each player controlling multiple copies of it.

Hint: Local City Resources Speed Wonder and Building Production does the scan-the-city-plots looking for workable/worked resources on a PlayerDoTurn event and also on a (Improvement) BuildFinished event.
  • The code is written to look 1st at what a city is constructing, and if it is constructing one of the Buildings/Wonders in the list that should have their production increased when Resource_X is nearby, improved, not-pillaged, and being worked by that city.
  • It only then looks through the plots around the city, and only when the required resource is nearby, improved, not-pillaged, and being worked by the city does it judge the resource as being "present" for that city.
  • Then it adds dummy buildings to the city that either increase the production of wonders, or the production of buildings, based on whether the city is constructing a building or a wonder.
 
If I were to do this:
  1. I would make two dummy buildings, one that gives Whiskey, and one that gives Chocolate.
  2. I would make a GameEvents.CityConstructed.Add(FancyBuildingCompleted) function in lua that would look for the primary 'real' building having been constructed. When constructed, I would have the function scan the city's plots for wheat and cocoa being near the city, improved, not-pillaged, and being worked by the city.
    • The City:IsHasResourceLocal() method pre-provided by Firaxis is unfortunately not really reliable because it gives too many false positives when two or more cities could work the same plot, and it gives false negatives in certain cases where one city is working a tile, but a different city from the same player is considered by the game to 'own' the tile.
    You could also make the code do an either/or sort of decision when a new copy of the building is constructed, such that if both wheat and cocoa are available to the city, and the player already has Chocolate, give the Whiskey luxury through the Whiskey Dummy Building. If the player has neither, then your code either defaults to Chocolate (for example), or 'flips a coin' to decide if it should give chocolate or whiskey.
  3. Because of issues related to new copies of a resource now being workable at some point later in the game, I would also tend to scan through a player's cities within a PlayerDoTurn looking for cities that have the building and have either lost access to the wheat/cocao or have added access to the wheat/cocoa. You might decide to only run the code-check-for-nearby-resources when the building is constructed, but this will ignore all the issues related to Barb-pillaging, Citadel culture-bombing, etc.
  4. The code itself for checking whether the resource is nearby when the building is constructed is not the hard part (at least for me), it is taking into consideration all these additional possibilities and making code to conform to them based on what you decide should happen when X happens long after the building is constructed.
  5. Also, unless the building is a World Wonder, National Wonder, or is limited in # a player can construct, there are going to be like 50 copies of the Chocolate and Whiskey resources available at some point in the game with each player controlling multiple copies of it.

Hint: Local City Resources Speed Wonder and Building Production does the scan-the-city-plots looking for workable/worked resources on a PlayerDoTurn event and also on a (Improvement) BuildFinished event.
  • The code is written to look 1st at what a city is constructing, and if it is constructing one of the Buildings/Wonders in the list that should have their production increased when Resource_X is nearby, improved, not-pillaged, and being worked by that city.
  • It only then looks through the plots around the city, and only when the required resource is nearby, improved, not-pillaged, and being worked by the city does it judge the resource as being "present" for that city.
  • Then it adds dummy buildings to the city that either increase the production of wonders, or the production of buildings, based on whether the city is constructing a building or a wonder.

Well, at the very least, I knew going in that this was going to be fairly complicated.

I'm assuming it would be fairly simple, once the basis of this building is complete, to make it so that if the city has both wheat and cocoa, that it'll provide both whiskey and chocolate? It would just require spawning in the two separate dummy buildings, each set to their own line of code based on their required resources.
 
Well, at the very least, I knew going in that this was going to be fairly complicated.

I'm assuming it would be fairly simple, once the basis of this building is complete, to make it so that if the city has both wheat and cocoa, that it'll provide both whiskey and chocolate? It would just require spawning in the two separate dummy buildings, each set to their own line of code based on their required resources.
Yup. You can make the lua give both types of dummy buildings to the city, or as many copies of each dummy building as you want. But you would still need to do the part with scanning the cities nearby plots in lua to determine if the city has both or only has cocoa, or only wheat.

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

There is another option that just occured to me: the basic building the player would build has three different available versions.

BUILDING_WHEAT_VERSION requires Wheat and gives Whiskey
BUILDING_COCOA_VERSION requires Cocoa and gives Chocolate
BUILDING_BOTH_VERSION requires both Cocoa and Wheat and gives both Chocolate and Whiskey.
Set all three buildings as mutually exclusive to each other in XML.

Then in lua you can disable the city from buildng the BUILDING_WHEAT_VERSION and BUILDING_COCOA_VERSION if the city can build the BUILDING_BOTH_VERSION.

All three versions of the building can use the same 'name' within their respective <Description> TXT_KEY_TAGS, as well as same icons. Game doesn't care about that.
 
Good Morning,

Would someone be able to code a civ trait allowing a leader to always suggest a third resolution at the world congress?
Or, eventually, not being forced to follow a voted resolution ?

Thanks to let me know! :)

Mezzzzz.
 
I have a question, and I hope someone could help me:
I am trying to make a UA for a civilization to be that it will receive a settler every time it destroys a barbarian camp. Any ideas on how to do it?
 
I am trying to make a UA for a civilization to be that it will receive a settler every time it destroys a barbarian camp. Any ideas on how to do it?

There's no event that I'm aware of for when a barbarian camp is cleared.

I can think of a way that would work by intercepting the popup that comes up, but of course that's only triggered if your civ is controlled by the human player. So you might want to just think about a new UA.

If you're OK with a human-only UA, then it'd be something like (i.e., this hasn't been tested):
Code:
function OnBarbClearPopup(popupInfo)
	if popupInfo.Type == ButtonPopupTypes.BUTTONPOPUP_BARBARIAN_CAMP_REWARD then
		if activePlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_YOURCIV"] then
			local newText = ""
			local label = "/InGame/BarbarianCampPopup/DescriptionLabel"
			local activePlayer = Players[Game.GetActivePlayer()]
			local newSettler = nil
			local selectedUnit = UI.GetHeadSelectedUnit()
			if Locale.GetCurrentLanguage().Type == "en_US" then
				newText = "You have freed captives, who have agreed to join your empire as Settlers!"
			else
				newText = Locale.ConvertTextKey("TXT_KEY_GOODY_SETTLER")
			end
			label:SetText(label:GetText() .."[NEWLINE][NEWLINE]".. newText)
			if selectedUnit then
				newSettler = activePlayer:InitUnit(GameInfoTypes["UNIT_SETTLER"], selectedUnit:GetX(), selectedUnit:GetY())
			else
				local activeCapital = activePlayer:GetCapitalCity()
				newSettler = activePlayer:InitUnit(GameInfoTypes["UNIT_SETTLER"], activeCapital:GetX(), activeCapital:GetY())
			end
			newSettler:JumpToNearestValidPlot()
		end
	end
end
Events.SerialEventGameMessagePopup.Add(OnBarbClearPopup)

I'm not sure whether the unit that cleared the camp will still count as the selected unit. If there's no selected unit, a settler is sent to the capital instead, so it should work either way.

The nice thing about using this method (i.e., intercepting popups) is that you can change the information displayed on the popup as I've done above without having to replace the popup entirely (i.e., adding a new VFS=true version of the file to your mod), which can cause compatibility issues with any other mod that might change the popup. Note if the current language isn't English, it'll just use the similar goody hut text ("You find survivors among the ruins...") which is close enough for non-English users.
 
I'm looking to create a UU replacement of the cargo ship that yields no gold to the recipient city-state/civilization.

LeeS kindly gave me the following code, which removes the gold from the recipient's treasury:
Spoiler :
Code:
iRequiredCiv = GameInfoTypes.CIVILIZATION_ROME
iRequiredDomain = GameInfoTypes.DOMAIN_SEA

function TradeRouteGoldCancel(playerID)
	local pPlayer = Players[playerID]
	if pPlayer:GetCivilizationType() == iRequiredCiv then
		local tradeRoutes = pPlayer:GetTradeRoutes()
		for i, v in ipairs(tradeRoutes) do
			if v.Domain == iRequiredDomain and v.FromCivilizationType == iRequiredCiv then
				local iGoldChange = math.floor(v.ToGPT / 100)
				Players[v.ToID]:ChangeGold(iGoldChange * -1) 
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(TradeRouteGoldCancel)

However, is there any way to make the trade overview reflect the lack of a gold yield for the recipient?
 
There's no event that I'm aware of for when a barbarian camp is cleared.

I can think of a way that would work by intercepting the popup that comes up, but of course that's only triggered if your civ is controlled by the human player. So you might want to just think about a new UA.

OK, thank you for the reply. I do not want to have a human-player only UA, so I will have to think of something else.
Another idea I have is that the civ's great generals can found cities. Can in be done without creating a new great general unit? If it can be done using XML only it would be even better)
 
Good evening,

I've created a mod using an improvement which claims adjacent tiles. However, I'd like it to not claim tiles which are already own by another civilization. The only mod I found using such feature is the one regarding the Inuits by TPangolin, but I'm kind of struggling with LUA. Therefore, could someone please provide me with a similar snippet adapted to my mod? (Mez's New France, available here and there)

Thanks,

Mezzzzz.
 
How can I implment the following UA?

Sword of Islam - Can build mosques after discovering theology. Units gain experience equal to triple the :c5faith: Faith output of the city they were produced in (capped at +30).
 
Can build mosques after discovering theology.
A unique building only the civ can build that gives freeBuildingCity (that may not be the exact XML name) a Mosques. The unique building would be unlocked at theology. Would only require XML to do all this.

Units gain experience equal to triple the :c5faith: Faith output of the city they were produced in (capped at +30).
Detect when a unit is created (I have a snippet that will do this). Then changeExperience based on the info from the city. Would require a couple of lines of lua.
 
Hi

I've recently added a Wonder Unit (<MaxGlobalInstances>1</MaxGlobalInstances>) to my mod, and I was wanting a notification to pop up, like what you get for building a wonder. Having looked at Firaxis' code, I decided to have a go, but I've got no real idea what I'm doing. Can anyone help?

What I came up with:
Spoiler :

Code:
print("300 Notification is working!");
local is300Ready = false;
function Is300Ready(iPlayer)
	local pPlayer = Players[iPlayer];
	if PlayerCanTrain (pPlayer, GameInfoTypes["UNIT_300"]) == true then
		is300Ready = true;
		GameEvents.PlayerDoTurn.Remove(Is300Ready);
	end
end
GameEvents.PlayerDoTurn.Add(Is300Ready);

function Is300Built(iPlayer)
	local pPlayer = Players[iPlayer]
	if (PlayerCanTrain(pPlayer, GameInfoTypes["UNIT_300"]) == false) and (is300Ready == true) then
		local portraitIndex = GameInfo.Units["UNIT_300"].PortraitIndex;
		IconHookup( portraitIndex, 80, GameInfo.Units["UNIT_300"].IconAtlas, instance.WonderConstructedAlphaAnim );
		GameEvents.PlayerDoTurn(iPlayer).Remove(Is300Built);
	end
	if iExtraGameData ~= -1 then
		CivIconHookup (iExtraGameData, 45, instance.CivIcon, instance.CivIconBH, instance.CivIconShadow, false, true );
		instance.WonderSmallCivFrame:SetHide(false);
		GameEvents.PlayerDoTurn.Remove(Is300Built);
	end
end
GameEvents.PlayerDoTurn.Add(Is300Built);
 
Alright, someone who knows lua better than me, why does this:
Code:
promotionCategories[xyz] = row.PediaType;
print("check: ",promotionCategories[xyz],"VS: ",row.PediaType);

produce this:
table: 14651698 VS: PEDIA_LAND

And how would I get to it work?

(It's a bit out of context, but the general gist of my issue is reached.)
 
Back
Top Bottom