Stellaris

Stellaris

Dynamic Mod Menu [3.10.*]
 This topic has been pinned, so it's probably important
TheFlyingPotato  [developer] 17 Jun, 2021 @ 2:42pm
For modders: how to add a button for your mod in DMM
Welcome! The configuration is really straightforward, don't be afraid ;)
DMM works in 2 part:
  1. Your mod needs to register itself (give a unique flag and the text that should displayed on the button)
  2. You need to add a country_event and subscribe it to an on_action
OldEnt made an example template[github.com] if you want to see what it looks like.

Registering the mod
At game start and on save game load (use on_actions), execute this effect:
dmm_register_mod = { DMM_NAME = my_amazing_mod.22 DMM_FLAG = my_amazing_mod_unique_flag }
Replace "my_amazing_mod.22" by what you want displayed on the button. I highly recommend using a localisation key.
Replace "my_amazing_mod_unique_flag" by something that is unique to your mod. I highly recommend using at least the full name of the mod ("origin_mod" is not enough!).
DO NOT put any spaces. You've been warned! If you want spaces in the text displayed on the button, you have to use a localisation key.

Adding the event and the on_action
Simply add this event (as usual don't forget the namespace):
country_event = { id = my_amazing_namespace.111 is_triggered_only = yes hide_window = yes trigger = { from = { has_leader_flag = my_amazing_mod_unique_flag } } immediate = { # open my settings menu } }
Of course reuse the same flag name you set before. In the immediate, you can for example fire the event that opens up your settings menu.

And subscribe the previous event to this on_action:
dmm_mod_selected = { events = { my_amazing_namespace.111 } }

And that's it! Yes! 22 lines of code only! Now you don't need an edict anymore!
If you don't want to add a hard dependency on DMM (ie you don't want to set it as required), but only want to add a soft dependency, you can add an edict (that fires your settings menu) that is only visible if DMM is not installed.
To do that, put in the potential clause :
NOT = { has_global_flag = dmm_installed }

Here's a bunch of utility stuff:
If for you want to unregister your mod (for example before the player uninstall it), simply use dmm_deregister_mod = { DMM_FLAG = my_amazing_mod_unique_flag }.
You can check if your mod is registered using dmm_is_registered_mod = { DMM_FLAG = my_amazing_mod_unique_flag }.

Hide the button
If you want to hide the button for some reason (crisis happened so remove crisis spawn), you can use
dmm_hide_button_all = { DMM_FLAG = my_amazing_mod_unique_flag }
To show it, use
dmm_show_button_all = { DMM_FLAG = my_amazing_mod_unique_flag }
If you want to inverse the show/hide for a specific country, then scope to that country and use
dmm_add_button_exception = { DMM_FLAG = my_amazing_mod_unique_flag }
To remove it, simply use
dmm_remove_button_exception = { DMM_FLAG = my_amazing_mod_unique_flag }
If you hide it to all and have an exception on a country (the host of the game for example), then only that country will see the button. Remember that AIs can't access DMM anyway.
Last edited by TheFlyingPotato; 17 Jun, 2021 @ 2:43pm