Help with Lua

Countbuffalo

Chieftain
Joined
Aug 16, 2013
Messages
94
I've been making my current Civ for a bit now and I've just run into the hardest part, the Trait, since using XML for a trait limits what I can do, I've got to use lua, problem is, I'm having trouble understanding the whole thing.

Where do I write the lua, do I use modbuddy and write it like an XML?
How do I know what codes there are? The Civilisation Wiki has them all but they're not really explanatory.

My idea is that each city held gives a bonus to the generation of Great scientist in the capital, so the outline would be a search to check if the player is playing that Civ, a city count, and then work create a modifier from that?

Also, another thing I imagine would be easy once I understand what I'm doing, creating the Aztec change but with a different yield from kills (Such as Science)
 
I've been making my current Civ for a bit now and I've just run into the hardest part, the Trait, since using XML for a trait limits what I can do, I've got to use lua, problem is, I'm having trouble understanding the whole thing.

Where do I write the lua, do I use modbuddy and write it like an XML?
  • I generally use a text editor such as Notepad to do all my code, whether it be lua or XML, and then simply add the finished product to my ModBuddy project using ModBuddy's "Add > Existing Item" functionality. It is just too much of a pain to me ever to create much code directly within ModBuddy.
  • You can also create your ModBuddy project, add the files you are going to need, whether XML or SQL or LUA (they'll just be empty files of correct format-type at this point), save everything, then exit from ModBuddy and use your browser to navigate to the ModBuddy folder, using Notepad or another text-edit program open the XML or LUA files you just created, and create the code you need. Once you save and close the file, you can start ModBuddy back up at some later point and see the changes you have made.
  • Just don't have the ModBuddy project open and try to edit any of the files of your project using a text editor like Notepad at the same time.
See here for an intro to LUA programming: [Lua] Basic Modding Guide for Civ5 (by bane_)
How do I know what codes there are? The Civilisation Wiki has them all but they're not really explanatory.
If you have BNW, these also apply:
  1. API changes in Brave New World
  2. BNW Patch Version 1.0.3.276 New Lua Hooks Note that many but not all of these also apply to pre-BNW. See Post #28 where whoward69 compiled a nice table of which of these new hooks work for which expansions.
My idea is that each city held gives a bonus to the generation of Great scientist in the capital, so the outline would be a search to check if the player is playing that Civ, a city count, and then work create a modifier from that?

Also, another thing I imagine would be easy once I understand what I'm doing, creating the Aztec change but with a different yield from kills (Such as Science)
You'll want the Player:GetNumCities() method to get the number of cities a player has. And the Player:GetCapitalCity() method to get the player's capital city. But I think you need to look through bane_'s intro tutorial first before you proceed any further.

------------------------------------------------------------
[edit]

Also see here for what you need to do within Modbuddy to "activate" different types of files so that they will actually have an effect in-game: whoward69's what ModBuddy setting for what file types tutorial
 
Alright, thanks for the all the help, I'm glad to see there's a intro tutorial! Thanks again.

I found the API for changing the great people rate, but how would I make it specific, it seems to apply to all great people rather than a single type.
 
Are you wanting to change the "rate" as a percentage per city in the empire or as a direct change in the number of Great Scientist GreatPersonPoints the capital will create?
 
I had intended for the ability to be a fixed amount, rather than a percentage, since that would probably be easier to balance, rate was all I could find. I guess it would be a percentage if I can't do a fixed number.
 
Actually, it's easier if you want to add a fixed number of GreatPersonPoints per city the empire owns. You can use a dummy building with the following as part of its definition under <Buildings>:
Code:
<SpecialistType>SPECIALIST_SCIENTIST</SpecialistType>
<GreatPeopleRateChange>1</GreatPeopleRateChange>
The example as shown would add "1" Scientist GreatPersonPoint per turn. Then you just add however many needed of the dummy (or hidden) building to the player's capital city via lua. If you want each city owned to give 3 GPP Scientist Points in the capital city, you just change to <GreatPeopleRateChange>3</GreatPeopleRateChange> in the dummy building, and add 1 dummy building to the capital for every city owned by the player.
 
How would I add a building using Lua? I can only find lines that deal with checking if a building can be built or for changing values to do with a building.
 
How would I add a building using Lua? I can only find lines that deal with checking if a building can be built or for changing values to do with a building.
As written here would include the capital city in the count of the number of cities, and the number of dummy buildings to be added:
Code:
gGreatPeopleBuilding = GameInfoTypes.BUILDING_GREAT_PEOPLE_DUMMY
gRequiredCivilization = "CIVLIZATION_ROME"

GameEvents.PlayerDoTurn.Add(function(iPlayer)
	local pPlayer = Players[iPlayer]
	if not pPlayer:IsAlive() then return end
	if pPlayer:GetCivilizationType() ~= GameInfoTypes[gRequiredCivilization] then return end
	local pCapitalCity = pPlayer:GetCapitalCity()
	local iNUmberCities = pPlayer:GetNumCities()
	pCapitalCity:SetNumRealBuilding(gGreatPeopleBuilding, iNUmberCities)
end)
Just change "CIVLIZATION_ROME" and BUILDING_GREAT_PEOPLE_DUMMY as needed based on what you actually call your civilization and the dummy building within your mod's XML.

edit -> see whoward69's what ModBuddy setting for what file types tutorial if you're not sure how to "activate" the lua program in your modbuddy settings. You want InGameUIAddin
 
Top Bottom