Quick Modding Questions Thread

Wow... I never knew it was that bad... I only thought ReplaceUIScript simply runs something to override them. Pretty sure last time I used ReplaceUIScript, it only changes what I need to change.

What is the proper way to do that then? I need to get unit's level, which only available in ContextUI, then I plan to use LuaEvents to communicate with Script context.

If you need your own UI and not replace some base game UI element you may add your own UI:

Code:
<AddUserInterfaces id="UI">
      <Properties>
        <Context>InGame</Context>
        <LoadOrder>99000</LoadOrder>
      </Properties>
      <File>CTE_UI.xml</File>
    </AddUserInterfaces>

You need a pair of UI files with the same name in your project like this:
CTE_UI.lua
CTE_UI.xml

XML may have simple structure:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Context Name="CmeCtx">
</Context>
 
Thanks. I saw similar structure in the Cheat Panel mod. Somehow I was able to make it run. I believe mod structure change is not updated every time a map is loaded. Took me 2 or 3 tries before it works. Thanks a lot!
 
You have replaced a lot of game code which is located in file InGame.lua with few of your functions. This is bad approach in general and I'd suggest you to find a better way to integrate your mod but if you want to stick with this approach you should copy the content of InGame.lua into your script file and append your code after the original code.
I'd suggest to simply use an "include" of the replaced UI file before the additional/replacing code.

That way no need to update after each patch affecting the original file.
 
I'd suggest to simply use an "include" of the replaced UI file before the additional/replacing code.

That way no need to update after each patch affecting the original file.

Yes this is correct. But it should be used only when replacing some script is really needed because this operation makes incompatible the mods which are replacing the same script.
 
Yes this is correct. But it should be used only when replacing some script is really needed because this operation makes incompatible the mods which are replacing the same script.
I was expecting the engine to be able to handle multiple <ReplaceUIScript> for the same Lua file.

That would also mean that mods can't use this method on files that are already edited this way by the expansions.
 
I was expecting the engine to be able to handle multiple <ReplaceUIScript> for the same Lua file.

That would also mean that mods can't use this method on files that are already edited this way by the expansions.

As far as I understand the expansions are using file naming to extend scripts like:

orig.lua

orig_exp2.lua
include("orig")

But if you are using it in mods:

orig_mod1.lua
include("orig_exp2")

and

orig_mod2.lua
include("orig_exp2")

Only one moded version will be active and code of one of the mods will be lost. I didn't check it but I always thought it works like that because in mod you are include the expansion version and not the version from the other mod.
 
OK, so it's only helpful when the base file is updated.

Reparent still the way to go for maximum compatibility then.

I'll do some test, IIRC in my mods I use
orig_mod.lua
include("orig")

Not
orig_mod.lua
include("orig_exp2")

And was expecting "orig" to be the merged version when XP2 is active
 
OK, so it's only helpful when the base file is updated.

Reparent still the way to go for maximum compatibility then.

I'll do some test, IIRC in my mods I use
orig_mod.lua
include("orig")

Not
orig_mod.lua
include("orig_exp2")

And was expecting "orig" to be the merged version when XP2 is active

You can check my Spy City Tooltip mod https://steamcommunity.com/sharedfiles/filedetails/?id=1674987878

I think the best way is to use proxy file if you want your mod to be compatible with both vanilla and expansion version of the script but only if the functions you want to overide are not marked as local in the game script.
 
And was expecting "orig" to be the merged version when XP2 is active
It is not. The original file is untouched, all changes needed for expansions are introduced in separate files via ReplaceUIScript.
The only time that the original base file is modified is when the patch changes something in the base game.
 
To get database entry hash value in lua script I use this.
Code:
GameInfo.Notifications["NOTIFICATION_BARBARIANS_SIGHTED"].Hash
Why it does not work for my custom entries?
 
Last edited:
Any simple way to make Apostle gains EXP in theological combat or it's coded that way and we need to intervene by LUA code?
 
So, a question regarding modding a mod. I would like to change some of the values for units included in Moar Units, but using XML doesn't seem to work correctly. I am guessing that the problem is because the added units are not contained in the "units" database, so it doesn't seem to take. Can anyone walk me through making a change to some of the values of units added in mods without the need to edit the original XML files?
 
So, a question regarding modding a mod. I would like to change some of the values for units included in Moar Units, but using XML doesn't seem to work correctly. I am guessing that the problem is because the added units are not contained in the "units" database, so it doesn't seem to take. Can anyone walk me through making a change to some of the values of units added in mods without the need to edit the original XML files?

You need to make sure your mod loads after Moar Units, as there is no such entry before that. I don't know about XML but it seem tedious to me, but if it's SQL, simply use something like

