which events to add lua functions to?

70ny

Chieftain
Joined
Apr 3, 2011
Messages
9
trying to make a lua mod that affects empire happiness based on cities and population, which lua event is the lua function supposed to be added to? (asking this cuz i found a lua events list, but there is quite a lot of factors that can change happiness):

WonderStateChanged
SerialEventCityCreated
SerialEventCityPopulationChanged
SerialEventCityDestroyed
SerialEventImprovementCreated
SerialEventImprovementDestroyed
ActivePlayerTurnStart
ActivePlayerTurnEnd

most of mods i looked at that use lua dont usually add the function to more than 4 events

also, what does serial events mean in general? and whats with serialevent___dirty what does that mean.
 
trying to make a lua mod that affects empire happiness based on cities and population

First of all, you can't change Happiness through Lua, at least not directly. It may LOOK like you can, but the game re-derives each player's happiness at the end of their turn. So if you use SetHappiness to add 10 happiness to your empire, it'll automatically be removed before having any effect since it won't be counted in the rederivation. (You can tell because it won't change the Golden Age timer or affect whether you receive a negative-happiness penalty.) Other Lua functions, like ChangeHappinessFromBuildings, don't work at all.

You CAN get around this somewhat by creating a temporary building, for instance, and placing it in the city. That WOULD add to the city's actual happiness, but it has a few other issues. First and foremost being, you can't subtract happiness this way. If you give a negative Happiness value to a building, it does nothing. You can add a negative-happiness Policy, but this then screws up the culture costs of future policies, the branches needed for a cultural victory, and the player's score.

also, what does serial events mean in general?

"Serial" events are UI-oriented. The event will only trigger when the game NEEDS it to trigger for display purposes.
For instance, consider SerialEventImprovementCreated, which is what the game uses to draw an Improvement on the map. It has two states: 2, and 4. "2" means an incomplete improvement, the half-drawn version you see while a worker is building it. "4" means complete.
If you're building an improvement in your own territory then it'll work fine; it'll trigger the "2" event when you start building, and the "4" event when it finishes. (It'll also trigger when an Ancient Ruin or Barbarian Camp are seen, but those are easy to check for.) But if an AI on the other side of the world builds the improvement, the Serial Event will only trigger when you, the active player, first SEE the tile in question. This is nearly always a state 4 version, for obvious reasons. So if you have logic that's supposed to trigger when a certain type of improvement is created, this event just won't work correctly for the AI.

But it's not consistent for all serial events. SerialEventUnitCreated, for instance, WILL trigger even if the unit is somewhere you can't see it. However, it'll ALSO trigger when:
> A savegame is first loaded
> The unit embarks
> The unit DISembarks
> An air unit rebases (I think)
As you can guess, this makes it a bit of a headache to use for unit-creation events. I got around that in my mod by creating a new "Rookie" promotion that a unit has until after its first fight, so that it's now easy to tell whether it's the first time the event has triggered for a given unit. So it's not insurmountable.

In general, ActivePlayerStartTurn and ActivePlayerEndTurn are what you'll use for the vast majority of your Lua coding. Just remember the "Active Player" part, meaning YOU, the guy sitting at the keyboard; it'll trigger at the start and end of your turn, and not do the same for the AI turns, so anything you put in there should loop over all players so that everyone gets the same opportunity to trigger your logic.
(Also, this'd hose multiplayer, but that one's a lost cause at this point regardless.)
 
thanks for the fast response

...there goes my grand idea of a happiness balance mod :'( seems theres no easy way to mod happiness through lua

but then how did the modder here do unhappiness from bureaucracy?:
http://forums.civfanatics.com/showthread.php?t=399829

from what i saw in his code im guessing you have to completely rework happiness from the base to do it?...
 
but then how did the modder here do unhappiness from bureaucracy?

I can't read through his files right now, but the base unhappiness due to number of cities (2) and unhappiness per population (1.0) can be increased through a mod pretty easily. In my own mod it's 4+1.2/pop. It sounds like he's putting something on top of that, though.

I'm just saying that on-the-fly adjustment of happiness doesn't work correctly. Creating a specialist that adds happiness, creating a building that subtracts happiness, those sorts of things just don't work in the way you'd expect.

I'll look at his code later on, but it's also possible that it just doesn't do what he thinks it does, that it LOOKS like it's adding unhappiness but isn't actually having that effect in practice. I had this problem in my own mod for a while; I thought my negative-happiness buildings were working correctly, because the happiness total at the top of the screen was adjusting to the correct value, but it wasn't actually working correctly; you'd still gain golden age points at the correct rate and suffer the negative happiness penalties at the same rate as without those negatives.
 
This is good to hear (there might still be hope), my mod idea features extreme levels of city unhappiness that increases as the number of cities go up (exponential increase).

Since changing things like base city unhappiness is easy, is changing other base values like amount of social policy per city also easy? (trying to keep the policy cost increase per new city the same as unmodded, but cause the cost to decrease and even lower back to normal as if you had no additional cities as empire happiness increase past certain levels).

also, i cant seem to find the value for policy cost increase from number of cities anywhere in the xml, any ideas for that?
 
For events to attach to, it worth also looking at GameEvents, which are all about rules-oriented occasions and even let you modify some default behaviours, rather than just add to them. Sseckman added some official info to the wiki a week ago, and I'm hoping he'll add more. The stuff specific to each event is all fan-documented via either the tuner or the DLC scenarios. The official wiki has docs at http://wiki.2kgames.com/civ5/index.php/Lua_Game_Objects/GameEvents
 
Back
Top Bottom