Does anyone know how to make a unit that makes more units?

anansethespider

Warlord
Joined
Oct 27, 2016
Messages
288
I would like to create a unit "UNIT X" that is somehow able to create new copies of "UNIT Y", either one every turn at the beginning of turn, or through an activated ability, or really anything remotely similar. Does anyone have any ideas how this might be done?
 
its a long shot but the mongol camp did this from the civ4 scenario with python or maybe lua i can't remember.
 
It's doable with lua. It is one thing that's actually still pretty straightforward with civ6 available lua.

Not sure whether the modifiers system would handle something like that, but I doubt. I think the issue would be the repeats.

I might be able to look at the exact code specifics needed tomorrow or Saturday (I've already got a Really Advanced Start "Lite" mod I made for easing mod testing that creates units). If done entirely through lua on an automatic EveryX do Y basis, I would need specifics. Once every X turns, once every turn, one new unit Y for every unit X every turn, or whatever. And as you stated in the OP you'd want Unit_X to create Unit_Y, but never additional copies of Unit_X, because this might cause infinite unit spam.
 
Exactly. Let's just make it trigger at the beginning of every turn if you think that's possible. For every Unit X, spawn a Unit Y right next to it (if possible).
 
Could you fake it with an ability that places an improvement that spawns the unit? Barbarian Camps are technically improvements and in theory you could make them placeable.
 
Could you fake it with an ability that places an improvement that spawns the unit? Barbarian Camps are technically improvements and in theory you could make them placeable.

Making it spawn each turn from something static like a city or district would be easier, but wouldn't accomplish the same goal of having a unit that did so. I appreciate the thinking outside the box, and it's a good alternate road to go down...but my intuition is that would only work for something static.
 
Attached mod.

Everything is done through the lua file. It is only set up to handle one unit creating another unit, not multiple sets of unit-spawnings.

  1. Unzip the attached mod and copy/paste the entire folder called "LUA" into your mod
  2. alter your mod's modinfo file to include the following:
    Code:
     	<Files>
    		<File>LUA/Unit_Duplication.lua</File>
    	</Files>
    	<Components>
    		<GameplayScripts id="UnitDuplication_LUA">
    			<Items>
    				<File>LUA/Unit_Duplication.lua</File>
    			</Items>
    		</GameplayScripts>
    	</Components>
  3. In notepad or some other text editor program open the file called Unit_Duplication.lua
  4. At the top of this file where it says:
    Code:
    local iOriginalUnit = GameInfo.Units["UNIT_WARRIOR"].Index
    local iNewUnit = GameInfo.Units["UNIT_SCOUT"].Index
    local iTurnIncrement = 1
    Edit as necessary
    • local iOriginalUnit is where you designate the unit that will create other units. Just edit UNIT_WARRIOR to whichever unit you want to create other units. If I want to change it to the Missionary Unit, I would alter to:
      Code:
      local iOriginalUnit = GameInfo.Units["UNIT_MISSIONARY"].Index
    • local iNewUnit is where you specify the new unit that will be created. Do not make both "iNewUnit" and "iOriginalUnit" state the same unit-designation because this will probably cause infinite spamming of units that will fill the available map-space.
    • local iTurnIncrement is for designating how often a new unit is created. As set (at "1") the code will do so for every "iOriginalUnit" on the map every turn. I've provided a turn increment because it seems that you might find you create a boatload of units otherwise. If you alter the setting to "2" you would get an "iNewUnit" every other turn.
  5. The code is written to not spawn anything on the initial game turn. You have to advance at least one turn for anything to happen. This is true regardless of the turn increment you designate.
  6. the code does not look for anything related to who the unit belongs to. It just processes for all players and spawns the new unit if the player has any of the designated original units.
 

Attachments

  • Civ6_UnitDuplication (v 2).zip
    2 KB · Views: 128
interesting. It could probably be modified to work exactly like the old mongol camp from here.

Only other hard part would be adding checks for what type of tile it is on. GRASSLANDS HILLS etc is where that really shined. It spawned different units depending on what type of tile the camp was on the previous turn.
 
Is it possible to create a new improvement (Training camp) like the goody hut that just give you a unit (Plague Trebuchet). A goody hut could give you a scout, so it should be possible to eliminate the other gifts.
Than give the another unit (Mongol Camp) the ability to build the new improvement like the builder. What happens when the Mongol Camp build the new improvement. Will this give you the Plague Trebuchet immediately or did the Mongol Camp have to move one tile away and than come back to activate the new improvement?
 
Top Bottom