Creating units on building production

Pokelover317

Chieftain
Joined
Feb 6, 2024
Messages
1
I've been trying to make a Civ designed for rapid expansion, and I thought maybe making settlers spawn after a certain building is completed (Colosseum, might nerf it by making it a later one), but I can't seem to get anything working with my puny coding knowledge, even the things found in these threads, so I thought I'd ask myself. Any help would be greatly appreciated!
 
Or Google search "Civ V Lua Reference"
This website is very helpful. Look under GameEvents, and you will find all the event hooks you need. These are all the objects, methods and events available for you to use.

You need to detect when a building is completed in a city. You will notice the event hooks you need is not present in the game.

Or Google "DLL - Various Mod Components"
This is a modded dll by whoward69, of civ modding fame. This fills in the many, many gaps left by the games developers. I've been modding this game for about a year, I refer to this mod more than the base game's resources.

If you look in the City.cpp file, and use Ctrl F to search for "GAMEEVENTINVOKE_HOOK", you will find all the added event hooks related to cities. One of them is "CityConstructed". This is the one you need.

Install this mod and configure the custommodoptions file to activate what features you need, then you will be able to detect when a building is built and then spawn any unit you like.

DLL mods do make it more obnoxious for you to do multiplayer with your mods, but it is still possible.

Do you know how to write the Lua code yourself and how to use event hooks?
 
Alternatively, now that I realize it, the Pyramids spawn units when you build them, as does Borobudur. You can use xml alone to make a unique building for your new civilization, and make it such that when you build that building, a unit spawns
 
Top Bottom