HOWTO: Use Game Setup Options in your mod

dbergan

Warlord
Joined
Feb 27, 2006
Messages
152
Location
Sioux Falls, SD
One of the biggest aha moments I've had in my civ 6 modding was learning how to use the Game Setup Options to turn on/off features. For example, my first flagship civ 6 mod is a religion overhaul called Soli Deo Gloria. The gist of SDG is that your religion gets beliefs from Great Prophets (not apostles) and that you can continually recruit Prophets throughout the game, like other Great People. Each new Great Prophet gives you a new belief, and there are no restrictions on how many beliefs (or what kind of beliefs) your religion can have.

Now, as I played with this over the years, there were several other aspects of religion that I wanted to change, but they weren't directly related to the SDG core and I wanted players to have the option of playing with or without them. Originally, I created all these options as separate mods, and in some cases these "a la carte" mods were literally a single line of code. Things like Remove Condemn Heretic or Inquisitors Only Get One Cleanse. So now my Steam Workshop page and Mod Selection screen was cluttered with over 30 mods, most of which are dinky little things like that. Having so many mods is a hassle, both for playing and for maintaining. I had multiple spreadsheets to keep track of the interactions of all these mods, when they all were dependent on, or intended to work alongside the main mod, SDG. When I play multiplayer, I have to get all my friends to download 30 of my mods.

The breakthrough for me was figuring out (with help from Gedemon, Zegangani, and FearSunn) how to combine all these a la carte mods into the main SDG mod as Game Setup Options. Now my friends only need a single mod that gives them all these capabilities. Here's what I'm talking about.

In my mod selection screen there's only one mod selected:

And by selecting just that one mod, all those a la carte "mini-mod" options are available on the Advanced Setup page of the Create Game settings:


Here's how I made this work.

1) Create two new sql files, something like "GameSetup.sql" and "LOC_GameSetup.sql" (you could probably also do this with xml, but that's not my preference)

2) In GameSetup.sql you add your options to the Parameters table like so:
Code:
INSERT INTO Parameters (ParameterId, Name, Description,
Domain, DefaultValue, ConfigurationGroup, ConfigurationId, GroupId, Visible, ReadOnly,
SupportsSinglePlayer, SupportsLANMultiplayer, SupportsInternetMultiplayer, SupportsHotSeat, SupportsPlayByCloud,
ChangeableAfterGameStart, ChangeableAfterPlayByCloudMatchCreate, SortIndex) VALUES

('SDG_REMOVE_CONDEMN_HERETIC', 'LOC_SDG_REMOVE_CONDEMN_HERETIC_NAME', 'LOC_SDG_REMOVE_CONDEMN_HERETIC_DESC',
'bool', 1, 'Game', 'SDG_REMOVE_CONDEMN_HERETIC', 'AdvancedOptions', 1, 0,
1, 1, 1, 1, 1,
0, 0, 331),

('SDG_ONE_CLEANSE_INQUISITORS', 'LOC_SDG_ONE_CLEANSE_INQUISITORS_NAME', 'LOC_SDG_ONE_CLEANSE_INQUISITORS_DESC',
'bool', 1, 'Game', 'SDG_ONE_CLEANSE_INQUISITORS', 'AdvancedOptions', 1, 0,
1, 1, 1, 1, 1,
0, 0, 332) ;

Some technical details to note here:
- "ConfigurationGroup" and "ConfigurationId" are the control variables we're defining. When we're looking to see if the user selected our option or not, we're looking at whether SDG_REMOVE_CONDEMN_HERETIC (in group "Game") is a 0 or 1.
- "Description" is the tooltip that shows up when you hover over the game option
- "GroupId" and "SortIndex" controls where your option shows up on the screen relative to the other setup options
- Setting "Domain" as "bool" means that we're using a check box; if you want to create a drop down box, that's a bit more complicated... open this spoiler for details:
Spoiler :

-- A) you define your own domain here with "FooDomain" in place of "bool"
-- B) then you need to add your drop-down options to another table called DomainValues like so:
Code:
INSERT OR REPLACE INTO DomainValues (Domain, Name, Description, SortIndex, Value) VALUES
('FooDomain', 'LOC_FooDomain_25_NAME', 'LOC_FooDomain_25_DESC', 1, 25),
('FooDomain', 'LOC_FooDomain_50_NAME', 'LOC_FooDomain_50_DESC', 2, 50),
('FooDomain', 'LOC_FooDomain_75_NAME', 'LOC_FooDomain_75_DESC', 3, 75),
('FooDomain', 'LOC_FooDomain_100_NAME', 'LOC_FooDomain_100_DESC', 4, 100) ;
-- C) then you need to populate all the LOC_FooDomain_X_NAME and LOC_FooDomain_X_DESC in your "LOC_GameSetup.sql"



3) In LOC_GameSetup.sql you provide the text strings to populate the LOCs from GameSetup.sql:
Code:
INSERT OR REPLACE INTO LocalizedText
(Tag, Text, Language) VALUES

('LOC_SDG_MOD_NOTE', '[NEWLINE][NEWLINE][COLOR_Red]from mod "DB [ICON_Faith]Soli Deo Gloria[ICON_Faith]"[ENDCOLOR]', 'en_US'),

('LOC_SDG_REMOVE_CONDEMN_HERETIC_NAME', 'Remove Condemn Heretic', 'en_US'),
('LOC_SDG_REMOVE_CONDEMN_HERETIC_DESC', 'Removes the Condemn Heretic action from military units{LOC_SDG_MOD_NOTE}', 'en_US'),

('LOC_SDG_ONE_CLEANSE_INQUISITORS_NAME', 'Inquisitors: Only 1 Cleanse', 'en_US'),
('LOC_SDG_ONE_CLEANSE_INQUISITORS_DESC', 'Inquisitors only get one cleansing charge each, instead of the usual three (and don''t get bonus charges from Mosques or the Exodus of the Evangelicals golden age commemoration){LOC_SDG_MOD_NOTE}', 'en_US') ;


4) Now let's talk about the code that actually carries out these game functions. How do you tell if the user checked "SDG_REMOVE_CONDEMN_HERETIC" or not? This is the part that tripped me up the most and thanks to Gedemon for putting me on the right path.

You can't directly access the game setup variables from the database inside the game itself. It's not like querying, say, the GameCapabilities or GlobalParameters table.

What happens instead is that your modinfo file can selectively execute/include any given sql, xml, or lua file based the user's checkbox.

Therefore, the next thing you need to do is to isolate the code that will execute when the box is checked into its own file or files. In my case that's "SDG_Option_RemoveCondemnHeretic.sql", "LOC_SDG_Option_RemoveCondemnHeretic.sql", "SDG_Option_OneCleanseInquisitors.sql", and "LOC_SDG_Option_OneCleanseInquisitors.sql". If you're doing a drop-down box, you will need to create a file for each drop-down option:
Spoiler :

FooDomain_25.sql
FooDomain_50.sql
FooDomain_75.sql
FooDomain_100.sql
LOC_FooDomain_25.sql
LOC_FooDomain_50.sql
LOC_FooDomain_75.sql
LOC_FooDomain_100.sql


5) Finally, we use the modinfo file to tie it all together:

First, we hook up the GameSetup files to FrontEndActions. (If you're using ModBuddy, it has its own tab separate from In-Game Actions, which is where we usually put things.)
Code:
  <FrontEndActions>
    <UpdateText id="LOC">
      <Properties>
        <LoadOrder>1</LoadOrder>
      </Properties>
      <File>LOC_SDG_GameSetup.sql</File>
    </UpdateText>
    <UpdateDatabase id="GameSetup">
      <Properties>
        <LoadOrder>9999999</LoadOrder>
      </Properties>
      <File>SDG_GameSetup.sql</File>
    </UpdateDatabase>
  </FrontEndActions>


Then we define an ActionCriteria for each of our Game Setup Options. (In ModBuddy you can do this by selecting your file from In-Game Actions, opening the Criteria section, and clicking the "Add" button. Make sure you add all three parts {ConfigurationId, Group, Value} in the Edit Criterion section.)
Code:
  <ActionCriteria>
    <Criteria id="SDG_ONE_CLEANSE_INQUISITORS">
      <ConfigurationValueMatches>
        <ConfigurationId>SDG_ONE_CLEANSE_INQUISITORS</ConfigurationId>
        <Group>Game</Group>
        <Value>1</Value>
      </ConfigurationValueMatches>
    </Criteria>
    <Criteria id="SDG_REMOVE_CONDEMN_HERETIC">
      <ConfigurationValueMatches>
        <ConfigurationId>SDG_REMOVE_CONDEMN_HERETIC</ConfigurationId>
        <Group>Game</Group>
        <Value>1</Value>
      </ConfigurationValueMatches>
    </Criteria>
  </ActionCriteria>

And then the files that conditionally execute get a Criteria tag that matches. (In ModBuddy, you just select your file from In-Game Actions, open the Criteria section, and click the criteria you made above.)
Code:
    <UpdateText id="LOC_SDG_Option_OneCleanseInquisitors">
      <Properties>
        <LoadOrder>9999999</LoadOrder>
      </Properties>
      <Criteria>SDG_ONE_CLEANSE_INQUISITORS</Criteria>
      <File>Options/LOC_SDG_Option_OneCleanseInquisitors.sql</File>
    </UpdateText>
    <UpdateDatabase id="SDG_Option_OneCleanseInquisitors">
      <Properties>
        <LoadOrder>9999999</LoadOrder>
      </Properties>
      <Criteria>SDG_ONE_CLEANSE_INQUISITORS</Criteria>
      <File>Options/SDG_Option_OneCleanseInquisitors.sql</File>
    </UpdateDatabase>


    <UpdateText id="LOC_SDG_Option_RemoveCondemnHeretic">
      <Properties>
        <LoadOrder>1</LoadOrder>
      </Properties>
      <Criteria>SDG_REMOVE_CONDEMN_HERETIC</Criteria>
      <File>Options/LOC_SDG_Option_RemoveCondemnHeretic.sql</File>
    </UpdateText>
    <UpdateDatabase id="SDG_Option_RemoveCondemnHeretic">
      <Properties>
        <LoadOrder>1</LoadOrder>
      </Properties>
      <Criteria>SDG_REMOVE_CONDEMN_HERETIC</Criteria>
      <File>Options/SDG_Option_RemoveCondemnHeretic.sql</File>
    </UpdateDatabase>

If you did these last parts with ModBuddy, you'll want to open up the actual modinfo file that gets generated and compare to the format here. It's very easy to make a mistake in all those Criteria dialog boxes.

Hope this was helpful. Let me know if you have any questions.

Kind regards,
DB
 
Last edited:
Moderator Action: moved to the tutorial section

and thanks !
 
Top Bottom