How to make a custom civ receive a free unit upon founding a pantheon?

Durkle

Chieftain
Joined
Jul 29, 2017
Messages
29
Location
Jerusalem
Hi everybody. First post here, and also my first time trying to make a custom civ. I've got a pretty good grasp on the xml side of things but trying to create a custom trait I'm finding to be pretty difficult. My trait says that the civ gets a free settler upon founding a pantheon, as well as whenever a great prophet is born. I went through some of the mods I had installed and found a similar ability from JFD's Nri Kingdom, where the Nri get a free Great Merchant upon founding a pantheon, and I modified it to be a Settler instead of a Great Merchant. This is the lua script:
Code:
--Chickasaw_PantheonFounded
local unitSettlerID    = GameInfoTypes["UNIT_SETTLER"]
function Chickasaw_PantheonFounded(playerID)
    local player = Players[playerID]
    if (not player:IsAlive()) then return end
    if (not HasTrait(player, traitChickasawID)) then return end
    local capital = player:GetCapitalCity()
    player:InitUnit(unitSettlerID, capital:GetX(), capital:GetY())
end
GameEvents.PantheonFounded.Add(Chickasaw_PantheonFounded)

Unfortunately, I can't figure out how to make this actually happen in game! If someone can tell me what I have to put in my xml files (or wherever) to make this function actually happen I would be really grateful.
 
You can check which entries/settings your lua (or xml files for that matter) file needs in this page by Whoward.
I can however see two problems in the code you copied. First of all, HasTrait(pPlayer,iTraitID) is not defined. It probably is defined in one of JFD's files, but not in yours.
Secondly, traitChickasawID is not defined in your code, so even if you copied HasTrait(..) from somewhere, you'd pass it a nil value which probably wouldn't mean good things. Add local traitChickasawID = GameInfoTypes.TRAIT_DURKLE_CHICKASAW_SOMETHING_SOMETHING at the top of the code (depending on how you defined it in the XML of course).
Checking for the CivilizationType rather than the Trait also works (and is easier to do if you just started out as it requires less code).

Here's an example using CivilizationType rather than the trait:
Code:
--Chickasaw_PantheonFounded
local unitSettlerID    = GameInfoTypes["UNIT_SETTLER"]
local iChickasaw = GameInfoTypes.CIVILIZATION_DURKLE_CHICKASAW --GameInfoTypes["CIVILIZATION_DURKLE_CHICKASAW"] is the same thing, just in a different format
function Chickasaw_PantheonFounded(playerID)
   local player = Players[playerID]
    if (not player:IsAlive()) then return end
    if (not (player:GetCivilizationType()==iChickasaw)) then return end
    local capital = player:GetCapitalCity()
    player:InitUnit(unitSettlerID, capital:GetX(), capital:GetY())
end
GameEvents.PantheonFounded.Add(Chickasaw_PantheonFounded)

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

You could also use Lua to do the second thing of your trait. The code will be very similar to what you already have, but rather than using PantheonFounded (which is a so-called Lua hook), you use Machiavelli's variant of SerialEventUnitCreated.

EDIT: You also posted in the wrong subforum. Use the main C&C subforum to post questions. This one is for tutorials (or other references) only
 
Wow it actually works perfectly this way, thanks! I hadn't considered using CivilizationType instead of the trait, but that makes it way easier.

Sorry for posting in the wrong subforum, I'll make sure to post in the right one next time.
 
Back
Top Bottom