Sid Meier's Civilization V

Sid Meier's Civilization V

Not enough ratings
Building Created Event [snippet for mod makers]
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
4.180 KB
26 Jun, 2014 @ 6:08pm
30 Aug, 2014 @ 5:12pm
4 Change Notes ( view )

Subscribe to download
Building Created Event [snippet for mod makers]

In 1 collection by Machiavelli
Machiavelli's snippets for mod makers
6 items
Description
For mod makers.

What it does
This mod contains code that defines a lua event that fires off when a building is created. The event does not fire for buildings with 0 or less hammer cost unless they have a faithCost greater than zero and are enabledByBelief. The lua event provides the information you need to get the city object and the buildingclass.

If an end-user is playing with multiple mods that use this snippet it will work properly.

Compatibility
This code is compatible with Vanilla, Gods & Kings and Brave New World.

How to incorporate into your mod
The building created event will only work correctly if you are also using the unit created event snippet. A copy of the unit created event code is included in this mod.

Copy the "unit created" directory and all its contents to your mod. Have the XML file update the database (via the Action tab) and set the LUA file as an "InGameUIAddin" (via the Content tab).

Copy the "building created" directory and all its contents to your mod. Have the XML and SQL files update the database (via the Action tab) and set the LUA file as an "InGameUIAddin" (via the Content tab).

How to use
Add your functions to the "LuaEvents.BuildingCreatedEvent" event.

How it works
This code creates a new unit class for every building class. These units are named "UNIT_BCE_BUILDINGCLASS_TEMPLE", "UNIT_BCE_BUILDINGCLASS_MONUMENT" etc (BCE = Building Created Event). It then has every building provide 1 free copy of the unit class for it. The unit created snippet is used to detect when a "buildingClass" unit is created and immediately delete the unit and fire off the event.

The end user should never ever see a "buildingClass" unit. They serve no purpose other than to be detected and deleted immediately.

CivFanatics Download[forums.civfanatics.com]
5 Comments
UncivilizedGuy 5 Sep, 2014 @ 5:05pm 
Thanks for responding. Makes more sense now.
Machiavelli  [author] 5 Sep, 2014 @ 4:56am 
Say you want to give a civilization you are creating the trait "+1 Population when a city builds a National or World Wonder." You can write some code that hooks into this event and tests if the created building was a Wonder, if so, give the city +1 Pop.
UncivilizedGuy 4 Sep, 2014 @ 9:05pm 
Could you possiblly give me a scenario of where and when I would use this code? I've read your description a few times but I'm still not clear.
Machiavelli  [author] 30 Aug, 2014 @ 8:47am 
Just as an fyi, I plan on releasing a small update for this snippet at some point this weekend. The update includes giving the "blank building units" a base movement so end users can manually delete them (as a fail safe if for some reason they aren't deleted automatically) and adding some code that be default will do nothing but end users can enable. The code would be something that look each turn for "blank building units" and deletes them. The optional code would be something users could enable as a fail safe if the units aren't deleted automatically.
ultima9 30 Aug, 2014 @ 2:30am 
Interesting. Thanks for sharing!