Quick Modding Questions Thread

@racha SQLite engine. Usually it provides a token that caused a syntax error. That is how SQL interpreter works.
If you want more info, use .xml files. There is an intermediate layer that provides much more info.
 
Is there a quick way to check if the GS active or not from lua gameplay and UI context? For example creating a river requires riverID parameter for GS and does not work if this parameter exist in case of vanilla and R&F.
 
Is there any way to make it so a particular city-state won't spawn at the start of a new game if a particular civ or leader is in the game?
 
I know about criterias in the modinfo file but this is not the case. I have one script for all expansions but inside I decide which parameter to use when calling the appropriate functions. I've used this code:

Code:
function IsXP2()
    if ( GameInfo.Units_XP2 ~= nil ) then
        --print("Expansion 2 detected");
        return true;
    end
    --print("Expansion 1/none detected");
    return false;
end

But it looks like something isn't right because I've got this report from the user: "I cannot select 1 in the combobox and I cannot input any value there. I currently have R&F expansion but no GS." Combobox is hidden based on the IsXP2() return value.
 
I know about criterias in the modinfo file but this is not the case. I have one script for all expansions but inside I decide which parameter to use when calling the appropriate functions. I've used this code:

Code:
function IsXP2()
    if ( GameInfo.Units_XP2 ~= nil ) then
        --print("Expansion 2 detected");
        return true;
    end
    --print("Expansion 1/none detected");
    return false;
end

But it looks like something isn't right because I've got this report from the user: "I cannot select 1 in the combobox and I cannot input any value there. I currently have R&F expansion but no GS." Combobox is hidden based on the IsXP2() return value.

I believe one of the features of GS is accessing gameinfo directly, so if you have R&F you cannot access it. Maybe someone that is more into Lua scripts confirms this.
 
@Zur13 In UI the best way is:
Code:
-- Expansions check
local bIsRiseAndFall:boolean = Modding.IsModActive("1B28771A-C749-434B-9053-D1380C553DE9"); -- Rise & Fall
print("Rise & Fall :", (bIsRiseAndFall and "YES" or "no"));
local bIsGatheringStorm:boolean = Modding.IsModActive("4873eb62-8ccc-4574-b784-dda455e74e68"); -- Gathering Storm
print("Gathering Storm:", (bIsGatheringStorm and "YES" or "no"));
 
Modding is not available in Gameplay, so I use
Code:
-- Expansions check
local bIsRiseFall:boolean = (Game.ChangePlayerEraScore ~= nil); -- Rise & Fall
print("Rise & Fall", (bIsRiseFall and "YES" or "no"));
local bIsGatheringStorm:boolean = (GameClimate ~= nil);  -- Gathering Storm
print("Gathering Storm:", (bIsGatheringStorm and "YES" or "no"));
 
I would think 'CITY_FOLLOWS_PANTHEON_REQUIREMENTS' would require the captured city follows the 'OP_ARES' pantheon

This is probably a detailed enough question you'd likely have better luck asking it as a help request thread


Figured it out. Just needed to mimic the Hellenistic Fusion trait to get a goody-hut-like bonus on city capture. Here's the result:

Code:
INSERT INTO BeliefModifiers (BeliefType, ModifierID) VALUES
                            ('OP_ARES', 'OP_ARES_ON_CITY_CAPTURE') ;
INSERT INTO Modifiers (ModifierId, ModifierType) VALUES
                      ('OP_ARES_ON_CITY_CAPTURE', 'MODIFIER_PLAYER_CAPTURED_CITY_ATTACH_MODIFIER') ;
INSERT INTO ModifierArguments (ModifierId, Name, Value) VALUES
                              ('OP_ARES_ON_CITY_CAPTURE', 'ModifierId', 'OP_ARES_FAITH_FROM_CAPTURE') ;

INSERT INTO Modifiers (ModifierId, ModifierType, RunOnce, Permanent) VALUES
                      ('OP_ARES_FAITH_FROM_CAPTURE', 'MODIFIER_PLAYER_GRANT_YIELD', 1, 1) ;
INSERT INTO ModifierArguments (ModifierId, Name, Value) VALUES
                              ('OP_ARES_FAITH_FROM_CAPTURE', 'Amount', 100),
                              ('OP_ARES_FAITH_FROM_CAPTURE', 'Scale', 1),
                              ('OP_ARES_FAITH_FROM_CAPTURE', 'YieldType', 'YIELD_FAITH') ;
 
1. Events.Combat returns a table. Does anyone know the more formalized structure of this table? I am having a fairly hard time understanding it myself, and have not seen any mods utilizing it as reference.

2. Is writing to disk possible via lua? Has anyone implemented user options without this? It seems FireTuner disallows this, and several other functions like pcall(), but it is possible I'm missing something.

