Gleb Bazov
Warlord
- Joined
- Feb 13, 2017
- Messages
- 176
Following on a recent thread about a creating a civilization trait granting a great persons upon construction of a district (after a specific technology is researched), I tried and ultimately gave up coding this in XML. The Modifier available in XML (MODIFIER_SINGLE_CITY_GRANT_GREAT_PERSON_CLASS_IN_CITY) is tied to COLLECTION_OWNER and there just isn't a way that I can see to tie all the necessary conditions (Civilization Type, District, Technology, etc.). This is particularly annoying because I can see that there is a Requirement (REQUIREMENT_CIV_TYPE_MATCHES) that would tie all this together by making it a District Modifier instead of a Trait, but this requirement is not used anywhere in the base game, and I can't figure out a way to use it with CivilizationTypes (I suspect it refers to the Major/Minor/Barbarian distinction instead). Anyways, long story short, I went the other way and coded the above process in LUA. It works and works well, apart from the following:
(1) I can't find a way to generate GreatPersonIndividuals. All I get are generic generals/admirals/engineers/etc., obviously without any abilities. I suppose I could mod generic great person units to have some useful abilities, but that wasn't the task I intended to accomplish.
Using GameInfo.GreatPersonClasses["GREAT_PERSON_CLASS_GENERAL"].Index for unitType in Create (unitType, unitX, unitY) generates a settler instead (not unexpectedly, since the index value is 0 for both).
(2) This one is silly. Instead of getting one unit, I get two of the same kind. For some reason, the code loops on itself. Using the print function, I get two sets of outputs when the district is created.
Here is the code. I would appreciate any assistance you may provide! Thank you in advance.
Going a different way, is there a function to trigger a GameEffect in LUA? E.g. to trigger the effect underlying MODIFIER_SINGLE_CITY_GRANT_GREAT_PERSON_CLASS_IN_CITY through Lua?
EDIT: For completeness, I also tried the UnitManager.InitUnit(pPlayer, "UNIT_GREAT_GENERAL", uCity:GetX(), uCity:GetY()) method, and it works, but it suffers from the same two problems as the Create approach.
(1) I can't find a way to generate GreatPersonIndividuals. All I get are generic generals/admirals/engineers/etc., obviously without any abilities. I suppose I could mod generic great person units to have some useful abilities, but that wasn't the task I intended to accomplish.
Using GameInfo.GreatPersonClasses["GREAT_PERSON_CLASS_GENERAL"].Index for unitType in Create (unitType, unitX, unitY) generates a settler instead (not unexpectedly, since the index value is 0 for both).
(2) This one is silly. Instead of getting one unit, I get two of the same kind. For some reason, the code loops on itself. Using the print function, I get two sets of outputs when the district is created.
Here is the code. I would appreciate any assistance you may provide! Thank you in advance.
Code:
--====================================================================================================================
-- Function Generating a Great Person Upon Certain Conditions Being Satisfied
--====================================================================================================================
local sRequiredCiv = "CIVILIZATION_EGYPT"
local iUnitType = "UNIT_GREAT_GENERAL"
local iRequiredDistrict = "DISTRICT_ENCAMPMENT"
local pRequiredTech = "TECH_MINING"
function OnEncampmentCompleted( playerID, cityID, orderType, unitType, canceled, typeModifier )
if orderType == 2 and GameInfo.Districts[unitType].DistrictType == iRequiredDistrict then
print ("District Conditions Satisfied")
local pPlayer = Players[ playerID ]
local uCity = pPlayer:GetCities():FindID(cityID)
local pPlayerConfig = PlayerConfigurations[ playerID ]
local pPlayerCivName = pPlayerConfig:GetCivilizationTypeName()
if pPlayerCivName == sRequiredCiv then
print ("Civilization Type Conditions Satisfied")
local pPlayerTechs = pPlayer:GetTechs()
if pPlayerTechs:HasTech(GameInfo.Technologies[pRequiredTech].Index) then
print ("Tech Conditions Satisfied")
local pUnitType = GameInfo.Units[iUnitType].Index
pPlayer:GetUnits():Create(pUnitType, uCity:GetX(), uCity:GetY())
end
end
end
end
Events.CityProductionCompleted.Add(OnEncampmentCompleted);
Going a different way, is there a function to trigger a GameEffect in LUA? E.g. to trigger the effect underlying MODIFIER_SINGLE_CITY_GRANT_GREAT_PERSON_CLASS_IN_CITY through Lua?
EDIT: For completeness, I also tried the UnitManager.InitUnit(pPlayer, "UNIT_GREAT_GENERAL", uCity:GetX(), uCity:GetY()) method, and it works, but it suffers from the same two problems as the Create approach.
Last edited: