1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Generate unit on city growth/Choose where the pop goes

Discussion in 'Civ5 - SDK / LUA' started by Gurra09, Jun 3, 2015.

  1. Gurra09

    Gurra09 First Consul

    Joined:
    Jan 1, 2008
    Messages:
    1,284
    Hi!

    I'm working out a concept for a new civ with a somewhat nomadic UA in mind which would need LUA coding and I'm not very familiar with it so hence this thread.

    The basic idea is that when a city of said civ grows, instead of adding a pop a unit is born in that city.

    How would I do something like that?

    The unit would be a specific unit, I'm planning to base the civ's UA on whoward's Units - Population mod (which adds a Population unit that spawns when cities are razed and have the opportunity to either join a city as a pop or settle a new city). With this civ, they would gain one of those when a city grows and the player gets to choose whether to add it to the city or use it to build a new one.

    I guess the way this would go about is that when the city grows, the game detects the growth, spawn a Population unit in said city, and decreases the city's population back one step. But as I said I'm not very familiar with LUA.
     
  2. Lynxbrutal

    Lynxbrutal Chieftain

    Joined:
    May 19, 2015
    Messages:
    17
    The city growth code I believe is all in C++ (CvCity.cpp and CvCity.h). I'm actually working on a similar change for my mod, except the cultural border growth gives you a unit instead of growing.

    Hopefully somebody here knows.
     
  3. Machiavelli24

    Machiavelli24 Mod creator

    Joined:
    May 9, 2012
    Messages:
    818
    You can detect when a city changes population by using the event:

    Code:
    Events.SerialEventCityPopulationChanged(hexX, hexY, population, citySize)
    While most Events (rather than GameEvents) are not recommended for use, this one actually works back when I tested it years ago. It fires for ai cities and cities the human can't see.

    However, if most of the time people are just going to be plopping that population back into the city it would probably be less busy work for them (and less likely to mess up the AI) if instead of giving them a unit each time a city grew you made a unique unit that subtracts a population when built.
     

Share This Page