3. Do City Propety Values actually do anything?

4. I probably know the answer to this, but is there any way to trigger a specific Modifier via Lua?
 
Ad. 1. There is a tab "Events.Combat" in @Gedemon 's old spredsheet with Lua objects that you might find very helpful.
Ad. 2. You can only write to lua.log by using print().
Ad. 3. I've seen it used once somewhere in the code, you need to look for it, I can't remember where it was.
Ad. 4. In GS there is a possibility to attach a modifier to a Player and a City (AttachModifierByID). Black Death scenario is using that. You can't detach them however.
 
Object:GetProperty()
Syntax:
Code:
Player:GetProperty(sPropertyName)
Arguments: Text property name
Return Type: varies to conform to the value stored previously via a matching Object:SetProperty(args) for the text property name.
Use: Returns the previously-stored value as mentioned in the Return Type explanation.


Object:SetProperty()
Syntax:
Code:
Player:SetProperty(sPropertyName, Value)
Return Type: NA
Arguments: sPropertyName
A text string which should be unique to the mod and file(s) where used​
Value: Can be any reasonable value: integer, boolean, etc.
Lua tables most likely will have to be converted to “serialization”, which is a way to describe a method by which lua tables are converted to a text string.​
Use: Allows persisitent storage of data between save and reload of a game under the correct usage, across lua contexts. This is the way Firaxis appears to use the SetProperty() & GetProperty() methods. See the Black Death Scenario lua files for more actual usage examples.

Plots, Cities, Units, and Players can all use these two methods. Not sure if they are all valid in both Gameplay state and UI state.
 
I appreciate the replies, which seem spot on for what I needed.
Somehow I have utterly missed the Events.Combat tab in that spreadsheet despite keeping it as reference. That exactly what I was looking for.

The SetProperty/SetValue's persistence through game loads is very powerful and useful to know. The post you mentioned Zur, also seems to use it for User Options. This is very much what I wanted.

I don't suppose there is a more full list of that function documentation for other functions/properties, @LeeS?

For file loading, is there a way to suppress a file if a certain configuration is set? For example, let's say if the UserConfiguration.IsQuickCombat set to false, I want to load one set of SQL/Lua files, else a different set of files entirely.
 
The documentation is really only what we've been able to put together so far. "We" being the community of modders, but most esp Gedemon, ChimpanG, and Chrisy15. See Chimp's spreadsheet ( https://docs.google.com/spreadsheet...6oDAtqNuXVW_2zHRn13epMYXY/edit#gid=1391246980 ) ChimpanG has another version of this spreadsheet available ( https://docs.google.com/spreadsheet...D_xTTld4sFEyMxrDoPwX2NUFc/edit#gid=1391246980) but I just generally use his older version.


So far as I know you cannot "criteria" User Configuration, so you cannot use it control what set of information is sent to the SQL database. You can get the setttings for the User Configuration at least on the FrontEnd and I think on the InGame side within lua but I don't think you'd be able to criteria those settings to determine which lua file is loaded. You'd have to get the value and then run one part of a file if the setting is off and another if the setting is on. If the lua file is a GameplayScript you might not be able to directly access UserConfiguration.GetValue(something, something, something) so might need to retrieve this data from a User Interface context and then share that value with a GameplayScript.
 
Hello!

I'm trying to start modding with very simple edition: encrease amount of charges for builders and change strategic resourse for modern armor.
But the mod doesn't work. I tried new game, saved game, switch off any other mods, tried different syntaxis variants...
I see my mod in the game, can switch it on, but no effect.

Code:
<GameInfo>
    <Units>
        <Update>
            <Where UnitType="UNIT_BUILDER"/>
            <set>
                <BuildCharges>7</BuildCharges>
            </set>
        </Update>
        <Update>
            <Where UnitType="UNIT_MODERN_ARMOR"/>
            <Set StrategicResource="RESOURCE_OIL"/>
        </Update>
    </Units>
</GameInfo>

It's so simple, but what is wrong?
Please help.

PS. If I change the files without mod then all works.
 
Last edited:
LeeS, thanks. I fixed "Set", but anyway nothing happens.

Maybe, I do something wrong in Tools?

I chosen File → New → Project… → Empty Mod
And nothing edit there, just add XML-file with code above.
After that I pressed “Build solution”.

Mod.jpg
 
You have to create an action, with an action-type of "UpdateDatabase", and add the file to the list of files to be enacted by the action. And the action must be under InGameActions.

There's a step-by-step example of how to add a new building to the game in this thing here, in the chapter called "Creating a Simple Mod Using Modbuddy". The Modbuddy procedures you need are indentical to that shown for adding a new building to the game.
 
Back
Top Bottom