Need help with settler mod

The_Elio

Chieftain
Joined
Aug 13, 2018
Messages
13
Hello all, I am needing some help from fellow modders in making a settler mod. I am making a settler than is available at colonialism that can travel further and see further. I also want it so when it settles a city, it starts with 3 population and a monument and a granary. I already have it so it can move further and see further, but I need help with the initial population and starting buildings. Does someone know the XML to go in the data file for the mod to make that happen? Any help with this would be appreciated. I linked the mod I am working on below. It is an edited form on a mod I found on here from a while ago. Thanks!
 

Attachments

  • Colonist-20180814T002903Z-001.zip
    109.9 KB · Views: 111
Last edited:
I think the only way is to use LUA code.

You can see my Portugal Mod latest version where I place a building in city when its built. For change Population you have city:ChangePopulation(3) function.

For some LUA basics check here: https://forums.civfanatics.com/threads/civ-6-modding-tools-basics.634429/#post-15173206
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So I am working off your Portugal mod to get the starting buildings and the city:ChangePopulation(3) function you provided, and the mod still loads with it, however it does not give the buildings or pop when I settle a city with the colonist. Can you take a look at the LUA file and see if something stands out as wrong?
 

Attachments

  • ColonistLua.zip
    783 bytes · Views: 137
did you added the lua file to modinfo?
I do have it in there, but it still is not changing anything. Does the lua look correct to you though? I feel like it's close but there may be something I am missing. I also attached the entire mod folder if you want to take a look. Thank you for your help by the way, I really want to get this working!
 

Attachments

  • Colonist.zip
    46.7 KB · Views: 119
I just tried that now but I don't see anything about my mod in the Lua.log file. I think it may be my modinfo file. I think I have the <File> tags and the <AddGameplayScripts> correct but it still starts me without the extra population.
 
Do prints and see logs, that can help.
So I think I may have found something in a log.
Loading Mod - D:/Documents/My Games/Sid Meier's Civilization VI/Mods/Colonist/Colonist.modinfo
[982596.368] Empty properties are not supported. Skipping.
[982597.269] Finished Discovery.
[982597.269] Discovery Summary:
[982597.269] Deleted 1 mods.
[982597.269] Discovered 1 mods.
[982597.269] New/Reloaded Mods:
[982597.370] fbc31d06-79a3-4f5b-9dae-cd98acb43277 (Colonist)
[982597.380] Discovering Mods took - 1237ms.
[982597.385] Verifying enabled mods can coexist.
[982597.403] Bootstrapping game content
[982597.403] Loading Vanilla DLL.
[982597.405] Building gameplay database.
[982597.585] Updating gameplay database with embedded GameCore data.
[982597.594] Updated gameplay database with GameCore data.
[982597.604] Initializing Vanilla DLL.
[982597.672] Instantiate GameCore UI Manager.
[982597.672] Saving a debug version of the gameplay database.
[982598.829] Successfully bootstrapped game content.
[982598.872] ERROR: Attempted to evaluate a path for a mod that doesn't actually contain that path.
[982598.873] ERROR: Attempted to evaluate a path for a mod that doesn't actually contain that path.
[982598.873] ERROR: Attempted to evaluate a path for a mod that doesn't actually contain that path.
[982598.874] ERROR: Attempted to evaluate a path for a mod that doesn't actually contain that path.
[982598.874] ERROR: Attempted to evaluate a path for a mod that doesn't actually contain that path.
[982598.875] ERROR: Attempted to evaluate a path for a mod that doesn't actually contain that path.


Do you know if this has something to do with it and if so how to fix it?
 
Your ColonistLua.lua file has fatal syntax errors. The "end" statements on these lines are neither needed nor allowed:
Code:
	PlaceBuildingInCityCenter(dCity, Monument) end
	PlaceBuildingInCityCenter(dCity, Granary) end
	PlaceBuildingInCityCenter(dCity, AncientWalls) end
The first of these will be interpretted as the "end" command for the function, and the others that follow will be parsed as errors.

An "end" command in lua always requires one of "function", "if", "for", "while" to match up with it.

The mod attached to post #6 also is not making the game do anything with the lua file. There is no in-game action associated with the file.
 
