stuck creating my 1st civilisation

daylightend

Chieftain
Joined
Oct 11, 2014
Messages
16
Hey modders !

I just started my very first mod, a new civ.

I want the trait of my new civ to be something like "+15% production towards military unit construction while at war". I got this idea from the swords into swords into plowshares belief (+x% growth when not at war). When i looked up this belief in CIV5Beliefs.xml I found the following

Spoiler :
<Row>
<Type>BELIEF_SWORD_PLOWSHARES</Type>
<Description>TXT_KEY_BELIEF_SWORD_PLOWSHARES</Description>
<ShortDescription>TXT_KEY_BELIEF_SWORD_PLOWSHARES_SHORT</ShortDescription>
<Follower>true</Follower>
<CityGrowthModifier>15</CityGrowthModifier>
<RequiresPeace>true</RequiresPeace>
</Row>


I wonder if anyone can tell me where I can find the logic behind "<RequiresPeace>true</RequiresPeace>". And how I can create a state check like that one.

I hope some experienced modders can help me. Thx in advance !
 
You can't lift logic from a belief and insert it into a unique ability without modding the DLL. However, that's not necessary as it's fairly easy to use Lua to determine peace/war state. Note that several modded civs have UAs that rely on peace/war status from which you can derive your Lua code.

If you want to include being at war with city states you would simply check the status with:
Code:
if (Teams[player:GetTeam()]:GetAtWarCount(true) > 0) then

Otherwise, here's a function lifted from whoward69's post #21 of this thread to determine whether your civ is at war with another civ:
Code:
function AtWarWithAnyMajor(iTeam)
  local pTeam = Teams[iTeam]

  for iOtherPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
    local pOtherPlayer = Players[iOtherPlayer]
    if (pOtherPlayer:IsAlive() and pTeam:IsAtWar(pOtherPlayer:GetTeam())) then
      print(string.format("Team %i is at war with (at least) player %i", iTeam, iOtherPlayer))
      return true
    end
  end

  print(string.format("Team %i is at war with nobody", iTeam))
  return false
end

Either way, if the check was successful, you'd give all of your civ's cities a hidden, unbuildable building. That Building would have entries for all of the CombatClass types (from UnitCombatInfos) in the Building_UnitCombatProductionModifiers table.

Let me know if that's all Greek to you.
 
That Building would have entries for all of the CombatClass types (from UnitCombatInfos) in the Building_UnitCombatProductionModifiers table.
Just use <MilitaryProductionModifier>15</MilitaryProductionModifier> directly in <Buildings> to cover all military units. If you want only land units, forex, use this instead:
Code:
<Building_DomainProductionModifiers>
	<Row>
		<BuildingType>BUILDING_NEW_BUILDING</BuildingType>
		<DomainType>DOMAIN_LAND</DomainType>
		<Modifier>15</Modifier>
	</Row>
</Building_DomainProductionModifiers>
Much simpler than doing so through Building_UnitCombatProductionModifiers
 
Good point. But your second example would apply to civilians...
Yeah...I keep forgetting that.

But then when I do remember it I generally decide to live with it since it's so much easier to add the code, and to look at it later.

Daylightend, here's a list of all the UnitCombat types, the domain (land, sea, air) they fit into, and the units assigned to them. It's for Brave New World, things are slightly different for Vanilla and Gods & Kings. Listing of Units, Domains, and UnitCombat Types
 
Thanks all for the fast replies !

I understand the part about how to give production bonus to units. I wouldn't know how to "put" a hidden unbuildable building into a city. Probably because I'm very unexperienced with lua.

I've been trying to run a basic lua script that just prints your amount of gold into the log (form this tutorial http://forums.civfanatics.com/showthread.php?t=533853)

