Unit Capture Rules Unique to Civilization

VainApocalypse

Warlord
Joined
Aug 10, 2010
Messages
245
Normally when unit X is captured, a Civ receives unit X. Suppose I wanted to change the rule for a single, custom Civ so that when the custom Civ captures unit X, it gets unit Y.

I think the rule is easily changed for all Civs in the game, but how would you do this for a single Civ? Would you need a LUA script or is there an easier way?
 
Look for CAPTURE_COMBAT_UNITS_AS_WORKERS in UnitAbilities.xml
Code:
        <Row>
            <ModifierId>CAPTURE_COMBAT_UNITS_AS_WORKERS</ModifierId>
            <Name>CanCapture</Name>
            <Value>true</Value>
        </Row>
        <Row>
            <ModifierId>CAPTURE_COMBAT_UNITS_AS_WORKERS</ModifierId>
            <Name>UnitType</Name>
            <Value>UNIT_BUILDER</Value>
        </Row>

This is part of the code you are looking for
 
Look at the code used by the Aztecs for their unit capture ability. I pasted the relevant data from the Modifiers and ModifierArguments tables below.
  • The Modifiers.ModifierType is MODIFIER_UNIT_ADJUST_COMBAT_CAPTURE
  • The ModifierArguments.Name arguments are CanCapture and UnitType


upload_2017-6-23_8-22-3.png
 
Look at the code used by the Aztecs for their unit capture ability. I pasted the relevant data from the Modifiers and ModifierArguments tables below.
  • The Modifiers.ModifierType is MODIFIER_UNIT_ADJUST_COMBAT_CAPTURE
  • The ModifierArguments.Name arguments are CanCapture and UnitType
View attachment 473205

Thanks for that. I totally forgot about the Aztec's unit.
 
Having looked closer at this, I don't think the modifier suggested by Isau or KoubaK does what I need. :sad: I'm trying to make it so that captured Settlers become builders. The EffectType is such, however, that if you use an Eagle Warrior to capture a Settler, it still becomes a Settler, because it doesn't apply to civilian units. EFFECT_ADJUST_UNIT_COMBAT_CAPTURE appears to only apply to combat units.
 
Last edited:
I think you might want to look under Units.xml too... there you should find the following lines.... see if you can cook up the right code for it.
Code:
    <UnitCaptures>
        <Row CapturedUnitType="UNIT_SETTLER" BecomesUnitType="UNIT_SETTLER"/>
        <Row CapturedUnitType="UNIT_BUILDER" BecomesUnitType="UNIT_BUILDER"/>
    </UnitCaptures>
 
I think you might want to look under Units.xml too... there you should find the following lines.... see if you can cook up the right code for it.
Code:
    <UnitCaptures>
        <Row CapturedUnitType="UNIT_SETTLER" BecomesUnitType="UNIT_SETTLER"/>
        <Row CapturedUnitType="UNIT_BUILDER" BecomesUnitType="UNIT_BUILDER"/>
    </UnitCaptures>

You may know something that I don't, but these rules aren't readily attached to a specific Civ within the scope of .xml or .SQL as they aren't associated with an EffectType.

In fact, in my experiments tonight, I can't even seem to get these rules to alter for all Civs.
Code:
    <UnitCaptures>
        <Row CapturedUnitType="UNIT_SETTLER" BecomesUnitType="UNIT_BUILDER"/>
    </UnitCaptures>

Throws no errors but still leaves a Settler upon capturing a Settler.
 
Doing this will I think violate the uniqueness requirements and would thus be rejected:
Code:
    <UnitCaptures>
        <Row CapturedUnitType="UNIT_SETTLER" BecomesUnitType="UNIT_BUILDER"/>
    </UnitCaptures>
The game already has a designation within the table of what to do for "UNIT_SETTLER" when it is captured and cannot have a second row in the table telling it to do something else with the same UnitType. You would need to do as
Code:
<UnitCaptures>
	<Update>
		<Where CapturedUnitType="UNIT_SETTLER" />
		<Set BecomesUnitType="UNIT_BUILDER"/>
	</Update>
</UnitCaptures>
But this would still not get you what you are after since it would apply to all players.

------------------------------------


Try the following lua script. You need to place it into an lua file and the lua file needs to be activated as a GamePlayScript under the "In-Game Actions" tab in modbuddy, or under <Components>/<InGameActions> if you create your mods manually:
Code:
local sRequiredCivilization = "CIVILIZATION_ROME"
local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
local iBuilder = GameInfo.Units["UNIT_BUILDER"].Index

function OnSettlerCaptured(iOwner, iUnitId, iUnsure1, iUnsure2)
	if (PlayerConfigurations[iOwner]:GetCivilizationTypeName() == sRequiredCivilization) then
		local pPlayer = Players[iOwner]
		local pPlayerUnits = pPlayer:GetUnits()
		local pUnit = pPlayerUnits:FindID(iUnitId)
		if (pUnit ~= nil) and (pUnit:GetType() == iSettler) then
			local iUnitX, iUnitY = pUnit:GetX(), pUnit:GetY()
			pPlayerUnits:Destroy(pUnit)
			pPlayerUnits:Create(iBuilder, iUnitX, iUnitY)
		end
	end
end
Events.UnitCaptured.Add(OnSettlerCaptured)
I'm not 100% sure what the final two arguments are for what the game engine passes to event-type "UnitCaptured", but I believe the 1st two are for the new owner's Player ID# and the unit's ID #, and the code is written accordingly.

You will have to edit "CIVILIZATION_ROME" to the correct name of the civilization you are using.

Here is what my modinfo file looks like for activating two "GamePlayScript" lua-files in a testing mod I use, just for reference on what the modinfo file ought to look like for an lua file of this sort when using modbuddy:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Mod id="808bc088-d136-4e70-a657-a3ad50756e66" version="1">
  <Properties>
    <Name>LUA Testing</Name>
    <Description>Testing LUA codes and concepts</Description>
    <Teaser>Testing LUA codes and concepts</Teaser>
    <Authors>Lee</Authors>
  </Properties>
  <InGameActions>
    <AddGameplayScripts id="Civ6LUA_Testing_File2">
      <File>LUA/Civ6LUA_Testing_File2.lua</File>
    </AddGameplayScripts>
    <AddGameplayScripts id="Civ6LUA_Testing_Gameplay">
      <File>LUA/Civ6LUA_Testing_Gameplay.lua</File>
    </AddGameplayScripts>
  </InGameActions>
  <Files>
    <File>LUA/Civ6LUA_Testing_File2.lua</File>
    <File>LUA/Civ6LUA_Testing_Gameplay.lua</File>
  </Files>
</Mod>
 
Doing this will I think violate the uniqueness requirements and would thus be rejected:
Code:
    <UnitCaptures>
        <Row CapturedUnitType="UNIT_SETTLER" BecomesUnitType="UNIT_BUILDER"/>
    </UnitCaptures>
The game already has a designation within the table of what to do for "UNIT_SETTLER" when it is captured and cannot have a second row in the table telling it to do something else with the same UnitType. You would need to do as
Code:
<UnitCaptures>
    <Update>
        <Where CapturedUnitType="UNIT_SETTLER" />
        <Set BecomesUnitType="UNIT_BUILDER"/>
    </Update>
</UnitCaptures>
But this would still not get you what you are after since it would apply to all players.

------------------------------------


Try the following lua script. You need to place it into an lua file and the lua file needs to be activated as a GamePlayScript under the "In-Game Actions" tab in modbuddy, or under <Components>/<InGameActions> if you create your mods manually:
Code:
local sRequiredCivilization = "CIVILIZATION_ROME"
local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
local iBuilder = GameInfo.Units["UNIT_BUILDER"].Index

function OnSettlerCaptured(iOwner, iUnitId, iUnsure1, iUnsure2)
    if (PlayerConfigurations[iOwner]:GetCivilizationTypeName() == sRequiredCivilization) then
        local pPlayer = Players[iOwner]
        local pPlayerUnits = pPlayer:GetUnits()
        local pUnit = pPlayerUnits:FindID(iUnitId)
        if (pUnit ~= nil) and (pUnit:GetType() == iSettler) then
            local iUnitX, iUnitY = pUnit:GetX(), pUnit:GetY()
            pPlayerUnits:Destroy(pUnit)
            pPlayerUnits:Create(iBuilder, iUnitX, iUnitY)
        end
    end
end
Events.UnitCaptured.Add(OnSettlerCaptured)
I'm not 100% sure what the final two arguments are for what the game engine passes to event-type "UnitCaptured", but I believe the 1st two are for the new owner's Player ID# and the unit's ID #, and the code is written accordingly.

You will have to edit "CIVILIZATION_ROME" to the correct name of the civilization you are using.

Here is what my modinfo file looks like for activating two "GamePlayScript" lua-files in a testing mod I use, just for reference on what the modinfo file ought to look like for an lua file of this sort when using modbuddy:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Mod id="808bc088-d136-4e70-a657-a3ad50756e66" version="1">
  <Properties>
    <Name>LUA Testing</Name>
    <Description>Testing LUA codes and concepts</Description>
    <Teaser>Testing LUA codes and concepts</Teaser>
    <Authors>Lee</Authors>
  </Properties>
  <InGameActions>
    <AddGameplayScripts id="Civ6LUA_Testing_File2">
      <File>LUA/Civ6LUA_Testing_File2.lua</File>
    </AddGameplayScripts>
    <AddGameplayScripts id="Civ6LUA_Testing_Gameplay">
      <File>LUA/Civ6LUA_Testing_Gameplay.lua</File>
    </AddGameplayScripts>
  </InGameActions>
  <Files>
    <File>LUA/Civ6LUA_Testing_File2.lua</File>
    <File>LUA/Civ6LUA_Testing_Gameplay.lua</File>
  </Files>
</Mod>

This didn't work for me, and I got the log that the script was loaded into the game.
 
Exactly. The quoted code violates the uniqueness rule and therefore will be rejected.

Erm, if you meant to refer to the lua-script then you'd have to zip and attach the mod itself in order to determine what is or is not running correctly.
 
Last edited:
Top Bottom