1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Chapter 2: Dynamic modifiers, effects, collections and arguments 2017-01-13

Learn how to create custom modifier types and determine a modifier's arguments.

  1. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    This is the second chapter of my guide on modifiers, explaining the underlying anatomy of the modifiers system including dynamic modifiers (modifier types), effects and collections.

    https://nycholusv.com/guides/using-modifiers/chapter-2/

    I apologise for how long it's taken to get this second chapter out. I've been very busy working on other civ-related things, such as my map script which is still a work-in-progress.

    * * *​

    In this chapter, you will learn how to define your own dynamic modifiers, which will allow for a very high degree of versatility in your modding. We will once again be creating a basic ‘balance patch’ as an example for you to follow along with, that will make the following changes:
    1. Founding Fathers (America’s special ability) increases the rate of border expansion by 20% in all cities.
    2. Mimar Sinan’s (Great Engineer) ability instantly grants +4 Population.
    By the end of this chapter, you should be able to:
    • Create and implement your own dynamic modifiers.
    • Understand what collections and effects are and how they are used by dynamic modifiers.
    • Understand how collections and effects relate to each other and to the concept of ‘subjects’.
    • Appreciate why creating your own dynamic modifiers is often necessary.
    • Determine what modifier arguments are valid for a modifier.
     
    isau and IllustriousYou like this.
  2. Pusperk

    Pusperk Chieftain

    Joined:
    Dec 24, 2015
    Messages:
    21
    Perfect guide. I have problem understand this:
    I have modifier for improvement dynamics type. This modifier test improvement tile on resource and if this is true,
    add second modifier. (Effect_attach_modifier, collection_single_plot_yields)
    Second modifier has type (adjust city amenities from religion) with collection type 'owner'.
    Function is ok, when build improvement with resource add amenity to city where improvement is build.
    Owner first modifier is improvement or plot tile?
    Who is owner second modifier? Improvement or city where improvement is build? Who is subject second modifier?
    City?
    Thanks for guide
    Pusperk
     
  3. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    Could you post your code here?
     
  4. Pusperk

    Pusperk Chieftain

    Joined:
    Dec 24, 2015
    Messages:
    21
    Yes.
    Code:
    <GameInfo>
        <Types>
            <!-- Definition new type modifier - dynamic modifier -->
            <Row Type="TCS_MODIFIER_PLOT_ADJUST_CITY_AMENITIES" Kind="KIND_MODIFIER"/>
        </Types>
        <!-- Definition new dynamic modifier -->
        <DynamicModifiers>
            <Row>
                <ModifierType>TCS_MODIFIER_PLOT_ADJUST_CITY_AMENITIES</ModifierType>
                <CollectionType>COLLECTION_SINGLE_PLOT_YIELDS</CollectionType>
                <EffectType>EFFECT_ATTACH_MODIFIER</EffectType>
            </Row>
        </DynamicModifiers>
        <!-- Definition new modifier -->
        <Modifiers>
            <Row>
                <ModifierId>TCS_ADD_AMENITY_FROM_DIAMONDS</ModifierId>
                <ModifierType>MODIFIER_SINGLE_CITY_ADJUST_CITY_AMENITIES_FROM_RELIGION</ModifierType>
                <SubjectRequirementSetId>TCS_CITY_HAS_PALACE_REQUIREMENTS</SubjectRequirementSetId>
            </Row>
            <Row>
                <ModifierId>TCS_ADD_AMENITY_FROM_DIAMONDS_MINE</ModifierId>
                <ModifierType>TCS_MODIFIER_PLOT_ADJUST_CITY_AMENITIES</ModifierType>
                <SubjectRequirementSetId>TCS_HAS_DIAMONDS</SubjectRequirementSetId>
            </Row>
        </Modifiers>
        <ModifierArguments>
        <Row>
                <ModifierId>TCS_ADD_AMENITY_FROM_DIAMONDS_MINE</ModifierId>
                <Name>ModifierId</Name>
                <Value>TCS_ADD_AMENITY_FROM_DIAMONDS</Value>
            </Row>
            <Row>
                <ModifierId>TCS_ADD_AMENITY_FROM_DIAMONDS</ModifierId>
                <Name>Amount</Name>
                <Value>2</Value>
            </Row>
        </ModifierArguments>
        <ImprovementModifiers>
            <Row>
                <ImprovementType>IMPROVEMENT_QUARRY</ImprovementType>
                <ModifierId>TCS_ADD_AMENITY_FROM_DIAMONDS_MINE</ModifierId>
            </Row>
        </ImprovementModifiers>
        <Requirements>
            <Row>
                <RequirementId>TCS_REQUIRES_CITY_HAS_DIAMONDS</RequirementId>
                <RequirementType>REQUIREMENT_PLOT_RESOURCE_TYPE_MATCHES</RequirementType>
            </Row>
            <Row>
                <RequirementId>TCS_REQUIRES_CITY_HAS_PALACE</RequirementId>
                <RequirementType>REQUIREMENT_CITY_HAS_BUILDING</RequirementType>
            </Row>
        </Requirements>
        <RequirementArguments>
            <Row>
                <RequirementId>TCS_REQUIRES_CITY_HAS_DIAMONDS</RequirementId>
                <Name>ResourceType</Name>
                <Value>RESOURCE_STONE</Value>
            </Row>
            <Row>
                <RequirementId>TCS_REQUIRES_CITY_HAS_PALACE</RequirementId>
                <Name>BuildingType</Name>
                <Value>BUILDING_PALACE</Value>
            </Row>
        </RequirementArguments>
        <RequirementSets>
            <Row>
                <RequirementSetId>TCS_HAS_DIAMONDS</RequirementSetId>
                <RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
            </Row>
            <Row>
                <RequirementSetId>TCS_CITY_HAS_PALACE_REQUIREMENTS</RequirementSetId>
                <RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
            </Row>
        </RequirementSets>
        <RequirementSetRequirements>
            <Row>
                <RequirementSetId>TCS_HAS_DIAMONDS</RequirementSetId>
                <RequirementId>TCS_REQUIRES_CITY_HAS_DIAMONDS</RequirementId>
            </Row>
            <Row>
                <RequirementSetId>TCS_CITY_HAS_PALACE_REQUIREMENTS</RequirementSetId>
                <RequirementId>TCS_REQUIRES_CITY_HAS_PALACE</RequirementId>
            </Row>
        </RequirementSetRequirements>
    </GameInfo>
     
  5. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    TCS_ADD_AMENITY_FROM_DIAMONDS_MINE
    • Owner: Plots, because you have this in ImprovementModifiers.
    • Subject(s): Plots, because the modifier type uses COLLECTION_SINGLE_PLOT_YIELDS.
    TCS_ADD_AMENITY_FROM_DIAMONDS
    • Owner: Plots, because the previous modifier is attaching this one to its subjects.
    • Subject(s): Plots, because MODIFIER_SINGLE_CITY_ADJUST_CITY_AMENITIES_FROM_RELIGION uses COLLECTION_OWNER.
     
  6. Deliverator

    Deliverator Graphical Hackificator

    Joined:
    Feb 12, 2008
    Messages:
    3,845
    Location:
    London, UK
    Thanks for tutorial @NycholusV. :)

    I'm trying to get something that ought to be simple working. I just want a Religion Belief to enable the construction of a particular unit.

    Here's my edited code:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <GameData>
    ...
        <Units>
            <Row UnitType="UNIT_TEMPLAR" BaseMoves="2" Cost="130" AdvisorType="ADVISOR_CONQUEST" BaseSightRange="2" ZoneOfControl="true"
                Domain="DOMAIN_LAND" FormationClass="FORMATION_CLASS_LAND_COMBAT" Name="LOC_UNIT_TEMPLAR_NAME"
                Description="LOC_UNIT_TEMPLAR_DESCRIPTION" PurchaseYield="YIELD_FAITH" PromotionClass="PROMOTION_CLASS_MELEE" Maintenance="2"
                Combat="40" PrereqTech="TECH_IRON_WORKING" MandatoryObsoleteTech="TECH_REPLACEABLE_PARTS" TraitType="TRAIT_CIVILIZATION_UNIT_TEMPLAR"/>
        </Units>
        <Traits>
            <Row TraitType="TRAIT_CIVILIZATION_UNIT_TEMPLAR" Name="LOC_UNIT_TEMPLAR_NAME"/>
        </Traits>
    ...
        <Modifiers>
            <Row>
                <ModifierId>JUST_WAR_TEMPLAR_UNIT_BONUS</ModifierId>
                <ModifierType>MODIFIER_ALL_PLAYERS_GRANT_TRAIT</ModifierType>
                <SubjectRequirementSetId>PLAYER_FOUNDED_RELIGION_REQUIREMENTS</SubjectRequirementSetId>
            </Row>
        </Modifiers>
        <ModifierArguments>
            <Row>
                <ModifierId>JUST_WAR_TEMPLAR_UNIT_BONUS</ModifierId>
                <Name>TraitType</Name>
                <Value>TRAIT_CIVILIZATION_UNIT_TEMPLAR</Value>
            </Row>
        </ModifierArguments>
        <BeliefModifiers>
            <Row BeliefType="BELIEF_JUST_WAR">
                <ModifierId>JUST_WAR_TEMPLAR_UNIT_BONUS</ModifierId>
            </Row>
        </BeliefModifiers>
    </GameData>
    
    From what I can tell MODIFIER_ALL_PLAYERS_GRANT_TRAIT doesn't work. Any ideas on how else to achieve this?

    Edit: Can I use the COLLECTION_PLAYER_CITIES with EFFECT_ATTACH_MODIFIER and then MODIFIER_SINGLE_CITY_GRANT_BUILDING_IN_CITY to grant a building which enables the unit?
     
    Last edited: Jan 30, 2017
  7. Deliverator

    Deliverator Graphical Hackificator

    Joined:
    Feb 12, 2008
    Messages:
    3,845
    Location:
    London, UK
    I don't fully understand what how the different combinations of the RunOnce and Permanent flags work. What happens if RunOnce is true but Permanent is false, or if Permanent is true and RunOnce is false?
     
  8. mauporte

    mauporte Chieftain

    Joined:
    Mar 7, 2012
    Messages:
    12
    Gender:
    Male
    Location:
    Monterrey, México
    Thanks for the guide, really helpful. Is there also a way to create effects?
     
  9. greyTiger

    greyTiger Chieftain

    Joined:
    Oct 7, 2010
    Messages:
    195
    Location:
    Australia
    Has anyone found a way to activate\deactivate modifiers independently through commands or lua function calls? This would be great as we could implement new game mechanics that update the core game using modifiers.
     
  10. Magil

    Magil Monarch

    Joined:
    Sep 26, 2010
    Messages:
    1,423
    I'd also like to know this, I have no idea what these two lines do.
     
  11. IllustriousYou

    IllustriousYou Chieftain

    Joined:
    Oct 25, 2016
    Messages:
    29
    Location:
    Earth
    No. The set of game effects listed in GameEffects.xml is hard-coded into the engine, per the comments on lines 3 and 4:

    Code:
    <!-- What goes in here? -->
    <!-- Any built-in GameEffect type that is exposed by the DLL. -->
    
     
  12. isau

    isau Chieftain

    Joined:
    Jan 15, 2007
    Messages:
    2,181

    I haven't tried the method you suggested. The "easiest" way to do this I think is to create a dummy Resource that the unit requires. Have the religion provide one copy of the resource (so it can't be traded).

    Use a resource like Jeans as the template so the resource doesn't appear on the map.

    Downside will be the strategic resource icon will show at the top of the screen. You can deal with this somewhat by setting it so the resource has a revealed Civic or Tech. Downside of that is the resource will still be "revealed" when people reach that tech, at least according to the Civ or Tech tree. They won't actually see anything if it's not on the map.

    Reminds me once again that Firaxis needs to make Techs and Civics that are unresearchable and don't appear in the trees. Would solve a million issues.
     
  13. mauporte

    mauporte Chieftain

    Joined:
    Mar 7, 2012
    Messages:
    12
    Gender:
    Male
    Location:
    Monterrey, México
    I thought so when I realized there was no GameEffects table in the Data xmls,
    I'm no videogame programmer but it does seem clunky the way effects are defined, I mean for example there is a grant_spy effect and an increase_trade_route_capacity effect; I would've thought of something like this:
    <GameEffects> <Effect Type><UnitType> <Amount> etc. etc.
    I don't know, it seems simpler that way.
     
    Last edited: Mar 3, 2017
  14. luei333

    luei333 Chieftain

    Joined:
    May 25, 2014
    Messages:
    139
    He actually goes into these in the first chapter. Direct quote:
    Short version, RunOnce means that the modifier will only run one time, instead of constantly applying its effects over multiple turns. Only really applicable for certain things, like granting units or population, etc.

    Permanent means that the modifier will ALWAYS exist on that entity, as long as the entity itself exists. Persistent bonuses, like bonuses to yields, will be applied forever and aren't turned off when the requirements are no longer met. And since the modifier can never be UN-applied, it can never be RE-applied. Combined with RunOnce, you can make modifiers that can trigger once, and only ever once per entity they can affect.

    Imagine adding a modifier to a city that grants 1 population (or a similar effect), and requires a builder to be in the city center's tile. The first time a builder walk onto its tile, the city will receive an extra population. If the RunOnce value isn't set to true, it will likely continue to gain extra population every turn or so, as long as the builder remains on its tile (or however often the effect would trigger). If Permanent but not RunOnce, it will likely gain extra population continuously for the rest of the game! Adding RunOnce means that the city would get extra population only one time, but without permanent it could trigger multiple times. Not sure on the exact nature there, but it might be as simple as moving the builder off of the tile and back on repeatedly to trigger the population gain again and again. With both RunOnce and Permanent set, that city would only ever be able to gain 1 extra population from having a builder on its tile, no matter how many different builders go on it throughout the course of the game.
     
  15. luei333

    luei333 Chieftain

    Joined:
    May 25, 2014
    Messages:
    139
    You could add a building dependency to the unit, much like the Temple has to the Apostle or the Archaeological Museum has to the Archaeologist. When a city gets your belief (use the same structure many of the religious modifiers do, the collection is all cities, but the requirement is that they follow your belief), then have the modifier grant them the free building (could just be a building with no effect or anything), and voila, they can train your unit, or buy it with faith, etc. Problem is, you'd have to remove the building once the city no longer has the belief, but that's much easier to do via Lua than fussing with resources. Also, the building will be visible in the city details panel, even if you hide its entries from the Civilopedia. An easy way to get around this is to include it in the design. Maybe the belief lets you build a religious building, and that building lets you train the unit you want. Could be a cheap building, maybe with only a +1 or +2 faith bonus besides giving access to the unit. Food for thought.
     
  16. luei333

    luei333 Chieftain

    Joined:
    May 25, 2014
    Messages:
    139
    Also, NycholusV, I love you for providing these tutorials. The first one helped me immensely in understanding how the modifiers system worked back when it was first posted, and by the time you posted this second chapter, I'd already figured out all the stuff you talked about in it! Definitely some of the best resources for modding Civ 6 so far.
     
  17. richardsvensson

    richardsvensson Chieftain

    Joined:
    Sep 25, 2010
    Messages:
    32
    Thanks a lot for the two chapters on Modifiers! Really useful.

    I've managed to change the Gold Yield for Shrines to 1 and Temples to 2 by using modifiers. However, I'm struggling with giving the bonus only once a civic (Reformed Church) is discovered. I can't figure out how to solve it.

    My first thought was to use OwnerRequirementSetId and specify that PLAYER_HAS_CIVIC_REFORMED_CHURCH, or something like that. (I couldn't find that one in the list and don't know how to create my own requirements)

    I've also been thinking about the possibility of linking the modifiers:

    Leader Trait --> Civic Modifier --> Bonus Yield for Building

    Would that give the Civic Modifier only to the leader(s) with that particular Leader trait, or to all players?
     
  18. Rajendran

    Rajendran Chieftain

    Joined:
    Jan 4, 2017
    Messages:
    58
    Gender:
    Male
    NycholusV,
    I downloaded this chapter file/mod (no changes were done) but noticed the following error in the log file pertaining to this mod.
     

    Attached Files:

  19. kassambique

    kassambique Chieftain

    Joined:
    Jun 1, 2011
    Messages:
    4
    Hello,

    thanks for the two interesting chapters, I was able to create a first modifier and indeed see it in the game (yeehaw) but I'm struggling with another one. I'd like to give the ability ABILITY_CAPTIVE_WORKERS to units of this new civilization, this ability is yet defined une the UnitAbilities file of the game.
    Even though there is no error when building the mode and fire tuner seems to apply the modifier MODIFIER_RWK_PLAYER_UNITS_CAN_CAPTURE to all unit, the ability is not there on each unit, as if one step to "propagate" the modifier from "Player's unit" to the unit itself was missing. But I can't see what, can somebody help?

    Thanks

    Code:
    --==========================================================================================================================
    -- CIVILIZATIONS: TRAITS
    --==========================================================================================================================
    -- Types
    --------------------------------------------------------------------------------------------------------------------------   
    INSERT INTO Types   
            (Type,                                                    Kind)
    VALUES    ('TRAIT_CIVILIZATION_RWK_CAN_CAPTURE',                        'KIND_TRAIT'),
            ('MODIFIER_RWK_PLAYER_UNITS_CAN_CAPTURE',               'KIND_MODIFIER');   
            
            
    --------------------------------------------------------------------------------------------------------------------------           
    -- Traits           
    --------------------------------------------------------------------------------------------------------------------------               
    INSERT INTO Traits               
            (TraitType,                                                    Name,                                                    Description)
    VALUES    ('TRAIT_CIVILIZATION_RWK_CAN_CAPTURE',                        'LOC_TRAIT_CIVILIZATION_RWK_CAN_CAPTURE_NAME',                    'LOC_TRAIT_CIVILIZATION_RWK_CAN_CAPTURE_DESCRIPTION');
    --------------------------------------------------------------------------------------------------------------------------       
    -- TraitModifiers       
    --------------------------------------------------------------------------------------------------------------------------           
    INSERT INTO TraitModifiers           
            (TraitType,                                            ModifierId)
    VALUES    ('TRAIT_CIVILIZATION_RWK_CAN_CAPTURE',                    'MODIFIER_RWK_PLAYER_UNITS_CAN_CAPTURE');   
    
    
                                                                                    
    --------------------------------------------------------------------------------------------------------------------------
    -- Modifiers
    --------------------------------------------------------------------------------------------------------------------------
    INSERT INTO Modifiers   
            (ModifierId,                                                ModifierType, Permanent)
    VALUES    ('MODIFIER_RWK_PLAYER_UNITS_CAN_CAPTURE',                                        'MODIFIER_PLAYER_UNITS_GRANT_ABILITY', '1');           
    --------------------------------------------------------------------------------------------------------------------------
    -- ModifierArguments
    --------------------------------------------------------------------------------------------------------------------------
    INSERT INTO ModifierArguments
            (ModifierId,                                                Name,                        Value)
    VALUES    ('MODIFIER_RWK_PLAYER_UNITS_CAN_CAPTURE',         'AbilityType',  'ABILITY_CAPTIVE_WORKERS');
    
    
    
     
  20. chadm290

    chadm290 Chieftain

    Joined:
    Apr 6, 2013
    Messages:
    31
    Thank you for this guide. Any chance we can get Chapter 3 for the requirements? I need an understanding of how they work to implement it in my own mods. Thank you!
     

Share This Page