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

Run a Lua function when game initializes

Discussion in 'Civ5 - SDK / LUA' started by Thalassicus, Oct 29, 2010.

  1. Thalassicus

    Thalassicus Bytes and Nibblers

    Joined:
    Nov 9, 2005
    Messages:
    11,057
    Location:
    Texas
    I've been looking through Events.function calls... having trouble finding something. What's the event for game start/load/initialization/whatever it might be called?
     
  2. rf900

    rf900 Warlord

    Joined:
    Jan 31, 2006
    Messages:
    194
  3. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    ActivePlayerTurnStart won't work, it doesn't start counting until turn 1 apparently. SerialEventStartGame won't work either... but this:

    Code:
    function firstturn ()
    if ( Game.GetGameTurn() == 0 ) then print("Game started.. kinda"); end
    end
    Events.ActivePlayerTurnEnd.Add( firstturn );
    
    works at the end of the player's first turn. i'm still keeping an eye out for a proper game start event, but so far that's the best i've found
     
  4. Thalassicus

    Thalassicus Bytes and Nibblers

    Joined:
    Nov 9, 2005
    Messages:
    11,057
    Location:
    Texas
    Hm, that's what I was worried about... problem is how whenever a save is loaded Lua effects won't be active until the next turn. In the modern era a turn can involve a lot of stuff. :\
     
  5. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    so ActivePlayerTurnStart doesnt count when you start a game from a save?
     
  6. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    oh :lol:

    Code:
    function realstart ()
    	print("Really really just started a game!");
    end
    Events.SequenceGameInitComplete.Add ( realstart );
    
     
  7. Thalassicus

    Thalassicus Bytes and Nibblers

    Joined:
    Nov 9, 2005
    Messages:
    11,057
    Location:
    Texas
    Such a confusing event name! Thank you for finding it.
     
  8. Gedemon

    Gedemon Modder Super Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,820
    Location:
    France
    So you really can use SequenceGameInitComplete ?

    I'm not able to use it, working around, but it would be cleaner...
     
  9. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    yes 123
     
  10. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
    I can't get SequenceGameInitComplete to work either. I've tried adding the lua 3 different ways: modding InGame.xml, replacing InGame.lua, and via mod buddy content tab "InGameUIAddin". All three methods clearly add my custom script, yet attaching a test function to SequenceGameInitComplete does nothing.
     
  11. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    make test.lua, copy paste the example, copy ingame.xml from the vanilla assets, add to ingame <LuaContext FileName="test" ID="test" Hidden="True" /> and then make sure the test mod does OnModActivated-UpdateDatabase-InGame.xml
     
  12. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
    Yeah, that's what I'm say'n. Does nothing when added to SequenceGameInitComplete, but generates output when added to ActivePlayerTurnStart; <shrug>

    You can also add lua files the other two ways I mentioned and tried that thinking it might have something to do with it, but no.

    Are you using FireTuner? I am, so perhaps a limitation of the Lua console?
     
  13. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    yeah i get the print in the liveturner. could it be one of these?

    Code:
    include( "IconSupport" );
    include( "InfoTooltipInclude" );
    include( "InstanceManager" );
    include( "SupportFunctions"  );
    include( "TechButtonInclude" );
    include( "TechHelpInclude" );
    include( "TutorialPopupScreen" );
    
     
  14. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
  15. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
    This is my init screen. Where abouts does the print statement show up for you?

    Spoiler :
    Code:
    Good Morning
    [ Lua State = Main State ]
     InstalledPanel: Refreshing Mods
     InstalledPanel: Refreshing Mods
     InstalledPanel: Refreshing Mods
     InstalledPanel: Refreshing Mods
     InstalledPanel: Refreshing Mods
     Map Script: Generating Map
     Map Script: Generating Plot Types (Lua Pangaea) ...
     Map Script: Setting Plot Types (MapGenerator.Lua)
     Map Script: Setting Plot Types (MapGenerator.Lua)
     Map Script: Setting Plot Types (MapGenerator.Lua)
     Map Script: Setting coasts and oceans (MapGenerator.Lua)
     Map Script: Expanding coasts (MapGenerator.Lua)
     Map Script: Setting Terrain Types (MapGenerator.Lua)
     Map Script: Map Generation - Adding Rivers
     Map Script: Map Generation - Adding Lakes
     Map Script: 3 lakes added
     Map Script: Adding Features (Lua Pangaea) ...
     Map Script: Creating start plot database.
     Map Script: Dividing the map in to Regions.
     Map Script: Map Generation - Dividing the map in to Regions
     Map Script: Choosing start locations for civilizations.
     Map Script: Map Generation - Choosing Start Locations for Civilizations
     Map Script: Normalizing start locations and assigning them to Players.
     Map Script: Placing Natural Wonders.
     Map Script: Placing Resources and City States.
     Map Script: Map Generation - Assigning Luxury Resource Distribution
     Map Script: Map Generation - Placing City States
     Map Script: Map Generation - Choosing sites for City States
     Map Script: All city states assigned.
     Map Script: Map Generation - Placing Luxuries
     Map Script: Map Generation - Placing Strategics
     Map Script: Map Generation - Placing Bonuses
     Map Script: Map Generation - Normalize City State Locations
     Map Script: -------------------------------
     Map Script: Map Generation - Adding Goodies
     Map Script: -------------------------------
     Map Script: Determining continents for art purposes (MapGenerator.Lua)
     CivilopediaScreen: SetSelectedCategory(12)
     CivilopediaScreen: CivilopediaCategory[CategoryTerrain].DisplayList
     CivilopediaScreen: SetSelectedCategory(1)
     CivilopediaScreen: CivilopediaCategory[CategoryHomePage].DisplayList
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\CityPlotManagementPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCommandPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivEnterTerritoryPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\LiberateMinorPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ReturnCivilianPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\AnnexCityPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\BarbarianRansomPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmGiftPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCityTaskPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\GreatPersonPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmPolicyBranchPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivGoldPopup.lua
     
  16. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    just set this up:

    before clicking 'begin your journey'

    Spoiler :

    Code:
    Hi!  Nice to see you again.
     InstalledPanel: Refreshing Mods
     InstalledPanel: nil
     InstalledPanel: Refreshing Mods
     InstalledPanel: nil
     InstalledPanel: Refreshing Mods
     InstalledPanel: nil
     InstalledPanel: Refreshing Mods
     InstalledPanel: nil
     Map Script: Generating Map
     Map Script: Generating Plot Types (Lua Pangaea) ...
     Map Script: Setting Plot Types (MapGenerator.Lua)
     Map Script: Setting Plot Types (MapGenerator.Lua)
     Map Script: Setting coasts and oceans (MapGenerator.Lua)
     Map Script: Expanding coasts (MapGenerator.Lua)
     Map Script: Setting Terrain Types (MapGenerator.Lua)
     Map Script: Map Generation - Adding Rivers
     Map Script: Map Generation - Adding Lakes
     Map Script: 1 lakes added
     Map Script: Adding Features (Lua Pangaea) ...
     Map Script: Creating start plot database.
     Map Script: Dividing the map in to Regions.
     Map Script: Map Generation - Dividing the map in to Regions
     Map Script: Choosing start locations for civilizations.
     Map Script: Map Generation - Choosing Start Locations for Civilizations
     Map Script: Normalizing start locations and assigning them to Players.
     Map Script: Placing Natural Wonders.
     Map Script: Placing Resources and City States.
     Map Script: Map Generation - Assigning Luxury Resource Distribution
     Map Script: Map Generation - Placing City States
     Map Script: Map Generation - Choosing sites for City States
     Map Script: All city states assigned.
     Map Script: Map Generation - Placing Luxuries
     Map Script: Map Generation - Placing Strategics
     Map Script: Map Generation - Placing Bonuses
     Map Script: Map Generation - Normalize City State Locations
     Map Script: -------------------------------
     Map Script: Map Generation - Adding Goodies
     Map Script: -------------------------------
     Map Script: Determining continents for art purposes (MapGenerator.Lua)
     CivilopediaScreen: SetSelectedCategory(12)
     CivilopediaScreen: CivilopediaCategory[CategoryTerrain].DisplayList
     CivilopediaScreen: SetSelectedCategory(1)
     CivilopediaScreen: CivilopediaCategory[CategoryHomePage].DisplayList
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\CityPlotManagementPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCommandPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivEnterTerritoryPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\LiberateMinorPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ReturnCivilianPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\AnnexCityPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\BarbarianRansomPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmGiftPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCityTaskPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\GreatPersonPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmPolicyBranchPopup.lua
     GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivGoldPopup.lua
     test: Really really just started a game!
    


    test.lua contents
    Spoiler :
    Code:
    function realstart ()
    	print("Really really just started a game!");
    end
    Events.SequenceGameInitComplete.Add ( realstart );
    


    ini settings, not sure which it could be so just guessing relevant ones

    Spoiler :

    config

    EnableTuner = 1
    EnableAsserts = 1
    DebugPanel = 1
    MessageLog = 1
    SerializationLog = 1
    LoggingEnabled = 1

    usersettings
    DebugMode = 1
     
  17. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
    No differences on those INI settings. I'm running Win7, direct X 10 &11. You?
     
  18. smellymummy

    smellymummy King

    Joined:
    Jul 31, 2002
    Messages:
    705
    vista, dx9
     
  19. Mannu

    Mannu Warlord

    Joined:
    Sep 23, 2005
    Messages:
    230
    Did you get a prompt to make an exception to the Windows Firewall? I did and allowed it. Before that I couldn't get messages to the tuner from CIV5 at all.

    I'll look and see what rules I have on mine and post them here in the hopes that you (or anyone else) can add them manually.
     
  20. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
    Well, in my allow settings, there are three entries for Civ5, one entry for Civ5 SDK, and one entry for Steam, all being allowed.

    Oh, I'm not using the Win7 home network though. I have an XP machine on the network so can't use it.
     

Share This Page