I thought I might share the working final bit in case somebody needs similiar functionality.
It's a simple thing that basically just renames each born great person with a civilization-specific name. All it needs to function is Machiavelli's SerialEventCreatedGood, the names added in the table, a xml file that has the text strings and a sql file to add the CivilizationType column in the Unit_UniqueNames in case the user doesn't have LeeS's mod.
Thanks a bunch to everyone involved! It feels truly amazing to have something like this done, eventhough it's essentially a product of your labor, not mine. Either way, it's alive and working, and I can continue to next bits with a heart full of excitement.
Next thing I need to figure out is how to have era-specific UnitSelect and UnitOrder sounds. But that's probably going to be its own mod, so I think I'll just finish with this package, apply it to some civs and then see if it's doable for me. I'll probably keep bugging you guys, if you don't mind
EDIT: By the way, it's actually pretty neat it only took 3 days to complete it. The involvement from you, the community, is pretty damn amazing and quick! I've only been learning this for 5 days, so this whole thing is pretty unimaginable without this community being so awesome
EDIT2: Though I definitely suggest everyone to use LeeS's mod, it's way better and more complete with the table saving functionality from TSL. He's also made it very well-documented and added the functionality to also rename all the GP, not only GGs or GAs.
While we're at the subject of saving the table - I might want to see how to apply the SaveUtils here. I'm thinking it might be faster to save the GP names table and have it load it from there?
Spoiler :
Code:
-- UGPFunctions.lua
-- Author: Olritoim A.K.A OrgrinRT
-- DateCreated: 11/24/2016 9:42:58 PM
--------------------------------------------------------------
--------------------------------------------------------------
-- Big thanks to LeeS and Chrisy15 for doing the base for this and essentially making it work!
--------------------------------------------------------------
local iPromotionUnitBorn = GameInfoTypes["PROMOTION_CREATED"]
local civilizationID = GameInfoTypes["CIVILIZATION_FINNS"]
local tGreatPeopleClassesToProcess = {
[GameInfoTypes["UNITCLASS_SCIENTIST"]] = true,
[GameInfoTypes["UNITCLASS_ENGINEER"]] = true,
[GameInfoTypes["UNITCLASS_MERCHANT"]] = true,
[GameInfoTypes["UNITCLASS_ARTIST"]] = true,
[GameInfoTypes["UNITCLASS_WRITER"]] = true,
[GameInfoTypes["UNITCLASS_MUSICIAN"]] = true,
[GameInfoTypes["UNITCLASS_PROPHET"]] = true,
[GameInfoTypes["UNITCLASS_GREAT_GENERAL"]] = true,
[GameInfoTypes["UNITCLASS_GREAT_ADMIRAL"]] = true,
[GameInfoTypes["UNITCLASS_SCOUT"]] = true,
[GameInfoTypes["UNITCLASS_JFD_GREAT_SCOUT"]] = true,
[GameInfoTypes["UNITCLASS_JFD_ADVENTURER"]] = true,
[GameInfoTypes["UNITCLASS_JFD_GREAT_ADVENTURER"]] = true,
[GameInfoTypes["UNITCLASS_JFD_EXPLORER"]] = true,
[GameInfoTypes["UNITCLASS_JFD_GREAT_EXPLORER"]] = true,
[GameInfoTypes["UNITCLASS_JFD_GREAT_DIGNITARY"]] = true,
[GameInfoTypes["UNITCLASS_JFD_GREAT_MAGISTRATE"]] = true,
}
-- JFD_IsCivilisationActive
function JFD_IsCivilisationActive(civilisationID)
for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local slotStatus = PreGame.GetSlotStatus(iSlot)
if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
if PreGame.GetCivilization(iSlot) == civilisationID then
return true
end
end
end
return false
end
-- JFD_GetRandom
function JFD_GetRandom(lower, upper)
return Game.Rand((upper + 1) - lower, "") + lower
end
-- This bit is based on LeeS's sample code
function GetNameForGreatPerson(pUnit)
if pUnit ~= nil then
local sUnitType = GameInfo.Units[pUnit:GetUnitType()].Type
local playerID = pUnit:GetOwner()
local pPlayer = Players[playerID]
local tCorrectUnitNames = {}
for row in DB.Query("SELECT UnitType, UniqueName FROM Unit_UniqueNames WHERE UnitType = \'" .. sUnitType .. "\' AND CivilizationType = 'CIVILIZATION_FINNS'") do
table.insert(tCorrectUnitNames, row.UniqueName)
end
if #tCorrectUnitNames > 0 then
if #tCorrectUnitNames == 1 then
return tCorrectUnitNames[1]
else
return tCorrectUnitNames[JFD_GetRandom(1, #tCorrectUnitNames)]
end
end
end
return "Tuntematon Sotilas"
end
--This bit is based on Chrisy15's sample
function C15_GPBorn(playerID, unitID)
local pPlayer = Players[playerID]
if pPlayer:GetCivilizationType() == civilizationID then
local pUnit = pPlayer:GetUnitByID(unitID)
if pUnit then
if tGreatPeopleClassesToProcess[pUnit:GetUnitClassType()] then
local sSelectedName = GetNameForGreatPerson(pUnit)
if sSelectedName then -- If the civ has no entries, then this will be nil; we must check for this
pUnit:SetName(sSelectedName)
Events.UnitNameChanged(playerID, unitID)
end
end
end
end
end
--if JFD_IsCivilisationActive(civilizationID) then
LuaEvents.SerialEventUnitCreatedGood.Add(C15_GPBorn)
--end
It's a simple thing that basically just renames each born great person with a civilization-specific name. All it needs to function is Machiavelli's SerialEventCreatedGood, the names added in the table, a xml file that has the text strings and a sql file to add the CivilizationType column in the Unit_UniqueNames in case the user doesn't have LeeS's mod.
Thanks a bunch to everyone involved! It feels truly amazing to have something like this done, eventhough it's essentially a product of your labor, not mine. Either way, it's alive and working, and I can continue to next bits with a heart full of excitement.
Next thing I need to figure out is how to have era-specific UnitSelect and UnitOrder sounds. But that's probably going to be its own mod, so I think I'll just finish with this package, apply it to some civs and then see if it's doable for me. I'll probably keep bugging you guys, if you don't mind

EDIT: By the way, it's actually pretty neat it only took 3 days to complete it. The involvement from you, the community, is pretty damn amazing and quick! I've only been learning this for 5 days, so this whole thing is pretty unimaginable without this community being so awesome

EDIT2: Though I definitely suggest everyone to use LeeS's mod, it's way better and more complete with the table saving functionality from TSL. He's also made it very well-documented and added the functionality to also rename all the GP, not only GGs or GAs.
While we're at the subject of saving the table - I might want to see how to apply the SaveUtils here. I'm thinking it might be faster to save the GP names table and have it load it from there?
Last edited: