• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

anniz00

Recruit
2 Badges
Feb 15, 2023
2
1
  • Crusader Kings II
  • Stellaris
Hey! I’m trying to make a mod where your tax income differs over the years due to weather fluctuations.To do this I intend using the already existing functions of prosperity and depopulation. I’ve found the functions increase_prosperity_effect, decrease_prosperity_effect, increase_depopulation_effect and decrease_depopulation_effect but don’t know how to implement them in my code. Although I want to put the effect on all owned provinces, I’m guessing you need to tie them to a certain province in some way? Should I implement them to a province_event? If so, how do I make sure that the function happens to all my owned provinces? Also, how do you even implement an effect, is there some documentation about it? I’m aware this is a broad question, but I really don’t know where to start.
 
  • 1Like
Reactions:
The scripted_effects you found increase/decrease prosperity by an entire step all at once. This is different to what normally happens in the base game: every province has a hidden "prosperity_value" variable; events modify this value up or down; if the value exceeds (or falls below) certain thresholds then the visible modifier is changed (eg. the visible "prosperity 1" province modifier corresponds to 100 <= prosperity_value < 250).

If you want to alter the prosperity of all owned provinces, you need to use the prosperity effect (or alter the prosperity value) from inside the relevant province scope.

For example, this is how you would increase the prosperity of all of ROOT's demesne provinces by one level:

Code:
ROOT = {
   any_demesne_province = {
      increase_prosperity_effect = yes
   }
}

...and this is how you would increase the hidden prosperity value of all of ROOT's demesne by 10 points:

Code:
ROOT = {
   any_demesne_province = {
      change_variable = { which = prosperity_value value = 10 }
   }
}

---

However, I don't think modifying prosperity is a good way to achieve your desired effect. Apart from anything else, this will interfere with the long-term development of prosperity across the map.

---

The simplest option would be to alter the mild_winter / normal_winter / severe_winter modifiers in ...\common\static_modifiers\static_modifiers.txt . For example, you could insert local_tax_modifier = -0.10 for mild_winter, -20% for normal winter, -50% for severe winter.

The advantage of this approach is that winter seems to be optimised inside the game engine, so you won't be adding any additional CPU load. Also, the game's winter functionality means that different regions have different seasons - you wouldn't need to do this manually. However, only winter is supported - you can only distinguish between not-winter and mild/normal/severe winter.

However, if you wanted to implement a cyclic approach, you could do this by applying a permanent positive modifier and makinig the negatives in winiter larger. For example, if you wanted +20% in not-winter and -10%/-20%/-50% in mild/normal/severe winter:
  • For every province that can have winter, add a province modifier (on game start) that gives +20% tax, with duration -1 (ie. forever)
  • Change the modifiers for mild/normal/severe winter to also include -30%/-40%/-70% tax

---

The more-complex alternative would be to write your own events that trigger several times a year that update province modifiers in every province in the game. This would be fully flexible, but CPU-intensive. You would also need to figure out what to do about regions with extremely different climates (eg. Mongolia vs Morocco), because they probably don't have the same seasons.
 
  • 1Like
Reactions:
@jonjowett
Thank you so much for your reply, and thank you especially for naming the alternative of using the winter modifiers. I'm planing on doing it that way instead, however, I'd also like to finish the mod I have begun writing with the prosperity/depopulation events.

Where do you implement the ROOT function you typed out? Should it be put directly in a character_event? Or maybe within immediate? And also, is it correct to use decrease_prosperity_effect the same way as increase?

I'm sending you a part of my code where I've tried implementing your code but can't make it work. Earlier in the code a randomizer is used to decide whether the character event increasing or decreasing prosperity should be triggered.

Code:
#DECREASE PROSPERITY INCASE OF BAD HARVEST - RUNS WHEN TRIGGERED
character_event = {
    id = TAX.4
    hide_window = yes
    is_triggered_only = yes
   
    trigger = { #Prevents TAX.4 from looping
        NOT = {
            has_character_flag = loop_gone
        }
    }

    immediate = {
        set_character_flag = loop_gone
        character_event = { #Restarts the whole function in a year
                    id = TAX.1 days = 365
                }
    }
   
    ROOT = {
        any_demesne_province = {
            decrease_prosperity_effect = yes
        }
    }
   
    after = { #Flag clean up
        clr_character_flag = loop_gone
    }
}
 
Last edited:
@jonjowett
Thank you so much for your reply, and thank you especially for naming the alternative of using the winter modifiers. I'm planing on doing it that way instead, however, I'd also like to finish the mod I have begun writing with the prosperity/depopulation events.

Where do you implement the ROOT function you typed out? Should it be put directly in a character_event? Or maybe within immediate? And also, is it correct to use decrease_prosperity_effect the same way as increase?

I'm sending you a part of my code where I've tried implementing your code but can't make it work. Earlier in the code a randomizer is used to decide whether the character event increasing or decreasing prosperity should be triggered.

Code:
#DECREASE PROSPERITY INCASE OF BAD HARVEST - RUNS WHEN TRIGGERED
character_event = {
    id = TAX.4
    hide_window = yes
    is_triggered_only = yes
 
    trigger = { #Prevents TAX.4 from looping
        NOT = {
            has_character_flag = loop_gone
        }
    }

    immediate = {
        set_character_flag = loop_gone
        character_event = { #Restarts the whole function in a year
                    id = TAX.1 days = 365
                }
    }
 
    ROOT = {
        any_demesne_province = {
            decrease_prosperity_effect = yes
        }
    }
 
    after = { #Flag clean up
        clr_character_flag = loop_gone
    }
}
If you don't know what ROOT is, you should probably familiarise yourself a bit more with the CK2 scripting language, eg. by reading the relevant articles on the wiki. Scripting and Scopes would be good starting points.

(In brief: ROOT is a standard word in the CK2 scripting language that means "the base scope of this event/decision/etc". In the case of a character event, ROOT is the character which receives the event, FROM is the character/province who sent the event to ROOT, etc etc.)

---

The code snippet you pasted won't work because you didn't follow the required event structure.

(Specifically: The ROOT={...} clause you added belongs inside the immediate={...} section. Your current code implies that ROOT={...} is its own separate section on the same level as immediate/trigger/after/etc, which is not valid syntax.)

In this case, you made the mistake because you're still learning but, in general, it's probably a good idea to install the Validator, as this will flag up this kind of obvious syntax error.