Okay so should I just remove the end statements from the 3 lines to fix that? Also how and where would I put that in game action to make the Lua run? Sorry if these are dumb questions but I'm pretty new to this.
 
Code:
local iStartPop = 15
function OnCityInit(iPlayer, iCity, iX, iY)	
	local dPlayer = Players[iPlayer]
	local dCity = dPlayer:GetCities():FindID(iCity)
	local playerConfig:table = PlayerConfigurations[iPlayer] 
	
	PlaceBuildingInCityCenter(dCity, Monument)
	PlaceBuildingInCityCenter(dCity, Granary)
	PlaceBuildingInCityCenter(dCity, AncientWalls)

	local iCurrentPop = dCity:GetPopulation()
	if iCurrentPop < iStartPop then
		dCity:ChangePopulation(iStartPop - iCurrentPop) --This is 15 just to test as I start in the modern era to test it quickly and want to make sure the starting pop is actually from the mod. It will be changed to 3 once it works.
	end
end

Events.CityInitialized.Add(OnCityInit);
You need to use an action type in the InGameActions of AddGameplayScripts and add the filename to the list of files for that action. And you still need the rest of the code that was in the Colonistlua file above the OnCityInit function.

Events.CityInitialized fires both on founding a city and when a city is captured or otherwise changes ownership. Hence the addition of the code to check what the current population is, and throwing the desired city population-level into a variable. However, there is still a possible issue in that the code will also create these effects for City-State cities. If you only want the effects to apply to Major Civilizations, then you would alter the code as follows:
Code:
local iStartPop = 15
function OnCityInit(iPlayer, iCity, iX, iY)	
	local dPlayer = Players[iPlayer]
	if dPlayer:IsMajor() then
		local dCity = dPlayer:GetCities():FindID(iCity)
		local playerConfig:table = PlayerConfigurations[iPlayer] 
	
		PlaceBuildingInCityCenter(dCity, Monument)
		PlaceBuildingInCityCenter(dCity, Granary)
		PlaceBuildingInCityCenter(dCity, AncientWalls)

		local iCurrentPop = dCity:GetPopulation()
		if iCurrentPop < iStartPop then
			dCity:ChangePopulation(iStartPop - iCurrentPop) --This is 15 just to test as I start in the modern era to test it quickly and want to make sure the starting pop is actually from the mod. It will be changed to 3 once it works.
		end
	end
end

Events.CityInitialized.Add(OnCityInit);
There is still a further issue in that Events.CityInitialized does not know whether or not the city was founded by a normal settler or by the new colonist unit. And by the time the event fires the colonist is essentially already removed from the game, and you won't be able to reliably figure out whether the city was founded by a settler or a colonist unit.
 
Thank you for that. I am thinking of having the colonist replace the settler, so late game it won't be a problem. Do you know is it possible to have this mod wait until the industrial era until to start?
 
So I just tried it with what you put there and it still is not changing the population. Here is the modinfo file, I think I still don't have it exactly right to work if you want to take a look.
 

Attachments

  • Colonist ModInfo.zip
    834 bytes · Views: 119
This is incorrect because you have <InGameActions> set-up as a sub-set of <Components>. They are equivalent to each other and cannot be contained within each other.
Code:
  <Components>
	<UpdateArt id="Art">
      <File>Colonist.dep</File>
    </UpdateArt>
    <UpdateDatabase id="Gameplay">
      <File>Colonist.xml</File>
	  <File>Colonist.sql</File>
    </UpdateDatabase>
	
	<InGameActions>
		<AddGameplayScripts>
			<File>ColonistLua.lua</File>
		</AddGameplayScripts>
	</InGameActions>
This is incorrect because it is Civ5 methodology rather than Civ6
Code:
	<EntryPoints>
		<EntryPoint type="InGameUIAddin" file="ColonistLua.lua">
		  <Name>Colonist_initial_pop</Name>
		  <Description>Starting Population</Description>
		</EntryPoint>
	</EntryPoints>
