units by era prereq?

Yes. Give the building no prereq tech (like the Monument) and then limit when it can be built with Lua via the GameEvents.CityCanConstruct callback
 
I will have to find that and try to get it to work - my project has something to do with one building "tree" to be unlocked in each era.

Once i figure out how to set it, i will be half done XD

im still new to this, and there is a lot to learn in that first big step.
 
Im no lua modder but from a few reads this looks like the correct direction, but something inside my personal intuition tells me i am wrong.

Spoiler :

GameEvents.PlayerCanConstruct.Add(function(iPlayer, buildingTypeID)
local prereqEra = GameInfo.Buildings[buildingTypeID].PrereqEra
if prereqEra then
local player = Players[iPlayer]
local Era = GameInfo.Era[prereqEra].ID
if not player:HasEra(EraID) then
return false
end
end
return true
end)


I wish there were an XML way to make a building/era available by era and i can't find anything in the game that already makes references to "dependency on era" such as the splash screens for entering an era, or unlocking social policies by era. This should be the easiest thing in the world yet i can not set my Trade Fair building to unlock when entering the classical era...

Where in the files could i find an example to use, the only LUA files i have found are for map scripts...
 
if not player:HasEra(EraID) then

You're really close. I've done this before with GameEvents.PlayerCanTrain.Add()

Try
Code:
local playerEra = player:GetCurrentEra();
which gives you an integer:

0 = ERA_ANCIENT/undefined
1 = ERA_CLASSICAL
2 = ERA_MEDIEVAL
3 = ERA_RENAISSANCE
4 = ERA_INDUSTRIAL
5 = ERA_MODERN
6 = ERA_FUTURE

If you add your 'prereqEra's as integers, then you can do a
Code:
if playerEra >= prereqEra then
return false;
end

EDIT: ...and don't forget your semicolons.
 
EDIT: ...and don't forget your semicolons.

Or do, as unless you are placing two statements on one line they are nothing by syntactic sugar
 
ahh, so i can use > as a statement, to make Trade Fair available at one "classical era onwards" instead of making "have era 2, have era 3..."

thanks for the tip!
 
Spoiler :

GameEvents.PlayerCanConstruct.Add(function(iPlayer , buildingTypeID)
local prereqEra = GameInfo.Buildings[buildingTypeID].PrereqEra
local playerEra = player:GetCurrentEra();
if playerEra >= prereqEra then
return false;
end
end
return true
end)


Something along the lines of this? If so, the one thing i have left to do is look at some more XML to figure out how to reference it
 
ahh, so i can use > as a statement, to make Trade Fair available at one "classical era onwards" instead of making "have era 2, have era 3..."

Yes, but you shouldn't do it as "currentEra >= 1", but should be "currentEra >= GameInfoTypes.ERA_CLASSICAL". That way, if someone makes a mod adding an era BEFORE the Ancient, renumbering all of the existing eras upwards by 1, then it'll still work correctly. The only problem you'll run into is if they remove the Classical Era entirely, and honestly, if someone's doing something like THAT, then a whole lot of things are going to break.

Side note: GameInfoTypes.ERA_CLASSICAL can also be written as GameInfo.Eras["ERA_CLASSICAL"].ID, but it's obviously more convenient to do it the way I showed.
 
Back
Top Bottom