[Vanilla] [SOLVED] Custom trait won't work

Zobtzler

Chieftain
Joined
Oct 21, 2017
Messages
95
Location
Sweden
A civ I'm making is supposed to have a custom ability, however when I load a new game it puts me back into the menu.

This is the section I want to add

Code:
--------------------------------------------------------------------------------------------------------------------------
-- TraitModifiers       
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO TraitModifiers           
        (TraitType,                                ModifierId)
VALUES    ('TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT',    'ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION');
--------------------------------------------------------------------------------------------------------------------------
-- Modifiers
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO Modifiers   
        (ModifierId,                                ModifierType                            SubjectRequirementSetId)
VALUES    ('ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION',    'MODIFIER_PLAYER_ADJUST_PLOT_YIELD',    'ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT');
--------------------------------------------------------------------------------------------------------------------------
-- ModifierArguments
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO ModifierArguments
        (ModifierId,                                Name,            Value)
VALUES    ('ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION',    'YieldType',    'YIELD_PRODUCTION'),
        ('ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION',    'Amount',        '2');
--------------------------------------------------------------------------------------------------------------------------
-- Requirements
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO Requirements
        (RequirementId,                            RequirementType)
VALUES    ('REQUIRES_PLOT_HAS_ZOB_GRASS_HILLS',    'REQUIREMENT_PLOT_TERRAIN_TYPE_MATCHES');
--------------------------------------------------------------------------------------------------------------------------
-- RequirementArguments
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO RequirementArguments
        (RequirementId,                            Name,            Value)
VALUES    ('REQUIRES_PLOT_HAS_ZOB_GRASS_HILLS',    'TerrainType',    'TERRAIN_GRASS_HILLS');
--------------------------------------------------------------------------------------------------------------------------
-- RequirementSets
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO RequirementSets
        (RequirementSetId,                                    RequirementSetType)
VALUES    ('ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT',    'REQUIREMENTSET_TEST_ALL');
--------------------------------------------------------------------------------------------------------------------------
-- RequirementSetRequirements
--------------------------------------------------------------------------------------------------------------------------
INSERT INTO RequirementSetRequirements
        (RequirementSetId,                                    RequirementId)
VALUES    ('ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT',    'REQUIRES_PLOT_HAS_ZOB_GRASS_HILLS');

This results in this from the database.log file

Code:
[3748379.566] [Gameplay] ERROR: near "SubjectRequirementSetId": syntax error
[3748379.569] [Gameplay] ERROR: FOREIGN KEY constraint failed
[3748379.569] [Gameplay] ERROR: FOREIGN KEY constraint failed
[3748379.569] [Gameplay]: Validating Foreign Key Constraints...
[3748379.581] [Gameplay] ERROR: Invalid Reference on TraitModifiers.ModifierId - "ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION" does not exist in Modifiers
[3748379.584] [Gameplay]: Failed Validation.

As an experiment, I switched TraitModifiers and Modifiers in the code (meaning that Modifiers instead came before TraitModifiers). This broke the mod in another way instead, I was able to start a game, but my civ suddenly didn't have any leader traits or civ traits or UUs at all (the game text was visible when picking the leader and civ, but not when the game started to load)
 
Update, tried to do it in XML instead, and this time the game will at least start, and all the previous traits are working (UUs and leader trait) but this trait won't load (it is still displayed in the diplomacy screen)

Anyone knows what to do?

