Modding/Startup Order

From Desynced Wiki

Startup sequence (each step is performed on all active mod packages in dependency order where packages with no dependencies are called first):

  1. Run the entry lua file of all active mod packages
  2. When starting a new game, run the function package:setup_scenario(settings). This function can modify the settings table. This step is skipped when loading a save or joining a multiplayer game.
  3. Load all files set in package:includes and call either package:init_ui() or package:init(). The function init_ui is not called when there is no local player (i.e. on a dedicated servre). Packages with init_ui are allowed to write to local variables defined outside of the function scope.
  4. Call package:post_init()
  5. When starting a new game, run the function package:on_world_spawn()
  6. For the local player or any newly joining multiplayer players, run the function package:get_new_player_faction_id(faction_id) which can return a faction id to be used for that player (only called on server!). The passed faction_id will be nil on the first package this is called on.
  7. When a new player faction is spawned or respawned, run the function package:on_player_faction_spawn(faction, is_respawn, player_faction_num)