You need
Code:
  </Properties>
  
  <InGameActions>
	<UpdateArt id="Art">
		<File>Colonist.dep</File>
	</UpdateArt>
	<UpdateDatabase id="Gameplay">
		<File>Colonist.xml</File>
		<File>Colonist.sql</File>
	</UpdateDatabase>
	<AddGameplayScripts id="ColonistScript">
		<File>ColonistLua.lua</File>
	</AddGameplayScripts>
	<UpdateIcons id="Icons">
		<File>Colonist_Icons.xml</File>
	</UpdateIcons>
	<UpdateText id="Text">
		<File>Colonist_Text.xml</File>
	</UpdateText>
	<ImportFiles id="IconFileImport">
		<File>Art/Icons/colonist22.dds</File>
		<File>Art/Icons/colonist32.dds</File>
		<File>Art/Icons/colonist38.dds</File>
		<File>Art/Icons/colonist50.dds</File>
		<File>Art/Icons/colonist80.dds</File>
		<File>Art/Icons/colonist256.dds</File>
	</ImportFiles>
  </InGameActions>
  
  <Files>
I've snipped the properties and files sections from the example of what you need to fix because there don't look to be any obvious problems there.
 
Hey I have it working now to where when I settle a city it does start with the 3 pop and the buildings! However, it does this for every settle, even in the ancient era. Is it possible to limit this ability to the colonist unit or start it when the game hits the industrial era?
 
This is the issue I mentioned in the final paragraph of post #12. You won't be able to know whether the city was founded by a settler or a colonist via lua. You can however determine what era a given player is in.
Code:
local pPlayer = Players[iPlayer]
local iPlayerEra = pPlayer:GetEras():GetEra()
if (iPlayerEra >= GameInfo.Eras["ERA_INDUSTRIAL"].Index) then
   print("This player is in the Industrial or later era")
end
As I remember R&F uses slightly different "names" for the era tags, so you'd have to check in the game's R&F files that you are using the correct name for the Industrial Era for R&F.
 
Okay so I worked with it and I have it working without the code above to check if it is in a certain era, but not when I include that. What I did was I wrapped the if/else statement around the main functions and event. Is that the correct way to do that? Also I looked and I am pretty sure it is ERA_INDUSTRIAL as I originally had the mod work by using the following.

UPDATE StartEras SET StartingPopulationCapital = 10, StartingPopulationOtherCities = 3 WHERE EraType = 'ERA_INDUSTRIAL';

Can you look at the lua and see maybe why it stops working when I try including the if/else for the era statement? I really appreciate your help with this too, thank you.
 

Attachments

  • ColonistLua.zip
    758 bytes · Views: 115
You need it inside the OnCityInit function, and since you made your player object variable "dPlayer" you must have all references to this object variable match the name you gave the variable. So instead of attempting the wrap the functions within a conditional statement, you need as follows for that part of the file
Code:
function PlaceBuildingInCityCenter(pCity, iBuilding)
	local iCityPlotIndex = Map.GetPlot(pCity:GetX(), pCity:GetY()):GetIndex()
	if not pCity:GetBuildings():HasBuilding(iBuilding) then
		pCity:GetBuildQueue():CreateIncompleteBuilding(iBuilding, iCityPlotIndex, 100);
	else
		if pCity:GetBuildings():IsPillaged(iBuilding) then
			pCity:GetBuildings():SetPillaged(iBuilding, false)
		end
	end
end

local iStartPop = 3
function OnCityInit(iPlayer, iCity, iX, iY)	
	local dPlayer = Players[iPlayer]
	if dPlayer:IsMajor() then
		local iPlayerEra = dPlayer:GetEras():GetEra()
		if (iPlayerEra >= GameInfo.Eras["ERA_INDUSTRIAL"].Index) then
			local dCity = dPlayer:GetCities():FindID(iCity)
			local playerConfig:table = PlayerConfigurations[iPlayer] 
	
			PlaceBuildingInCityCenter(dCity, Monument)
			PlaceBuildingInCityCenter(dCity, Granary)
			PlaceBuildingInCityCenter(dCity, AncientWalls)

			local iCurrentPop = dCity:GetPopulation()
			if iCurrentPop > iStartPop then
				dCity:ChangePopulation(iStartPop - iCurrentPop)
			end
		end
	end
end
Events.CityInitialized.Add(OnCityInit);
 
tho i'm not sure why you would change this line from what I originally had:
Code:
if iCurrentPop > iStartPop then
Because it would reduce the population in captured cities upon their capture if the city had a population greater than 3.
 
Top Bottom