1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Using Modifiers - Chapter 1: Creating and attaching modifiers 2016-11-22

Learn how to implement modifiers into the game.

  1. Lord Yanaek

    Lord Yanaek Chieftain

    Joined:
    Aug 15, 2003
    Messages:
    1,438
    Well, as far as i know, you can use Lua for UI effects as much as you want by overwriting core game files. You can also create "game scripts" that affects the game, but those are only loaded when you create a new game, and not when you load a saved game, making them useless for anything but initialization.

    Not sure whether it's a bug or there is something to add to the modinfo file. Somebody might even have found a way to load them with saved game but in this case, i missed the announcement.
    EDIT: Just asked. Both LeeS and Gedemon confirmed that gameplay scripts still don't work so currently Lua modding is very limited (mostly UI stuff and a few game affecting functions that might be hacked into an UI script)

    So there's no way to do it easily with modifiers is there?
     
    Last edited: Nov 24, 2016
  2. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    Tried to add a new modifier to make siege towers only work with non-cav units. Worked on it a long time, but just realized the promotion is a modifier, but the effect is a dynamic modifier. I can't seem to figure out how to put requirements on dynamic modifiers.

    Or maybe I've been working on it too long, and have lost sanity. Here's the code

    INSERT INTO Requirements (RequirementId, RequirementType, Inverse) VALUES ("UNIT_IS_NOT_CAVALRY_REQUIREMENT","REQUIREMENT_UNIT_PROMOTION_CLASS_MATCHES",1);
    INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES ("UNIT_IS_NOT_CAVALRY_REQUIREMENT","UnitPromotionClass","UNIT_IS_CAVALRY_REQUIREMENTS");
    INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES ("BYPASS_WALLS_REQUIREMENTS","REQUIREMENTSET_TEST_ALL");
    UPDATE Modifiers Set SubjectRequirementSetId = 'BYPASS_WALLS_REQUIREMENTS' Where ModifierType = 'MODIFIER_PLAYER_UNIT_ADJUST_BYPASS_WALLS';
    INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES ("BYPASS_WALLS_REQUIREMENTS","UNIT_IS_NOT_CAVALRY_REQUIREMENT");
     
  3. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    You cannot place requirements on dynamic modifiers, and there is no need to either. Each modifier is assigned a dynamic modifier. Assign the RequirementSet to that.
     
  4. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    I've tried many variations and it doesn't work. I think it's due to how BYPASS_WALLS works, and that isn't something I can edit.
     
    Atlas627 likes this.
  5. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    Just had a look, and that does seem to be the case. MODIFIER_PLAYER_UNIT_ADJUST_BYPASS_WALLS uses COLLECTION_OWNER, meaning the only entity that the effect is actually applied to is the Siege Tower itself.
     
  6. Elucidus

    Elucidus Chieftain

    Joined:
    Mar 3, 2002
    Messages:
    980
    Location:
    USA
    This is great. I'm gonna go through this in-depth tomorrow. Beei trying to add a trait to Russia for Tundra Mountains and Petra for Desert mountains.
     
  7. Elucidus

    Elucidus Chieftain

    Joined:
    Mar 3, 2002
    Messages:
    980
    Location:
    USA
    This is great, I read one of the first paragraphs and it gave me what I was missing. Thanks Nycholus.
     
    NycholusV likes this.
  8. Enj0y

    Enj0y Chieftain

    Joined:
    Jul 9, 2014
    Messages:
    26
    Gender:
    Male
    Location:
    Orange County, CA
    First off, this resource was incredibly helpful. I'm watching daily for chapter 2 to be posted. Well done.

    Second, I'm trying to breakout all of the various Leader Traits and Civ Abilities into a modular format so one can mix and match. The first civ I'm starting with is Rome. I'm trying to modify Trajan's Column to include a 15% percent border expansion increase as well as updating All Roads Lead To Rome to include +1 Production and +1 Food for traveling thru domestic trading posts because naturally going thru domestic trading posts would spread food and productivity as well as gold.

    In both .sql files I was originally getting a "UNIQUE constraint failed: TraitModifiers.TraitType, TraitModifiers.TraitType" error. I tweaked the SQL from all INSERT INTO to a mix of UPDATE and INSERT INTO which resolved that error. But now I'm getting "ERROR: Near "(": syntax error".

    Any help would be greatly appreciated. .sql is below, as well as the most recent database.log. The GameEffects.log file is a little long, but I'll put it up if anyone needs it.

    All Roads To Rome
    HTML:
    --Entity-Modifier
    
    Tables INSERT INTO TraitModifiers ( TraitType, ModifierId ) VALUES
    ( 'TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME', 'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS' ),
    ( 'TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME', 'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS' );
    
     -- The Modifiers Table
    
    INSERT INTO Modifiers ( ModifierId, ModifierType, RunOnce, Permanent, SubjectRequirementSetId ) VALUES
    ( 'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS', 'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_YIELD_PER_POST_IN_OWN_CITY', '0', '0', NULL ),
    ( 'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS', 'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_YIELD_PER_POST_IN_OWN_CITY', '0', '0', NULL );
    
    -- Modifier Arguments
    
    UPDATE ModifierArguments ( ModifierId, Name, Value ) VALUES ( 'TRAIT_GOLD_FROM_DOMESTIC_TRADING_POSTS', 'Amount', '10' ), INSERT INTO ModifierArguments ( ModifierId, Name, Value ) VALUES
    ( 'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS', 'YieldType', 'YIELD_FOOD' ),
    ( 'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS', 'Amount', '2' ),
    ( 'TRAIT_GOLD_FROM_DOMESTIC_TRADING_POSTS', 'YieldType', 'YIELD_GOLD' ),
    ( 'TRAIT_GOLD_FROM_DOMESTIC_TRADING_POSTS', 'Amount', '1' ),
    ( 'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS', 'YieldType', 'YIELD_PRODUCTION' ),
    ( 'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS', 'Amount', '1' );
    
    UPDATE BaseGameText ( Tag, Text ) VALUES
    ( 'LOC_TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME_DESCRIPTION'), 'All cities you found or conquer start with a Trading Post. If in [ICON_TradeRoute] Trade Route range of your [ICON_Capital] Capital, they also start with a road to it. Your [ICON_TradeRoute] Trade Routes earn +1 [ICON_Gold] Gold, [ICON_Production] Production, and [ICON_Food] Food for passing through Trading Posts in your own cities.' );"]
    Trajan's Column
    HTML:
    -- Entity-Modifier Tables
    
    UPDATE TraitModifiers ( TraitType, ModifierId ) VALUES
    ( 'TRAJANS_COLUMN_TRAIT', 'TRAIT_ADJUST_NON_CAPITAL_FREE_CHEAPEST_BUILDING' );
    INSERT INTO TraitModifiers ( TraitType, ModifierId ) VALUES 
    ( 'TRAJANS_COLUMN_TRAIT', 'TRAIT_INCREASED_CULTURE_BORDER_EXPANSION' );
    
    -- The Modifiers Table
    
    UPDATE Modifiers ( ModifierId, ModifierType, RunOnce, Permanent, SubjectRequirementSetId ) VALUES
    ( 'TRAIT_ADJUST_NON_CAPITAL_FREE_CHEAPEST_BUILDING', 'MODIFIER_PLAYER_CITIES_GRANT_CHEAPEST_BUILDING_IN_CITY', '1', '1', NULL );
    INSERT INTO Modifiers ( ModifierId, ModifierType, RunOnce, Permanent, SubjectRequirementSetId ) VALUES
    ( 'TRAIT_INCREASED_CULTURE_BORDER_EXPANSION', 'MODIFIER_ALL_CITIES_CULTURE_BORDER_EXPANSION', '0', '0', NULL );
    
    -- Modifier Arguments
    
    UPDATE ModifierArguments ( ModifierId, Name, Value ) VALUES
    ( 'TRAIT_ADJUST_NON_CAPITAL_FREE_CHEAPEST_BUILDING', 'Amount', '2' );
    INSERT INTO ModifierArguments ( ModifierId, Name, Value ) VALUES
    ( 'TRAIT_INCREASED_CULTURE_BORDER_EXPANSION', 'Amount', '15' );"]
    Database.log
    HTML:
    [624340.913] [Localization]: Validating Foreign Key Constraints...
    [624340.913] [Localization]: Passed Validation.
    [624340.929] [Configuration]: Validating Foreign Key Constraints...
    [624340.930] [Configuration]: Passed Validation.
    [624346.754] [FullTextSearch]: Initializing FullTextSearch
    [624347.224] [Gameplay]: Validating Foreign Key Constraints...
    [624347.234] [Gameplay]: Passed Validation.
    [624347.567] [Configuration]: Validating Foreign Key Constraints...
    [624347.568] [Configuration]: Passed Validation.
    [624378.779] [Gameplay] ERROR: near "(": syntax error
    [624378.792] [Gameplay]: Validating Foreign Key Constraints...
    [624378.803] [Gameplay]: Passed Validation.
    [624382.699] [FullTextSearch]: FTS - Creating Context
    [624382.852] [FullTextSearch]: FTS - Creating Context
    [624383.303] [FullTextSearch]: FTS - Creating Context
    [624527.607] [FullTextSearch]: FullTextSearch - Shutting down
     
    Last edited: Dec 22, 2016
  9. Elucidus

    Elucidus Chieftain

    Joined:
    Mar 3, 2002
    Messages:
    980
    Location:
    USA
    Updates are handled a lot dfferently than insert

    Usually it is somethign like
    UPDATE ModifierArguments
    SET Value = 2
    WHERE ModifierID = 'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS' AND Value = 2;


    Also you with a comma not a semicolon at the bolded area, and you are also updating and then inserting the same modifierID (underlined below). ModifierID & Name are a combination in ModifierArguments that must be unique. Not sure if those fix your problems, but it is pretty late, I will check with fresh eyes tomorrow sometime. Good luck.

     
    Enj0y likes this.
  10. Enj0y

    Enj0y Chieftain

    Joined:
    Jul 9, 2014
    Messages:
    26
    Gender:
    Male
    Location:
    Orange County, CA
    I think that did it for the All Roads Lead To Rome ability. Thanks for burning the midnight oil.

    I updated the sql to this:

    Code:
    -- Entity-Modifier Tables
    
    INSERT INTO TraitModifiers
    (    TraitType,                                ModifierId                                        )    VALUES
    (    'TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME',    'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS'        ),
    (    'TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME',    'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS'    );
    
    -- The Modifiers Table
    
    INSERT INTO Modifiers
    (    ModifierId,                                            ModifierType,                                                        RunOnce,    Permanent,    SubjectRequirementSetId        )    VALUES
    (    'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS',            'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_YIELD_PER_POST_IN_OWN_CITY',    '0',        '0',        NULL                        ),
    (    'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS',        'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_YIELD_PER_POST_IN_OWN_CITY',    '0',        '0',        NULL                        );
    
    -- Modifier Arguments
    
    INSERT INTO ModifierArguments
    (    ModifierId,                                        Name,            Value                )    VALUES
    (    'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS',        'YieldType',    'YIELD_FOOD'        ),
    (    'TRAIT_FOOD_FROM_DOMESTIC_TRADING_POSTS',        'Amount',        '10'                ),
    (    'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS',    'YieldType',    'YIELD_PRODUCTION'    ),
    (    'TRAIT_PRODUCTION_FROM_DOMESTIC_TRADING_POSTS',    'Amount',        '10'                );
    
    UPDATE ModifierArguments
    SET Value = 2
    WHERE ModifierID = 'TRAIT_GOLD_FROM_DOMESTIC_TRADING_POSTS' AND Value = 1;
    And the new database.log says this:

    Code:
    [667328.500] [Localization]: Validating Foreign Key Constraints...
    [667328.502] [Localization]: Passed Validation.
    [667328.513] [Configuration]: Validating Foreign Key Constraints...
    [667328.513] [Configuration]: Passed Validation.
    [667334.437] [FullTextSearch]: Initializing FullTextSearch
    [667334.948] [Gameplay]: Validating Foreign Key Constraints...
    [667334.958] [Gameplay]: Passed Validation.
    [667335.333] [Configuration]: Validating Foreign Key Constraints...
    [667335.333] [Configuration]: Passed Validation.
    [667387.928] [Gameplay]: Validating Foreign Key Constraints...
    [667387.939] [Gameplay]: Passed Validation.
    [667391.698] [FullTextSearch]: FTS - Creating Context
    [667391.848] [FullTextSearch]: FTS - Creating Context
    [667392.336] [FullTextSearch]: FTS - Creating Context
    [668338.332] [FullTextSearch]: FullTextSearch - Shutting down
    So I think we're golden. Thanks a lot!
     
  11. Elucidus

    Elucidus Chieftain

    Joined:
    Mar 3, 2002
    Messages:
    980
    Location:
    USA
    Glad I could help.
     
  12. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    I want to make Defender of the Faith, and Crusade require having a religious unit on the tile.

    There are two requirements, the original,
    Founded religion, and not a religious unit, and near a friendly city
    And
    On a tile with an apostle, or a missionary, or an inquisitor.

    So an Any requirements, and an All requirements. But you can only set one requirement per modifier.

    Any ideas how to make that happen?
     
  13. Enj0y

    Enj0y Chieftain

    Joined:
    Jul 9, 2014
    Messages:
    26
    Gender:
    Male
    Location:
    Orange County, CA
    Have you tried giving the ability to the apostle/missionary/inquisitor instead, with an active range of 0? That may eliminate the need for the set set of requirements.
     
  14. Elucidus

    Elucidus Chieftain

    Joined:
    Mar 3, 2002
    Messages:
    980
    Location:
    USA
    Perhaps I am misunderstanding, but you can most definitely have multiple requirements per modifier, that is where RequirementSets come in and also requirements have an inverse option, which reverses them, between all of that you should be able to do what you want, no?

    You could probably re-use Requirement_Unit_Type_Matches and add all fo the units it should work with.
     
  15. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    There's a requirement that checks another RequirementSet. Can't remember what it's called off the top of my head but I think it's listed near the top of GameEffects.xml.

    So as I understand you want to do:
    x and (y or z)

    This can effectively become:
    x and S
    S = y or z

    by using 'nested' requirements, just as you can use 'nested' modifiers (as I suspect you found out when creating the new pantheons for the NQ mod).
     
  16. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    Just FYI, the GameEffects file is not of much use if there's an SQL error in the Database file. When a syntax error is found, the current query and the rest of the file is rejected and not processed. A constraint error will reject any changes that break the constraint.

    So the GameEffects file is used when something isn't working but there's no SQL errors.
     
  17. NycholusV

    NycholusV Chieftain

    Joined:
    Jun 25, 2016
    Messages:
    85
    Gender:
    Male
    Location:
    Sydney, Australia
    Also, I'm currently working on a map script for Civ 6, once I'm done with that I'll focus on writing Chapter 2. I pretty much know what I'll include in it (i.e. the examples), just need to write it. It seems sometimes I'm in a literary and educative mood, other times not.
     
    IllustriousYou likes this.
  18. Rajendran

    Rajendran Chieftain

    Joined:
    Jan 4, 2017
    Messages:
    58
    Gender:
    Male
    Nycholus V, Thank you very much for the tutorial material. I have been playing since Civ 2 but have never created my own mod. Wanted to try to create my own preferred mod but did not know where to start. Started to read up some basic xml and sql formatting but was still unsure how to go. However, after seeing these contents, it gave me a great enjoyment and confident to create my own mod. THANK YOU.
     
  19. weregamer

    weregamer Gandhi of the Mongols

    Joined:
    Sep 6, 2006
    Messages:
    244
    Location:
    San Jose, CA
    Oh, daggumit!

    The link to this tutorial is dead. I remember thinking how useful this would be when I got around to writing a meaningful mod. Could somebody who downloaded it put it up somewhere?
     
  20. kingchris20

    kingchris20 Wisdom Seeker

    Joined:
    Jul 30, 2012
    Messages:
    1,328
    Location:
    Resident of Heaven; Currently in the Waiting Room

Share This Page

Ebates: Get Paid to Shop