EDIT: NVM it seems to be working now! XML did the job apparently (forgot that I can't check unsettled/unowned tiles lol :crazyeye:)

Code:
<Types>
        <Row Type="TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT" Kind="KIND_TRAIT"/>
    </Types>
    <Traits>
        <Row TraitType="TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT" Name="LOC_TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT_NAME" Description="LOC_TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT_DESCRIPTION"/>
    </Traits>
    <TraitModifiers>
        <Row TraitType="TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT" ModifierId="ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION"/>
    </TraitModifiers>
    <Modifiers>
        <Row ModifierId="ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION" ModifierType="MODIFIER_PLAYER_ADJUST_PLOT_YIELD" SubjectRequirementSetId="ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT"/>
    </Modifiers>
    <ModifierArguments>
        <Row ModifierId="ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION" Name="YieldType" Value="YIELD_PRODUCTION"/>
        <Row ModifierId="ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION" Name="Amount" Value="2"/>
    </ModifierArguments>
    <Requirements>
        <Row RequirementId="REQUIRES_PLOT_HAS_ZOB_GRASS_HILLS" RequirementType="REQUIREMENT_PLOT_TERRAIN_TYPE_MATCHES"/>
    </Requirements>
    <RequirementArguments>
        <Row RequirementId="REQUIRES_PLOT_HAS_ZOB_GRASS_HILLS" Name="TerrainType" Value="TERRAIN_GRASS_HILLS"/>
    </RequirementArguments>
    <RequirementSets>
        <Row RequirementSetId="ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT" RequirementSetType="REQUIREMENTSET_TEST_ALL"/>
    </RequirementSets>
    <RequirementSetRequirements>
        <Row RequirementSetId="ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT" RequirementId="REQUIRES_PLOT_HAS_ZOB_GRASS_HILLS"/>
    </RequirementSetRequirements>
    <CivilizationTraits>
        <Row TraitType="TRAIT_CIVILIZATION_ZOB_SWEDEN_TRAIT" CivilizationType="CIVILIZATION_ZOB_CIV_SWEDEN"/>
    </CivilizationTraits>
 
in your original sql code
Code:
INSERT INTO Modifiers   
        (ModifierId,                                ModifierType                            SubjectRequirementSetId)
VALUES    ('ZOB_SWEDEN_TRAIT_GRASS_HILLS_PRODUCTION',    'MODIFIER_PLAYER_ADJUST_PLOT_YIELD',    'ZOB_PRODUCTION_PLOT_HAS_GRASS_HILLS_REQUIREMENT');
You indeed have a syntax error as Database.log reported. You are missing a comma after ModifierType

As soon as the game reads a syntax error like this in a file (whether SQL or XML) it ceases to use anything in that file from that point downward. So moving this chunk of code around within the file would make more or less of the file's contents get implemented into the game's database depending on whether you move the bit with the error up or down in the file.

You'd probably still get shoved back to the main menu regardless of where you move it except perhaps to place it at the very end (so everything else would then get read in). But most likely you'll keep getting shoved back to the main menu because of the "invalid reference" error that will result from this sort of syntax error until you find and fix the error.

Fixing a syntax error toward the top of a file will often reveal another error farther down. You need to just keep working the problem by finding and eliminating the syntax errors before you can really test whether the game has enough requirements etc to implement what you are after.
 
Last edited:
If you download and use an SQL database viewer program you can load up the game's database and test you sql chunks to see if they have syntax errors even before you attempt to use those chunks of SQL code within a functioning mod.

This is not a test as to whether the game will implement your code as you hope, but rather that there are not SQL syntax errors.
 
just a question. does this trait upgrade all grass hills for your new civ "sweden"? so when you found a city with grass hills within the borders it will give directly +2 production?

i used MODIFIER_PLAYER_ADJUST_PLOT_YIELD to change the yield amounts of placed farms. i thought that PLAYER_ADJUST_PLOT means an action of the player unit like the builder builds a farm. so does this also effect a settler "builds" a city?

i think i still dont understand "PLOT" in the modifiers...
 
just a question. does this trait upgrade all grass hills for your new civ "sweden"? so when you found a city with grass hills within the borders it will give directly +2 production?

i used MODIFIER_PLAYER_ADJUST_PLOT_YIELD to change the yield amounts of placed farms. i thought that PLAYER_ADJUST_PLOT means an action of the player unit like the builder builds a farm. so does this also effect a settler "builds" a city?

i think i still dont understand "PLOT" in the modifiers...

Yes, It affects all plots (tiles) with grass hills within the borders of any city of this civ (meaning that as long as a tile has grass hills, it will always have that production bonus). If a grass hills tile was outside my borders, it would have 1 production, but if I bought that tile, it would now have 3 production automatically.

But this was just a placeholder as I changed it to +1 production from forests and +1 production from lumber mills yesterday.
After some testing I realized that after researching steel, I could get a 8 production tile by having a plains hills tile (+2 production) with forest (+1 production, +1 production from mod), a lumber mill (+1 production, +1 production after steel, +1 production from mod) that is by a river (+1 production to lumber mills), and if it's just on a a flat grass tile it's up to 6 production
On the Y(n)AEMP Europe map, Sweden has a LOT of forests and a few of those are grass hills and even some are plains hills...
Although in my test I started in the informational era, I was able to get a 116 production city along a river surrounded by forests without any traders in and out of that city... but that was all without any entertainment districts etc, so I don't think it would be such an issue... but should it be one, I'll nerf it :p
 
Last edited:
Top Bottom