Code:
UPDATE Units SET MovementSpeed = 4 WHERE UnitType = 'UNIT_FOO';

About the load order, you should check in the modinfo file, there should be a LoadOrder property for their database update. You just need to add the same thing to your mod and increase the order number and make sure it's higher than theirs.
 
Quick question about city projects, is it possible to make them only available once per city?
 
To get database entry hash value in lua script I use this.
Code:
GameInfo.Notifications["NOTIFICATION_BARBARIANS_SIGHTED"].Hash
Why it does not work for my custom entries?
It's probably related to why
Code:
GameInfo.Notifications["NOTIFICATION_BARBARIANS_SIGHTED"].RowID
will give you the unmodded value in the database for "RowID" and not the proper value after mods make changes to the database. I always use
Code:
GameInfo.Notifications["NOTIFICATION_BARBARIANS_SIGHTED"].Index
as this always conforms properly to alterations made by mods to the database, and "Index" functions identically anywhere I have ever tried it to using the "Hash" number Firaxis often uses.

The other thing to be careful of is that if a "thing" is not listed in table <Types> then as I recall it will not have a "hash" number assigned to it, and I think "Index" will also not work properly.
 
Last edited:
Hi,

I am new to world builder, as a person that constantly restarts for a great map, I am really looking forward to using this tool.

I have created my map & managed to add my start position for (Japan) but when I add other civs using the advanced options, I start the game it says I have had a domination victory on the first go?

can someone explain what I am doing wrong? I am guessing I am not selecting the AI civs correctly. is there away for them to auto spawn? or start in a desired location?

Thanks in advance.
 
You need to make sure your mod loads after Moar Units, as there is no such entry before that. I don't know about XML but it seem tedious to me, but if it's SQL, simply use something like

Code:
UPDATE Units SET MovementSpeed = 4 WHERE UnitType = 'UNIT_FOO';

About the load order, you should check in the modinfo file, there should be a LoadOrder property for their database update. You just need to add the same thing to your mod and increase the order number and make sure it's higher than theirs.

So, I have tried any number of ways to affect the characteristics of a unit. The load order in my modinfo file is 9999. This is the code I have:

Code:
<GameInfo>
    <GlobalParameters>

        <Replace Name="COMBAT_ARMY_STRENGTH_MODIFIER" Value="42" />

        <Replace Name="COMBAT_CORPS_STRENGTH_MODIFIER" Value="25" />

    </GlobalParameters>
</GameInfo>
<GameData>
    <Units>
        <Update>
            <Where UnitType="UNIT_WARRIOR"/>
            <Set BaseMoves="25"/>
        </Update>
    </Units>
</GameData>

Now, the interesting thing here is that the army and corps strength modifiers DO change, so clearly the file is being properly loaded. However, no matter how I manipulate the unit update, I can't affect the base movement of the warrior unit. I seriously have no idea of what I am doing wrong, because according to the stuff I have read, the code above should change things, but it doesn't.

David
 
So, I have tried any number of ways to affect the characteristics of a unit. The load order in my modinfo file is 9999. This is the code I have:

Code:
<GameInfo>
    <GlobalParameters>

        <Replace Name="COMBAT_ARMY_STRENGTH_MODIFIER" Value="42" />

        <Replace Name="COMBAT_CORPS_STRENGTH_MODIFIER" Value="25" />

    </GlobalParameters>
</GameInfo>
<GameData>
    <Units>
        <Update>
            <Where UnitType="UNIT_WARRIOR"/>
            <Set BaseMoves="25"/>
        </Update>
    </Units>
</GameData>

Now, the interesting thing here is that the army and corps strength modifiers DO change, so clearly the file is being properly loaded. However, no matter how I manipulate the unit update, I can't affect the base movement of the warrior unit. I seriously have no idea of what I am doing wrong, because according to the stuff I have read, the code above should change things, but it doesn't.

David

And, of course, as soon as I said this, I tried one more thing and it worked. I got rid of the GameData block and put everything into GameInfo, like this

Code:
<GameInfo>
    <GlobalParameters>

        <Replace Name="COMBAT_ARMY_STRENGTH_MODIFIER" Value="42" />

        <Replace Name="COMBAT_CORPS_STRENGTH_MODIFIER" Value="25" />

    </GlobalParameters>
    <Units>
        <Update>
            <Where UnitType="UNIT_WARRIOR"/>
            <Set BaseMoves="25"/>
        </Update>
    </Units>
</GameInfo>

and everything suddenly magically worked, although I could swear that I did exactly the same thing like a week ago, and it didn't take. I don't know, I'm just a stupid programmer.

David
 
Are there any good sources to start learning "lua"? I want to make a new unit that I can't just use xml or sql for
 
Back
Top Bottom