Spoiler :
function RichiesCoffers(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_RICHIE_RICH"] then
local iGold = pPlayer:GetGold()
print(iGold)
end
end
GameEvents.PlayerDoTurn.Add(RichiesCoffers)


Had no succes yet. I'm probably just missing something thats covered in all the tutorials O.O
 
Hints:
Is logging turned on in your config.ini?

Do you have your Lua file published as InGameUIAddin?

Before "if pPlayer...", throw in an extra
Code:
print("Hello world")
to see if your Lua is even running...
 
In config.ini i have:

Spoiler :
; Enable message logging
MessageLog = 1


assuming that is the loggin you are refering to ?

I included a pic for the file published as InGameUIAddin.

I put the hello world before the if, log still empty.
I also built, and ran the "empty" mod from this thread http://forums.civfanatics.com/showthread.php?t=490438

The hello world print from that mod also doens't show up in my lua.log
 

Attachments

  • lua.png
    lua.png
    78 KB · Views: 99
Allright, that was 0 :blush:

I turned it on, and this is what i got

log after loading the mod, in game setup screen

Spoiler :
[4122.810] Initializing Lua 5.1.4
[4161.872] InstalledPanel: Refreshing Mods
[4161.872] InstalledPanel: GetModBrowserListings()
[4161.888] InstalledPanel: Refreshing Mods
[4161.888] InstalledPanel: GetModBrowserListings()
[4168.377] InstalledPanel: Refreshing Mods
[4168.377] InstalledPanel: GetModBrowserListings()
[4168.736] InstalledPanel: Refreshing Mods
[4168.736] InstalledPanel: GetModBrowserListings()
[4169.953] InstalledPanel: Refreshing Mods
[4169.953] InstalledPanel: GetModBrowserListings()


log after starting a game with my modded civ, turn 0 (or 1)

Spoiler :
[4122.810] Initializing Lua 5.1.4
[4161.872] InstalledPanel: Refreshing Mods
[4161.872] InstalledPanel: GetModBrowserListings()
[4161.888] InstalledPanel: Refreshing Mods
[4161.888] InstalledPanel: GetModBrowserListings()
[4168.377] InstalledPanel: Refreshing Mods
[4168.377] InstalledPanel: GetModBrowserListings()
[4168.736] InstalledPanel: Refreshing Mods
[4168.736] InstalledPanel: GetModBrowserListings()
[4169.953] InstalledPanel: Refreshing Mods
[4169.953] InstalledPanel: GetModBrowserListings()
[4217.034] Map Script: Generating Map
[4217.034] Map Script: Setting Plot Types (Lua Skirmish) ...
[4217.050] Map Script: Setting Plot Types (MapGenerator.Lua)
[4217.050] Map Script: Setting coasts and oceans (MapGenerator.Lua)
[4217.050] Map Script: Expanding coasts (MapGenerator.Lua)
[4217.050] Map Script: Generating Terrain (Lua Skirmish) ...
[4217.128] Map Script: Setting Terrain Types (MapGenerator.Lua)
[4217.128] Map Script: Adding Features (Lua Skirmish) ...
[4217.143] Map Script: Creating start plot database.
[4217.143] Map Script: Dividing the map in to Regions.
[4217.143] Map Script: Map Generation - Dividing the map in to Regions
[4217.143] Map Script: -
[4217.143] Map Script: Civs: 2
[4217.143] Map Script: City States: 4
[4217.143] Map Script: -
[4217.143] Map Script: Teams: 2
[4217.143] Map Script: -
[4217.143] Map Script: Number of Teams present is two! Using custom team start placement for Skirmish.
[4217.143] Map Script: -
[4217.143] Map Script: -
[4217.143] Map Script: ---------------------------------------------
[4217.143] Map Script: Defined location of Start Region # 1
[4217.143] Map Script: ---------------------------------------------
[4217.143] Map Script: -
[4217.143] Map Script: -
[4217.143] Map Script: ---------------------------------------------
[4217.143] Map Script: Defined location of Start Region # 2
[4217.143] Map Script: ---------------------------------------------
[4217.143] Map Script: -
[4217.143] Map Script: Choosing start locations for civilizations.
[4217.143] Map Script: Map Generation - Choosing Start Locations for Civilizations
[4217.175] Map Script: Normalizing start locations and assigning them to Players.
[4217.175] Map Script: -
[4217.175] Map Script: This is a team game with two teams! Place one team in West, other in East.
[4217.175] Map Script: -
[4217.175] Map Script: Player # 0 belongs to Team # 0 and will be placed in the South.
[4217.175] Map Script: Player # 1 belongs to Team # 1 and will be placed in the North.
[4217.175] Map Script: Placing Natural Wonders.
[4217.206] Map Script: -
[4217.206] Map Script: -
[4217.206] Map Script: --- Number of Candidate Plots on the map for Natural Wonders ---
[4217.206] Map Script: -
[4217.206] Map Script: - 86 candidates for FEATURE_CRATER
[4217.206] Map Script: - 0 candidates for FEATURE_FUJI
[4217.206] Map Script: - 80 candidates for FEATURE_MESA
[4217.206] Map Script: - 0 candidates for FEATURE_REEF
[4217.206] Map Script: - 0 candidates for FEATURE_VOLCANO
[4217.206] Map Script: - 0 candidates for FEATURE_GIBRALTAR
[4217.206] Map Script: - 103 candidates for FEATURE_GEYSER
[4217.206] Map Script: - 187 candidates for FEATURE_FOUNTAIN_YOUTH
[4217.206] Map Script: - 160 candidates for FEATURE_POTOSI
[4217.206] Map Script: - 0 candidates for FEATURE_EL_DORADO
[4217.206] Map Script: - 0 candidates for FEATURE_SRI_PADA
[4217.206] Map Script: - 0 candidates for FEATURE_MT_SINAI
[4217.206] Map Script: - 19 candidates for FEATURE_MT_KAILASH
[4217.206] Map Script: - 0 candidates for FEATURE_ULURU
[4217.206] Map Script: - 187 candidates for FEATURE_LAKE_VICTORIA
[4217.206] Map Script: - 13 candidates for FEATURE_KILIMANJARO
[4217.206] Map Script: - 180 candidates for FEATURE_SOLOMONS_MINES
[4217.206] Map Script: -
[4217.206] Map Script: --- End of candidates readout for Natural Wonders ---
[4217.206] Map Script: -
[4217.206] Map Script: -- Placed all Natural Wonders --
[4217.206] Map Script: -
[4217.206] Map Script: -
[4217.206] Map Script: Placing Resources and City States.
[4217.206] Map Script: Map Generation - Assigning Luxury Resource Distribution
[4217.206] Map Script: -
[4217.206] Map Script: Region# 1 of type 1 has been assigned Luxury ID# 31
[4217.206] Map Script: -
[4217.206] Map Script: Region# 2 of type 1 has been assigned Luxury ID# 21
[4217.206] Map Script: Luxury ID# 21 rejected by City States as already belonging to Regions.
[4217.206] Map Script: Luxury ID# 31 rejected by City States as already belonging to Regions.
[4217.206] Map Script: --- Luxury Assignment Table ---
[4217.206] Map Script: -
[4217.206] Map Script: - - Assigned to Regions - -
[4217.206] Map Script: Region# 1 has Luxury type 31
[4217.206] Map Script: Region# 2 has Luxury type 21
[4217.206] Map Script: -
[4217.206] Map Script: - - Assigned to City States - -
[4217.206] Map Script: Luxury type 25
[4217.206] Map Script: Luxury type 33
[4217.206] Map Script: Luxury type 27
[4217.206] Map Script: -
[4217.206] Map Script: - - Assigned to Random - -
[4217.206] Map Script: Luxury type 23
[4217.206] Map Script: Luxury type 34
[4217.206] Map Script: Luxury type 19
[4217.206] Map Script: Luxury type 13
[4217.206] Map Script: -
[4217.206] Map Script: - - Luxuries handled via Special Case - -
[4217.206] Map Script: Luxury type 18
[4217.206] Map Script: -
[4217.206] Map Script: - - Disabled - -
[4217.206] Map Script: Luxury type 15
[4217.206] Map Script: Luxury type 14
[4217.206] Map Script: Luxury type 24
[4217.206] Map Script: Luxury type 20
[4217.206] Map Script: Luxury type 22
[4217.206] Map Script: Luxury type 16
[4217.206] Map Script: Luxury type 17
[4217.206] Map Script: Luxury type 32
[4217.206] Map Script: Luxury type 30
[4217.206] Map Script: Luxury type 26
[4217.206] Map Script: - - - - - - - - - - - - - - - -
[4217.206] Map Script: Map Generation - Placing City States
[4217.206] Map Script: Map Generation - Choosing sites for City States
[4217.206] Map Script: All city states assigned.
[4217.206] Map Script: Map Generation - Placing Luxuries
[4217.206] Map Script: -
[4217.206] Map Script: Attempting to place Luxury# 31 at start plot 3 3 in Region# 1
[4217.206] Map Script: -
[4217.206] Map Script: Attempting to place Luxury# 21 at start plot 19 12 in Region# 2
[4217.206] Map Script: -
[4217.206] Map Script: -
[4217.206] Map Script: -Assigned Luxury Type 27 to City State# 1
[4217.206] Map Script: -
[4217.206] Map Script: -
[4217.206] Map Script: -Assigned Luxury Type 21 to City State# 2
[4217.206] Map Script: -
[4217.206] Map Script: -
[4217.206] Map Script: -Assigned Luxury Type 23 to City State# 4
[4217.206] Map Script: -
[4217.206] Map Script: - - -
[4217.206] Map Script: Attempting to place regional luxury # 31 in Region# 1
[4217.206] Map Script: -
[4217.206] Map Script: - - -
[4217.206] Map Script: Attempting to place regional luxury # 21 in Region# 2
[4217.206] Map Script: * *
[4217.206] Map Script: * iNumTypesRandom = 4
[4217.206] Map Script: * *
[4217.221] Map Script: -
[4217.221] Map Script: --- Eligible Types List for Second Luxury in Region# 1 ---
[4217.221] Map Script: --- End of Eligible Types list for Second Luxury in Region# 1 ---
[4217.221] Map Script: -
[4217.221] Map Script: Placed Second Luxury type of ID# 23 for start located at Plot 3 3 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: --- Eligible Types List for Second Luxury in Region# 2 ---
[4217.221] Map Script: --- End of Eligible Types list for Second Luxury in Region# 2 ---
[4217.221] Map Script: -
[4217.221] Map Script: Placed Second Luxury type of ID# 23 for start located at Plot 19 12 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 0 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 0
[4217.221] Map Script: Found indices of 4 5 10 14
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 1 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 1
[4217.221] Map Script: Found indices of 12 11 4 13
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 2 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 2
[4217.221] Map Script: Found indices of 4 5 2 9
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 3 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 3
[4217.221] Map Script: Found indices of 10 2 14 15
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 4 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 4
[4217.221] Map Script: Found indices of 4 5 14 10
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 5 in Region# 1
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 5
[4217.221] Map Script: Found indices of 8 2 14 10
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 0 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 0
[4217.221] Map Script: Found indices of 4 5 10 14
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 1 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 1
[4217.221] Map Script: Found indices of 12 11 4 13
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 2 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 2
[4217.221] Map Script: Found indices of 4 5 2 9
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 3 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 3
[4217.221] Map Script: Found indices of 10 2 14 15
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 4 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 4
[4217.221] Map Script: Found indices of 4 5 14 10
[4217.221] Map Script: -
[4217.221] Map Script: - - -
[4217.221] Map Script: Attempting to place strategic resource # 5 in Region# 2
[4217.221] Map Script: -
[4217.221] Map Script: Obtaining indices for Strategic# 5
[4217.221] Map Script: Found indices of 8 2 14 10
[4217.221] Map Script: Map Generation - Placing Bonuses
[4217.221] Map Script: Map Generation - Normalize City State Locations
[4217.221] Map Script: -
[4217.221] Map Script: --- Table of Results, New Start Finder ---
[4217.221] Map Script: -
[4217.221] Map Script: Region# 1 has start plot at: 3 3 with Fertility Rating of 253
[4217.221] Map Script: -
[4217.221] Map Script: Region# 2 has start plot at: 19 12 with Fertility Rating of 256
[4217.221] Map Script: -
[4217.221] Map Script: --- End of Start Finder Results Table ---
[4217.221] Map Script: -
[4217.221] Map Script: -
[4217.221] Map Script: --- Table of Final Results, City State Placements ---
[4217.221] Map Script: -
[4217.221] Map Script: - City State 1 in Region 1 is located at Plot 10 1
[4217.221] Map Script: - City State 2 in Region 2 is located at Plot 13 14
[4217.221] Map Script: - City State 3 in Region 1 is located at Plot 7 13
[4217.221] Map Script: - City State 4 in Region 2 is located at Plot 16 2
[4217.221] Map Script: -
[4217.221] Map Script: - - - - -
[4217.221] Map Script: -
[4217.221] Map Script: --- Table of Final Results, Resource Distribution ---
[4217.221] Map Script: -
[4217.221] Map Script: - LUXURY Resources -
[4217.221] Map Script: - Whale...: 0
[4217.221] Map Script: - Pearls..: 0
[4217.221] Map Script: - Gold....: 0
[4217.221] Map Script: - Silver..: 0
[4217.221] Map Script: - Gems....: 0
[4217.221] Map Script: - Marble..: 2
[4217.221] Map Script: - Ivory...: 2
[4217.221] Map Script: - Fur.....: 0
[4217.221] Map Script: - Dye.....: 5
[4217.221] Map Script: - Spices..: 0
[4217.221] Map Script: - Silk....: 6
[4217.221] Map Script: - Sugar...: 0
[4217.221] Map Script: - Cotton..: 0
[4217.221] Map Script: - Wine....: 0
[4217.221] Map Script: - Incense.: 1
[4217.221] Map Script: - Expansion LUXURY Resources -
[4217.221] Map Script: - Copper..: 0
[4217.221] Map Script: - Salt....: 4
[4217.221] Map Script: - Citrus..: 1
[4217.221] Map Script: - Truffles: 0
[4217.221] Map Script: - Crab....: 0
[4217.221] Map Script: -
[4217.221] Map Script: + TOTAL.Lux: 53
[4217.221] Map Script: -
[4217.221] Map Script: - STRATEGIC Resources -
[4217.221] Map Script: - Iron....: 28
[4217.221] Map Script: - Horse...: 20
[4217.221] Map Script: - Coal....: 20
[4217.221] Map Script: - Oil.....: 24
[4217.221] Map Script: - Aluminum: 22
[4217.221] Map Script: - Uranium.: 10
[4217.221] Map Script: -
[4217.221] Map Script: - BONUS Resources -
[4217.221] Map Script: - Cow.....: 0
[4217.221] Map Script: - Wheat...: 3
[4217.221] Map Script: - Sheep...: 4
[4217.221] Map Script: - Deer....: 42
[4217.221] Map Script: - Banana..: 0
[4217.221] Map Script: - Fish....: 0
[4217.221] Map Script: - Stone...: 6
[4217.221] Map Script: -
[4217.221] Map Script: -----------------------------------------------------
[4217.221] Map Script: -------------------------------
[4217.221] Map Script: Map Generation - Adding Goodies
[4217.221] Map Script: -------------------------------
[4217.221] Map Script: Determining continents for art purposes (MapGenerator.Lua)
[4218.407] CivilopediaScreen: SetSelectedCategory(12)
[4218.407] CivilopediaScreen: CivilopediaCategory[CategoryTerrain].DisplayList
[4218.423] CivilopediaScreen: SetSelectedCategory(1)
[4218.423] CivilopediaScreen: CivilopediaCategory[CategoryHomePage].DisplayList
[4218.610] Tutorial: Loaded Additional Tutorial checks - Assets\DLC\Expansion2\Tutorial\Lua\TutorialInclude_Expansion2.lua
[4218.610] Tutorial: Loaded Additional Tutorial checks - Assets\DLC\Expansion\Tutorial\lua\TutorialInclude_Expansion1.lua
[4218.984] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\DeclareWarPlunderTradeRoutePopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\DLC\Expansion2\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\NetworkKickedPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\CityPlotManagementPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCommandPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivEnterTerritoryPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\LiberateMinorPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ReturnCivilianPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\AnnexCityPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\BarbarianRansomPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmGiftPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCityTaskPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmPolicyBranchPopup.lua
[4218.984] GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivGoldPopup.lua
[4219.093] EconomicGeneralInfo: Total Units - 2
[4219.093] EconomicGeneralInfo: Maint Free Units - 0
[4219.093] EconomicGeneralInfo: Paid Units - 2
[4219.093] EconomicGeneralInfo: Total Units - 2
[4219.093] EconomicGeneralInfo: Maint Free Units - 0
[4219.093] EconomicGeneralInfo: Paid Units - 2
[4219.312] ChoosePantheonPopup: 152
[4219.312] ChoosePantheonPopup: 963
[4219.312] ChoosePantheonPopup: 1115
[4219.374] ChooseIdeologyPopup: 152
[4219.374] ChooseIdeologyPopup: 963
[4219.374] ChooseIdeologyPopup: 1115
[4219.639] AdvisorInfoPopup: Closing Advisor Info
[4219.639] Demographics: Dequeuing demographics
[4219.639] Demographics: Dequeuing demographics


Still, no hello world. But one step closer :)
 
I think you may have missed Nutty's earlier comment about making your lua file an InGameUIAddin within ModBuddy. See whoward69's what ModBuddy setting for what file types tutorial. Without an entry for your lua file in the "Content" tab of the Mod's Properties (within ModBuddy), the game won't have any instructions on what to do with your lua file.

Since your lua file doesn't fit any of the other lua categories (such as a Map Script or a Diplomacy Screen Add-in), and the file is not referenced inside of another lua file via an include("YourFileName.lua") command, you need the InGameUIAddin method of activating your lua file.

------------------------------------------------------------------------------------------------
Also, this would work as a hidden building you can reference within your lua. As coded, it is using the <MilitaryProductionModifier>15</MilitaryProductionModifier> and would therefore increase production of all military units, regardless of domain: land, sea, air. Also as written it would only work for BNW. If you have G&K or Vanilla it would have to be coded differently, and would be best done as a non-hidden building. It is possible to hide buildings in G&K (and I think Vanilla) but it is much much harder to do.

Code:
<GameData>
	<Buildings>
		<Row>
			<Type>BUILDING_MIL_PROD_MODIFIER</Type>
			<BuildingClass>BUILDINGCLASS_MIL_PROD_MODIFIER</BuildingClass>
			<Cost>-1</Cost>
			<FaithCost>-1</FaithCost>
			<PrereqTech>NULL</PrereqTech>
			<GreatWorkCount>-1</GreatWorkCount>
			<ArtDefineTag>NONE</ArtDefineTag>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>-1</HurryCostModifier>
			<IconAtlas>BW_ATLAS_1</IconAtlas>
			<PortraitIndex>19</PortraitIndex>
			<Description>TXT_KEY_MIL_PROD_MODIFIER</Description>
			<NukeImmune>true</NukeImmune>
			[COLOR="Blue"]<MilitaryProductionModifier>15</MilitaryProductionModifier>[/COLOR]
		</Row>
	</Buildings>

	<BuildingClasses>
		<Row>
			<Type>BUILDINGCLASS_MIL_PROD_MODIFIER</Type>
			<DefaultBuilding>BUILDING_MIL_PROD_MODIFIER</DefaultBuilding>
			<Description>TXT_KEY_MIL_PROD_MODIFIER</Description>
		</Row>
	</BuildingClasses>

	<Language_en_US>
		<Row Tag="TXT_KEY_MIL_PROD_MODIFIER">
			<Text>Mil Prod Modifier</Text>
		</Row>
	</Language_en_US>
