Is there a way to lua code something to happen only when a Golden Age starts?

Galgus

Emperor
Joined
Aug 22, 2012
Messages
1,705
I've recently ventured into looking into lua code, and while I'm mostly confused and intimidated I've noticed that things dealing with starting Golden Ages tend to just set golden age turns.

I'm looking for a way of making something trigger when a Golden Age starts, I'd like to know what other lua code deals with :c5goldenage:'s, if this kind of thing is indeed possible.
 
Maybe with Player:GetGoldenAgeTurns?
Check if it's greater than 0.

I'm no Lua expert, though.


EDIT:
"When it starts". My bad.
Maybe then check if the GA turns is the maximum amount possible for that Civ (which would indicate it just started)?

Would there be a way to check for Chichen Itza with that?

Are there any other effects that change :c5goldenage: duration to worry about?

Edit: Since this is intended to be a UA and thus not apply to Persia, I don't need to worry about them.

Is there a way to check for game speed, since that affects :c5goldenage:'s?
 
There isn't a clean way to detect when a Golden Age starts*. The closest would be to test each turn to see if the player is in a Golden Age.

*Using a custom DLL could provide this, but that is probably outside the scope of your intended mod.
 
There isn't a clean way to detect when a Golden Age starts*. The closest would be to test each turn to see if the player is in a Golden Age.

*Using a custom DLL could provide this, but that is probably outside the scope of your intended mod.

So far the best way I see is the incredibly clunky method of checking for game speed, Chichen Itza, and the Freedom tenant that boosts :c5goldenage: length.

In the meantime, I don't know how to check for any of them, or to tie the whole thing to spawning a unit.

I suppose a cop-out solution would be to check if the :c5goldenage: has 1 turn left for a similar effect, but it wouldn't feel the same.
 
What are you trying to do? Because you can use player:GetGoldenAgeTurns() to see how many turns of a Golden Age a player has left rather than trying to calculate everything yourself.
 
What are you trying to do? Because you can use player:GetGoldenAgeTurns() to see how many turns of a Golden Age a player has left rather than trying to calculate everything yourself.

Ideally I'd like to detect when a :c5goldenage: starts and cause a unit to spawn then.

That is why I was trying to think of a way to detect what turn a :c5goldenage: starts on based on modifiers.
 
I would guess you would want to spawn the unit when a player who isn't in a Golden Age goes into one and when a player's Golden Age duration increases. (An example of the second case would be a player already in a Golden Age pops a Great Artist for more Golden Age turns).

You could achieve this, but it would not be clean (in the sense that the unit would not spawn when the golden age starts, but only at the start of their next turn). You would want to use the following algorithm:
  • Each turn you'll need to know two things: 1) the current duration of the player's golden age and 2) last turn's golden age duration.
  • If (current duration > 0 and current duration > previous duration - 1) then {give unit} end
  • Store/persist the current duration for use in next turn's test.
 
I would guess you would want to spawn the unit when a player who isn't in a Golden Age goes into one and when a player's Golden Age duration increases. (An example of the second case would be a player already in a Golden Age pops a Great Artist for more Golden Age turns).

You could achieve this, but it would not be clean (in the sense that the unit would not spawn when the golden age starts, but only at the start of their next turn). You would want to use the following algorithm:
  • Each turn you'll need to know two things: 1) the current duration of the player's golden age and 2) last turn's golden age duration.
  • If (current duration > 0 and current duration > previous duration - 1) then {give unit} end
  • Store/persist the current duration for use in next turn's test.

Thanks for the help, now I know what to try to do with it.

Start of next turn would be good enough, really.
 
Yes there is an event "GoldenAgeStarted", but it's not used by Firaxis so the parameters passed are unknown (likely to be player ID). To find out, take some time to test this:
Events.GoldenAgeStarted.Add( function(...) print(...) end );
it will print in lua.log (if enabled) the event parameters each time a golden age is triggered.
Cheers
 
Back
Top Bottom