Great Person spawn rate manipulation

EricNgui

CPU of 1980's Planeptune
Joined
Jul 23, 2014
Messages
138
Location
Liverpool, UK
Ok, i have made a new LUA file that make my civ trait is:Military structures within a city increases the spawn rate of Great Scientist and Engineer. Here it is:
Spoiler :
function GetJapaneseGreatPeopleRateChange(city)
local greatPeopleRateChange = 0
if city:IsHasBuilding(GameInfoTypes["BUILDING_BARRACKS"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

if city:IsHasBuilding(GameInfoTypes["BUILDING_ARMORY"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

if city:IsHasBuilding(GameInfoTypes["BUILDING_MILITARY_ACADEMY"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

return greatPeopleRateChange
end

function JapaneseGreatScientist(playerID)
local player = Players[playerID]
if player:IsAlive() and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MAHOUKA"] then
for city in player:Cities() do
local greatPeopleRateChange = GetJapaneseGreatPeopleRateChange(city)
if greatPeopleRateChange > 0 then
local currentScientistRate = city:GetGreatPeopleUnitProgress(GameInfoTypes["SPECIALIST_SCIENTIST"])
local currentScientistRate = city:GetGreatPeopleUnitProgress(GameInfoTypes["SPECIALIST_ENGINEER"])
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_SCIENTIST"], currentScientistRate * greatPeopleRateChange / 100)
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_ENGINEER"], currentScientistRate * greatPeopleRateChange / 100)
end
end
end
end
GameEvents.PlayerDoTurn.Add(DefensiveGSESpawn)


Is this right?:confused:
 
Ok, i have made a new LUA file that make my civ trait is:Military structures within a city increases the spawn rate of Great Scientist and Engineer. Here it is:
Spoiler :
function GetJapaneseGreatPeopleRateChange(city)
local greatPeopleRateChange = 0
if city:IsHasBuilding(GameInfoTypes["BUILDING_BARRACKS"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

if city:IsHasBuilding(GameInfoTypes["BUILDING_ARMORY"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

if city:IsHasBuilding(GameInfoTypes["BUILDING_MILITARY_ACADEMY"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

return greatPeopleRateChange
end

function JapaneseGreatScientist(playerID)
local player = Players[playerID]
if player:IsAlive() and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MAHOUKA"] then
for city in player:Cities() do
local greatPeopleRateChange = GetJapaneseGreatPeopleRateChange(city)
if greatPeopleRateChange > 0 then
local currentScientistRate = city:GetGreatPeopleUnitProgress(GameInfoTypes["SPECIALIST_SCIENTIST"])
local currentScientistRate = city:GetGreatPeopleUnitProgress(GameInfoTypes["SPECIALIST_ENGINEER"])
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_SCIENTIST"], currentScientistRate * greatPeopleRateChange / 100)
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_ENGINEER"], currentScientistRate * greatPeopleRateChange / 100)
end
end
end
end
GameEvents.PlayerDoTurn.Add(DefensiveGSESpawn)


Is this right?:confused:
Highlighted function names are not the same, so you'd be asking the lua to run a function every turn that is not defined elsewhere in your lua. Not sure about the rest.
 
Ok, but i have problem here. I try to make the highlighted function same but each time i get runtime error like this:
Spoiler :
[220469.406] Runtime Error: C:\Users\user\Documents\My Games\Sid Meier's Civilization 5\MODS\mahouka cc (v 1)\DefensiveGSESpawn.lua:28: attempt to call method 'GetGreatPeopleUnitProgress' (a nil value)
 
Ok, i have made a new LUA file that make my civ trait is:Military structures within a city increases the spawn rate of Great Scientist and Engineer. Here it is:
Spoiler :
function GetJapaneseGreatPeopleRateChange(city)
local greatPeopleRateChange = 0
if city:IsHasBuilding(GameInfoTypes["BUILDING_BARRACKS"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

if city:IsHasBuilding(GameInfoTypes["BUILDING_ARMORY"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

if city:IsHasBuilding(GameInfoTypes["BUILDING_MILITARY_ACADEMY"]) then
greatPeopleRateChange = greatPeopleRateChange + 30
end

return greatPeopleRateChange
end

function JapaneseGreatScientist(playerID)
local player = Players[playerID]
if player:IsAlive() and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_MAHOUKA"] then
for city in player:Cities() do
local greatPeopleRateChange = GetJapaneseGreatPeopleRateChange(city)
if greatPeopleRateChange > 0 then
local currentScientistRate = city:GetGreatPeopleUnitProgress(GameInfoTypes["SPECIALIST_SCIENTIST"])
local currentScientistRate = city:GetGreatPeopleUnitProgress(GameInfoTypes["SPECIALIST_ENGINEER"])
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_SCIENTIST"], currentScientistRate * greatPeopleRateChange / 100)
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_ENGINEER"], currentScientistRate * greatPeopleRateChange / 100)
end
end
end
end
GameEvents.PlayerDoTurn.Add(DefensiveGSESpawn)


Is this right?:confused:
OK, looking a little closer at your lua there a couple of things I missed.

(1) Note where I have quoted your code the Blue and Green highlight of the two lines with local currentScientistRate. You are creating the same local variable twice and assigning values to it, so only the second (the one for Engineers) will take effect.

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

(2) This is incorrect because it must reference a Unit and not a Specialist:
Code:
local [COLOR="Blue"]currentScientistRate[/COLOR] = city:GetGreatPeopleUnitProgress(GameInfoTypes["[COLOR="red"]SPECIALIST_SCIENTIST[/COLOR]"])
The Modwiki API reference states it must reference the Unit Type: (Since I have not experimented with these commands myself I must trust the accuracy of Modwiki, and so far I haven't really found anywhere it was dead wrong, though there are places where it is incomplete or vague).
int City:GetGreatPeopleUnitProgress(UnitType index)
This must correspond to the ID #'s in the <Units> table, so Specialist Types cannot be stated. I believe what you will need is:
Code:
local [COLOR="Blue"]currentScientistRate[/COLOR] = city:GetGreatPeopleUnitProgress(GameInfoTypes["[COLOR="blue"]UNIT_SCIENTIST[/COLOR]"])

and

local [COLOR="SeaGreen"]currentEngineerRate[/COLOR] = city:GetGreatPeopleUnitProgress(GameInfoTypes["[COLOR="SeaGreen"]UNIT_ENGINEER[/COLOR]"])
Plus you'll have to make the same sort of adjustments to these lines, and make each one reference the correct local variable with the value for the correct type of Great Person Progress:
Code:
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_SCIENTIST"], currentScientistRate * greatPeopleRateChange / 100)
city:ChangeSpecialistGreatPersonProgressTimes100(GameInfoTypes["SPECIALIST_ENGINEER"], currentScientistRate * greatPeopleRateChange / 100)
Sorry I didn't catch all that before.

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

Also, I struggle with those darn "Times100" commands every time I try to use them because it isn't always clear to me whether "100" = "1" or the other way around. In other words I struggle with whether inputting "1" will translate in-game to ".01" of a Great Person Progress Point or whether it will translate in-game to "100" Great Person Points. You may have to make additional mathematical adjustments to your city:ChangeSpecialistGreatPersonProgressTimes100 lines, and you may need to do a "math.floor" or "math.ceiling" on those lines to eliminate partial great people points.
 
Back
Top Bottom