Adding units upon reaching a new era question.

Joebles

Chieftain
Joined
Jun 9, 2014
Messages
62
So, I'm relatively new to the modding scene, but I've spent the past week or so delving the wiki, these forums, and picking apart other peoples' mods and the game's XML, Lua, and source code.

The current project I'm working on involves a Trait that grants you settlers when you reach the Classical and Renaissance eras, and I found some code (provided by whoward for Carloso in another thread I believe) that I thought I could adapt for what I was doing.

The code:
Spoiler :
local iMySpecialCiv = GameInfoTypes.CIVILIZATION_SPECIAL

Events.SerialEventEraChanged.Add(function(iEra, iPlayer)
local pPlayer = Players[iPlayer]

if ((pPlayer:GetCivilizationType() == iMySpecialCiv) and (iEra < 3)) then
pPlayer:AddFreeUnit(GameInfo.Units["UNIT_SETTLER"].ID, UNITAI_SETTLE)​
end​
end)


Well, after hitting my head against the wall for a couple hours tonight I thought I would just ask for help. I have a general knowledge of coding, but no knowledge of Lua specifically, and it's possible that I messed up the syntax somewhere. From what I can tell in Fire Tuner and the logs, the .lua file isn't even being run by the mod (and when I put print commands in to test, nothing shows up). I've imported the .lua file into the VFS, but maybe I needed to do something else? Any suggestions?
 
That definitely did the trick! Thanks so much.

Though, now the game crashes whenever I go past the medieval era... Not entirely sure why yet. Going to try and find out.

EDIT: Pretty sure I forgot to name my civ's spies. Pretty sure this causes the game to crash. Whooopsies.

EDIT 2: Yep, that was it. Everything works fine now!
 
Back
Top Bottom