</GameData>
I highlighted the production modifier command so it would be a little easier to see. You would want to throw the entire code into an XML file, and activate it in the normal way with an OnModActivated > UpdateDatabase > Filename.XML in the Actions tab within ModBuddy.
 
I think I did including it in the content tab, I included a screenshot of my content tab in post #8 in this thread. I might have screwed something up there since I had to type the file name manualy (drop down menu only reconised .xml files, no the .lua)
 
I think I did including it in the content tab, I included a screenshot of my content tab in post #8 in this thread. I might have screwed something up there since I had to type the file name manualy (drop down menu only reconised .xml files, no the .lua)
hmmm...look for typos between the name of the file as it is shown in the Solution Explorer View and as you typed it in under the Content tab. Also look for typos in the file extension (ie, you could have typed ".lau" instead of ".lua")

[edit] I looked at your screenshot and I don't see anything that looks wrong there, but it's fuzzy enough I can't make out whether there are or are not any typos in the name of the file as you entered it. You might just want to redo your Content add-in, using the method I mentioned below. (By this I mean delete the one you have and re-do it using my hint method of selecting the file before any of the other stuff)

Hint for future use: When using the Content Tab, select the File from the drop-down list 1st, before selecting the Type, or entering the info for Name and Description. Lua files will show in the drop-down list if you do it this way.
 
Allright ! it worked. I deleted the lua file and made a new one, then put it in the content tab like you suggested. Got hello world in the log now.

I hope I can trial and error my way into some lua scripting from here :). Thanks to everyone for replying and dealing with these noobie questions and mistakes ^^.
 
Allright, I did some lua stuff now. Looped trough players and cities, printing in log every step. Also ran the AtWarWithAnyMajor function posted by Nutty. All working fine.

My issue now is, how do I go about the hidden building that gives production to military units? I think I get the XML part from LeeS, but that is just to define the hidden building right ? not put it in any cities or so (or am I totaly wrong xD ?).

If my assumption is right I still have to "put" the building in my cities when I'm at war, and take it away when I'm not. Or maby always have the building in all my cities, but edit the production from 0 to 15 when at war? I'm not sure how to go about this. Ive been looking in the lua reference on the modiki. But haven't found functions to add or remove buildings.
 
(re-edited to make my response a little more clear, I hope)
Allright, I did some lua stuff now. Looped trough players and cities, printing in log every step. Also ran the AtWarWithAnyMajor function posted by Nutty. All working fine.

My issue now is, how do I go about the hidden building that gives production to military units? I think I get the XML part from LeeS, but that is just to define the hidden building right ? not put it in any cities or so (or am I totaly wrong xD ?).
Yup. All that XML code does is define the building for use later in the lua.
If my assumption is right I still have to "put" the building in my cities when I'm at war, and take it away when I'm not...Ive been looking in the lua reference on the modiki. But haven't found functions to add or remove buildings.
Code:
pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 1)
will add the building in "pCity".
Code:
pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 0)
will remove the building in "pCity".

