Jump to content

Add event listener associated with a mod?


RageLeague

Recommended Posts

I am trying to add global event listeners for mods. Initially, I provided a "OnGameStart" function, which adds the mod as an event listener for the global events. However, I noticed that all event listeners are cleared whenever the game tries to load up a new run, which would remove the event listener on the mod. As far as I am aware, there is no hooks when the game is loaded for mods to do anything. Is there a way in the API that allows mods to hook up to global events? If not, I will probably overwrite some game code or something.

Link to comment
Share on other sites

  • Developer

You are correct with regards to OnGameStart.

Trying to think of the right place -- possibly at the end of Game:ResumeGame?   ResumeGame is called after a save game is loaded, or a new game is started.  I could add a mod invocation there if that seems reasonable.

Link to comment
Share on other sites

On 9/29/2021 at 6:23 PM, rooks said:

You are correct with regards to OnGameStart.

Trying to think of the right place -- possibly at the end of Game:ResumeGame?   ResumeGame is called after a save game is loaded, or a new game is started.  I could add a mod invocation there if that seems reasonable.

There would be a window of opportunity between event handlers are cleared and event handlers are re-added. If we add it at the end of Game:ResumeGame then the modded event handlers cannot listen to events during the game state loading process. Which could lead to problems for mods (specifically my mod where I need to filter out specific work positions depending on the campaign, using a custom event).

While we are on the topic of work positions, they are always enabled by default in all campaigns, and there are no good ways of adding work positions during a game. Can we make it so that either campaigns can somehow manually select which work position to add from the work position defs, or somehow add work positions not defined already in a campaign?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...