1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Lua Objects

Discussion in 'Civ6 - Modding Tutorials & Reference' started by Gedemon, Oct 23, 2016.

  1. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,920
    Location:
    France
    I've not managed to use it to override the AI yet, as it seems to move its units just after their moves are (re)initialized but before the corresponding event is fired...
     
    Gleb Bazov likes this.
  2. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,920
    Location:
    France
    I've also added (in the second post on first page) the code I use in a new action button in Firetuner to get the Events arguments values.
     
    Gleb Bazov likes this.
  3. GeneN

    GeneN Chieftain

    Joined:
    Apr 11, 2017
    Messages:
    16
    Gender:
    Male
     
  4. GeneN

    GeneN Chieftain

    Joined:
    Apr 11, 2017
    Messages:
    16
    Gender:
    Male
    I'm just starting my Civ modding adventure and would like to understand how to set up and use the FireTuner in Civ VI. Could someone direct me to something akin to a User Manual?
     
  5. CivilizationAce

    CivilizationAce Chieftain

    Joined:
    Jan 17, 2017
    Messages:
    236
    Gender:
    Male
    There's no such thing. Welcome, mushroom.

    P.S. If you have a question it's best to post a new question, not a reply.

    P.P.S. Before anyone points out that I do the same thing, I know that. It's a bad habit I'm trying to break.
     
  6. Superhai

    Superhai Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    18
    Location:
    Oslo, Norway
    I am figuring out modding for myself, and made notes of most of the events, because I want to make a new autoplay mod where more detailed info will be available throughout the "set". I thought I could share it, I am not sure how many are already known, and I have not made any effort to make "proper" typenames, but I think it should be sufficiently understandable, and may save someone the effort to find out themselves.
     

    Attached Files:

  7. GeneN

    GeneN Chieftain

    Joined:
    Apr 11, 2017
    Messages:
    16
    Gender:
    Male
    Thanks for the welcome and the tip.
    In the dark. Well fertilized.
    A journey. Not a destination.
     
  8. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,266
    Gender:
    Male
    Location:
    Warsaw
    @Gleb Bazov How did you encounter those Events? In my game they do not exist (except CityPopulationChanged).
     
  9. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,266
    Gender:
    Male
    Location:
    Warsaw
    integer A & integer B are district owner and district ID
    Hash is command - value from CityCommandTypes enumeration
    integer C - additional Data, command specific

    HashA - can be decoded via Types, it is ERA_xxx
    HashB - it is hash from Civilization table
    integerB - it is supposed to indicate Previous Attempts but I've never managed to get here something else than 0
     
  10. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,920
    Location:
    France
    Those are Game Events, like : GameEvents.CityBuilt

    CityPopulationChanged exist as an event and game event, someone from Firaxis team may have required one for a DLC scenario (they seem to add those as GameEvents), and it was added by a programmer, not knowing it was already available in Events (or maybe it fires at a different time)
     
  11. CivilizationAce

    CivilizationAce Chieftain

    Joined:
    Jan 17, 2017
    Messages:
    236
    Gender:
    Male
    At least one of the contexts is on-the-map animation time, right?

    Is there a list of contexts, what they're for, and timing issues that arise from them? I ask because a) I want to know and b) In my mod I run most of my code in InGame context and only switch to the default context that AddGameplayScripts uses to create a unit, and I wonder if there are any consequences of using InGame or whether I should switch to the default for most of the code and only use InGame sparingly.
     
  12. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,266
    Gender:
    Male
    Location:
    Warsaw
    I looked through GameEvents some time ago and they were all the same as Events. I assumed that they exist for some kind of backward compatbility. So, all standard game events are available via Events and all user-defined events via LuaEvents. Although GameEvents can be different than Events, what a surprise... Well, you can learn something new here everyday :)
     
  13. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,920
    Location:
    France
    GameEvents could be used for user-defined events, not sure the following still work:

     
    Infixo likes this.
  14. Craig_Sutter

    Craig_Sutter Chieftain

    Joined:
    Aug 13, 2002
    Messages:
    2,719
    Gender:
    Male
    Location:
    Seoul, South Korea
    I have to confess, I am really having a hard time figuring this all out. I got somewhat comfortable modding in Civ 5 lua, but this is a different animal.

    In any case, I have "stolen" some code from YNAMP files that is supposed to print out the map plots of a civ6 map file to be used in a map script.

    I did this in Civ 5 using similar code with "Events.SequenceGameInitComplete.Add(ExportMap)" as the hook.

    In all the documentation I have seen, this event is not evident, so I used the following code:
    Code:
    ----------------------------------------------------------------------------------------
    -- Export a complete civ6 map to Lua.log
    ----------------------------------------------------------------------------------------
    function ExportMap()
        local iPlotCount = Map.GetPlotCount();
        for iPlotLoop = 0, iPlotCount-1, 1 do
            local bData = false
            local plot = Map.GetPlotByIndex(iPlotLoop)
            local NEOfCliff = 0
            local WOfCliff = 0
            local NWOfCliff = 0
            if plot:IsNEOfCliff() then NEOfCliff = 1 end
            if plot:IsWOfCliff() then WOfCliff = 1 end
            if plot:IsNWOfCliff() then NWOfCliff = 1 end
            local NEOfRiver = 0
            local WOfRiver = 0
            local NWOfRiver = 0
            if plot:IsNEOfRiver() then NEOfRiver = 1 end -- GetRiverSWFlowDirection()
            if plot:IsWOfRiver() then WOfRiver = 1 end -- GetRiverEFlowDirection()
            if plot:IsNWOfRiver() then NWOfRiver = 1 end -- GetRiverSEFlowDirection()
            print("MapToConvert["..plot:GetX().."]["..plot:GetY().."]={"..plot:GetTerrainType()..","..plot:GetFeatureType()..","..plot:GetContinentType()..",{{"..NEOfRiver..","..plot:GetRiverSWFlowDirection().. "},{"..WOfRiver..","..plot:GetRiverEFlowDirection().."},{"..NWOfRiver..","..plot:GetRiverSEFlowDirection().."}},{"..plot:GetResourceType(-1)..","..tostring(1).."},{"..NEOfCliff..","..WOfCliff..","..NWOfCliff.."}}")
        end
    end
    
    Events.PlayerEraChanged.Add(iPlayer, iEra)
    --Events.SequenceGameInitComplete.Add(ExportMap)
    However, my log did not print the info... I am not certain what I have done wrong. In the mod info file, I have added the file as a script component...

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Mod id="cdf37c94-4b94-4351-8f83-6a1674ba542a">
    <Properties>
    <Name>Custom Maps</Name>
    <Stability>Final</Stability>
    <Teaser>Custom Map Operating Mod</Teaser>
    <Description>A mod to test and record custom map information</Description>
    <Authors>Craig</Authors>
    </Properties>
    
    <Settings>
        <Custom id="CM_SETTINGS">
            <Items>
                <File>CM_Config.xml</File>
            </Items>
        </Custom>
        <Map id="CM_MAP">
            <Properties>
                <Group>StandardMaps</Group>
                <Name>Custom Map</Name>
                <Description>Test Map</Description>
            </Properties>
            <!--add the map file in Maps subdirectory-->
            <Items>
                <File>Maps/Northwest_Europe_135x81_Map.Civ6Map</File>
            </Items>
        </Map>
    </Settings>
    
    <Components>
        <GameplayScripts>
            <Items>
                <File>Scripts/Custom Map Export.lua</File>
            </Items>
          </GameplayScripts>
        <UpdateDatabase />
    </Components>
    
    <Files>
        <!--This part is very simple, just make sure the filenames all match up-->
        <File>Maps/Northwest_Europe_135x81_Map.Civ6Map</File>   
        <File>CM_Config.xml</File>
        <File>Scripts/Custom Map Export.lua</File>
    </Files>
    </Mod>
    What am I doing wrong, please? If I can just figure out how event hooks and modinfo files interact to run lua, I can figure the code out from there.

    Thanks.
     
  15. Craig_Sutter

    Craig_Sutter Chieftain

    Joined:
    Aug 13, 2002
    Messages:
    2,719
    Gender:
    Male
    Location:
    Seoul, South Korea
    Oops, I see I didn't call the function from the event... I have to run see if it works.

    In any case, does "SequenceGameInitComplete" exist?

    PS The player era change event does work... I would still rather use an event that just goes off once at the beginning of the game.
     
    Last edited: Apr 29, 2017
  16. Infixo

    Infixo Warlord

    Joined:
    Jan 9, 2016
    Messages:
    2,266
    Gender:
    Male
    Location:
    Warsaw
    Probably one of those below.
    Events.AppInitComplete
    Events.GameViewStateDone
    Events.LoadGameViewStateDone
    Events.LoadScreenClose
    Events.LoadScreenContentReady
    Events.MainMenuStateDone
    I usually use LoadScreenClose when not bothering with save files.
    But, as I understand, you want to basically print some map info. Entire map data is available when your script is initialized, i.e. you can run your function in your mod's Initialize.
     
    Craig_Sutter likes this.
  17. Craig_Sutter

    Craig_Sutter Chieftain

    Joined:
    Aug 13, 2002
    Messages:
    2,719
    Gender:
    Male
    Location:
    Seoul, South Korea
    Events.LoadScreenClose worked perfectly for my needs. Now I have map data, I have to figure out how to make it into a script... which leads to a whole new set of questions being asked in another thread :).

    Thanks.
     
  18. Gleb Bazov

    Gleb Bazov Chieftain

    Joined:
    Feb 13, 2017
    Messages:
    176
    Gender:
    Male
    Dear all, a question, specifically for Gedemon, whose excellent work I am trying to apply in my own modding. I have tried to use the Serialize.lua / SaveLoad method that Gedemon designed, most with success. However, I can only keep the saved data while the game application is running. In other words, saved tables will persist if I don't quit Civ 6. They load, save and reload properly. However, as soon as I quit the main application (to desktop) the saved table data is gone, without a trace. Is this just an impregnable limitaiton of the Civ 6 lua or am I doing something completely wrong? Is there a way to have the saved data persist after the game application is closed?

    Kind thanks for any advice! I've been breaking my head over this for days.

    Gleb
     
  19. Gleb Bazov

    Gleb Bazov Chieftain

    Joined:
    Feb 13, 2017
    Messages:
    176
    Gender:
    Male
    HOORAY! I got it working! Much thanks, Gedemon! Bravo :)

    It was my own error in the end and I tracked it down.

    Cheers!
     
  20. Atlas627

    Atlas627 Chieftain

    Joined:
    Aug 25, 2011
    Messages:
    2,484
    Sorry if this has been answered before, but has this been updated since the Spring Patch? If not, we are probably about to have another patch very soon that might be worth waiting for.
     

Share This Page