So you could add an if ___ then block such as:
Code:
for pCity in pPlayer:Cities() do
	if AtWarWithAnyMajor(iTeam) then
		pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 1)
	else pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 0)
	end
end
You could also do something like the following, if you've already 'grabbed' and stored the war status you got from AtWarWithAnyMajor(iTeam) and have it stored in a variable (differences highlighted in blue):
Code:
[COLOR="Blue"]local bAtWarIsTrue = AtWarWithAnyMajor(iTeam)[/COLOR]
for pCity in pPlayer:Cities() do
	if [COLOR="Blue"]bAtWarIsTrue[/COLOR] then
		pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 1)
	else pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 0)
	end
end
Or maby always have the building in all my cities, but edit the production from 0 to 15 when at war? I'm not sure how to go about this.
  • This part of your question(s) really isn't (a) possible in any workable method I can think of, (b) something you want to spend any time chasing after. Just use the lua method shown above, or something like it.
  • Just adding this final note for future posterity of the forum. I learned a lot by reading old threads when I first started modding, and a lot of what I learned came from very often nearly throw-away comments such as: Oh, by the way Bob, did you do XYZ in your code*. So I don't want anyone reading this thread in future to misunderstand my post.

* and 90% of those seemed to be BTW mentions made by W. Howard. :)
 
Thx LeeS!

That was exactly what I was looking for. I did see that function when looking at the modiki, just didnt figure out it was the one I needed :)
 
Code:
local bAtWarIsTrue = AtWarWithAnyMajor(iTeam)
for pCity in pPlayer:Cities() do
  if bAtWarIsTrue then
    pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 1)
  else
    pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_MIL_PROD_MODIFIER, 0)
  end
end

* and 90% of those seemed to be BTW mentions made by W. Howard. :)

I'll add another one then ;)

The condition inside the loop is invariant (that is, it doesn't depend on what the value of the loop variable - pCity in this case - is). So you can evaluate it once outside the loop and use another stored value within the loop. Won't save you much in execution time unless you have a large number of cities, but the general practice is a good one to follow. We can also do the same for the table lookup (GameInfoTypes.BUILDING_MIL_PROD_MODIFIER)

Code:
local iBuildingType = GameInfoTypes.BUILDING_MIL_PROD_MODIFIER
local bAtWarIsTrue = AtWarWithAnyMajor(iTeam)
local iBuildingsNeeded = 0
if bAtWarIsTrue then
  iBuildingsNeeded = 1
end

for pCity in pPlayer:Cities() do
  pCity:SetNumRealBuilding(iBuildingType, iBuildingsNeeded)
end

and you can then omit bAtWarIsTrue

Code:
local iBuildingsNeeded = 0
if AtWarWithAnyMajor(iTeam) then
  iBuildingsNeeded = 1
end

and for really brief code

Code:
local iBuildingsNeeded = AtWarWithAnyMajor(iTeam) and 1 or 0
 
Top Bottom