• 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.

blackninja9939

Experienced Programmer - Crusader Kings 3
Paradox Staff
78 Badges
Aug 28, 2013
2.401
7.847
  • Crusader Kings III
  • Stellaris: Federations
  • Battle for Bosporus
  • Stellaris: Nemesis
  • Hearts of Iron IV: No Step Back
  • Europa Universalis IV
  • Crusader Kings III: Royal Edition
  • Europa Universalis 4: Emperor
  • Stellaris: Necroids
  • Crusader Kings II
  • Crusader Kings II: Holy Fury
  • Imperator: Rome - Magna Graecia
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Old Gods
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Cradle of Civilization
  • Stellaris: Synthetic Dawn
  • Surviving Mars
  • BATTLETECH
  • Europa Universalis IV: Mandate of Heaven
  • Crusader Kings II: Monks and Mystics
  • Tyranny: Archon Edition
  • Europa Universalis IV: Rule Britannia
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: Colonel
  • Stellaris Sign-up
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Apocalypse
  • Stellaris: Lithoids
  • Stellaris: Distant Stars
  • Europa Universalis IV: Dharma
  • Shadowrun Returns
  • Imperator: Rome Deluxe Edition
  • Prison Architect
  • Imperator: Rome Sign Up
  • Stellaris: Ancient Relics
  • Age of Wonders: Planetfall
  • Crusader Kings II: Conclave
  • Crusader Kings II: The Republic
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Stellaris
  • Mount & Blade: Warband
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Sunset Invasion
I've got a question on variables. I'd like to be able to set a variable on a character based on the same variable for that character's parent. The wiki says that a variable can be set like so:

A scope (in the form of ROOT/FROM/PREV/THIS) which contains a variable with the same name: (set|change|subtract|multiply|divide)_variable = { which = <variable_name> which = <scope> }

Are those the only scopes possible? I tried doing "set_variable = { which = my_var which = father_even_if_dead }", but that didn't work.
I believe only ROOT/FROM/PREV/THIS work as the right hand side for a which argument. What you would want to do is something like father = { ROOT = { set_variable = { which = my_var which = PREV } } }
 
  • 1
  • 1
Reactions:

LordPeter

Marjoram
49 Badges
Mar 5, 2012
2.249
382
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Conclave
  • Stellaris Sign-up
  • Hearts of Iron IV: Cadet
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Prison Architect
  • Stellaris - Path to Destruction bundle
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris: Synthetic Dawn
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Stellaris: Distant Stars
  • Stellaris: Megacorp
  • Crusader Kings II: Holy Fury
  • Imperator: Rome
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Way of Life
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
  • Europa Universalis IV
  • Crusader Kings II: Sword of Islam
  • Stellaris
  • Europa Universalis IV: Third Rome
  • Cities: Skylines
  • Crusader Kings II: Jade Dragon
  • Europa Universalis IV: Cradle of Civilization
Greetings, so I am a bit confused again.

I want to have an event that checks ALL provinces in the game for certain province_modifiers, and count the instances of provinces with them.
If the number is below a certain treshold, it would set a flag related to that modifier, which would make events applying the modifier more likely to fire.
Then after 10 years or so, the original event would fire again, re-evaluate the current numbers, and clear the flag if the number is now over the treshold.

But my problem is: How do I count provinces with a certain modifier?

Looking at the Wiki, I did find "count" and "clac_true_if". But both of them seem to not work the way I want - or am I mistaken?
 

Silversweeeper

Ichi no Hito
58 Badges
Aug 24, 2012
3.943
2.840
  • Stellaris - Path to Destruction bundle
  • 500k Club
  • Europa Universalis IV: El Dorado
  • Magicka: Wizard Wars Founder Wizard
  • Crusader Kings II: Way of Life
  • Pillars of Eternity
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Stellaris: Distant Stars
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Imperator: Rome Sign Up
  • Imperator: Rome Deluxe Edition
  • Crusader Kings II: Holy Fury
  • Stellaris: Megacorp
  • Europa Universalis IV
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Charlemagne
  • Stellaris Sign-up
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Res Publica
  • Crusader Kings II
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III Complete
  • Magicka
Greetings, so I am a bit confused again.

I want to have an event that checks ALL provinces in the game for certain province_modifiers, and count the instances of provinces with them.
If the number is below a certain treshold, it would set a flag related to that modifier, which would make events applying the modifier more likely to fire.
Then after 10 years or so, the original event would fire again, re-evaluate the current numbers, and clear the flag if the number is now over the treshold.

But my problem is: How do I count provinces with a certain modifier?

Looking at the Wiki, I did find "count" and "clac_true_if". But both of them seem to not work the way I want - or am I mistaken?

There are two ways to do it.

One option would be to use count as below.

Code:
if = {
   limit = {
       any_province = {
           count = X
           has_province_modifier = Y
       }
   }
   #DOSTUFF
   clr_global_flag = Z
   break = yes
}
set_global_flag = Z

The other option is to divide it into four events

Code:
# Effect of event 1

set_variable = {
   which = counter
   value = 0
}

any_province = {
   province_event = { id = event2 }
}

province_event = { id = event4 days = 1 }

# Effect of event 2

if = {
   limit = {
       has_province_modifier = X
   }
   FROM = {
       province_event = { id = event3 }
   }
}

# Effect of event 3
change_variable = {
   which = counter
   value = 1
}

# Effect of event 4
if = {
   limit = {
       NOT = {
           check_variable = [
               which = counter
               value = Y
           }
       }
   }
   set_global_flag = Z
}
if = {
   limit = {
       check_variable = [
           which = counter
           value = Y
       }
   }
   clr_global_flag = Z
}
province_event = { id = event1 days = 3650 }

Keep in mind that any_province is a CPU-heavy scope, so use it with care. The first option is nice in that only fires a single event, while the second option might be useful if you e.g. want the province holder to confirm that they want to increase the counter, which may or may not be useful.
 
  • 1
Reactions:

NoxBestia

First Lieutenant
37 Badges
Jul 9, 2014
206
21
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Crusader Kings II
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Sunset Invasion
  • Cities: Skylines - Green Cities
  • Crusader Kings II: Jade Dragon
  • Surviving Mars: Digital Deluxe Edition
  • Cities: Skylines - Parklife Pre-Order
  • Cities: Skylines - Parklife
  • Crusader Kings II: Holy Fury Pre-order
  • Surviving Mars: First Colony Edition
  • Crusader Kings II: Holy Fury
  • Surviving Mars: First Colony Edition
  • Imperator: Rome Sign Up
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Surviving Mars
  • Cities: Skylines - Mass Transit
  • Crusader Kings II: Monks and Mystics
  • Cities: Skylines - Natural Disasters
  • Crusader Kings II: Reapers Due
  • Cities: Skylines - Snowfall
  • Crusader Kings II: Conclave
  • Cities: Skylines - After Dark
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Way of Life
  • Cities: Skylines
  • Europa Universalis IV
I was told my mod is generating too many characters. What is the acceptable population deviation from the defines if they have not been changed?
Code:
NEngine = {
    POPULATION_BASELINE = 20000, -- The baseline of what would be considered normal amount of population
},

My mod is generating about 20% above that after 100 years in observer mode (25000-27000). Is that a "normal" amount of variance or should I keep looking for something wrong in my code?
 

Silversweeeper

Ichi no Hito
58 Badges
Aug 24, 2012
3.943
2.840
  • Stellaris - Path to Destruction bundle
  • 500k Club
  • Europa Universalis IV: El Dorado
  • Magicka: Wizard Wars Founder Wizard
  • Crusader Kings II: Way of Life
  • Pillars of Eternity
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Stellaris: Distant Stars
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Imperator: Rome Sign Up
  • Imperator: Rome Deluxe Edition
  • Crusader Kings II: Holy Fury
  • Stellaris: Megacorp
  • Europa Universalis IV
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Charlemagne
  • Stellaris Sign-up
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Res Publica
  • Crusader Kings II
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III Complete
  • Magicka
Based on the graph in the optimization dev diary (https://forum.paradoxplaza.com/foru...dev-diary-18-optimization-and-modding.962057/), a 20 % increase after a century seems rather small. However, the amount of living characters is considerably less than you have, so assuming that the graph was made with the 20k baseline you have far more characters, assiming the 25-27k are living characters and not just characters.

What changes have you made in your mod? Knowing that would help figuring out where your problem is.
 

NoxBestia

First Lieutenant
37 Badges
Jul 9, 2014
206
21
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Crusader Kings II
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Sunset Invasion
  • Cities: Skylines - Green Cities
  • Crusader Kings II: Jade Dragon
  • Surviving Mars: Digital Deluxe Edition
  • Cities: Skylines - Parklife Pre-Order
  • Cities: Skylines - Parklife
  • Crusader Kings II: Holy Fury Pre-order
  • Surviving Mars: First Colony Edition
  • Crusader Kings II: Holy Fury
  • Surviving Mars: First Colony Edition
  • Imperator: Rome Sign Up
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Surviving Mars
  • Cities: Skylines - Mass Transit
  • Crusader Kings II: Monks and Mystics
  • Cities: Skylines - Natural Disasters
  • Crusader Kings II: Reapers Due
  • Cities: Skylines - Snowfall
  • Crusader Kings II: Conclave
  • Cities: Skylines - After Dark
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Way of Life
  • Cities: Skylines
  • Europa Universalis IV
Based on the graph in the optimization dev diary (https://forum.paradoxplaza.com/foru...dev-diary-18-optimization-and-modding.962057/), a 20 % increase after a century seems rather small. However, the amount of living characters is considerably less than you have, so assuming that the graph was made with the 20k baseline you have far more characters, assiming the 25-27k are living characters and not just characters.

What changes have you made in your mod? Knowing that would help figuring out where your problem is.
Here are the full stats I have recorded so far. (KEY: baseline is what is created at the start of a game without letting it go. parent = the mod mine is written for. 3rd = another person's sub-mod for the same parent mod)
Code:
 TEST: observe mode 100 years (769 start):
  baseline 769.1.1    10745 characters    |  2631 deceased    |   8114 living
  baseline 867.1.1    13230 characters    |  5147 deceased    |   8083 living
    with no mod       50168 characetrs    | 29577 deceased    |  20591 living
no mods no invasion   50391 characetrs    | 29755 deceased    |  20636 living
  parent mod only     50856 characters    | 29524 deceased    |  21332 living
 parent+my mod        56626 characters    | 31412 deceased    |  25214 living
 parent+my mod+3rd    59861 characters    | 33916 deceased    |  25945 living
 parent+my mod+3rd    59847 characters    | 32684 deceased    |  27163 living

As for what all I have changed, that is literally thousands of lines of code, so it will be a lot of searching to try to find exactly what. I do have some ideas though.

EDIT: I did check the other sub-mod as well as the parent mod and the only change to defines is the number of portrait properties. That plus the stats I have collected make me pretty sure the problem is somewhere in my mod.
 
Last edited:

Silver Wizard

Byzantophile
44 Badges
Jul 14, 2014
722
476
  • Crusader Kings II
  • Semper Fi
  • Victoria 2: A House Divided
  • Victoria 2: Heart of Darkness
  • Cities: Skylines Deluxe Edition
  • Crusader Kings II: Conclave
  • Imperator: Rome
  • Crusader Kings II: Holy Fury
  • Stellaris: Megacorp
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Parklife
  • Stellaris
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: Cadet
  • Europa Universalis IV: Rights of Man
  • Hearts of Iron IV: Together for Victory
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Jade Dragon
  • Stellaris: Apocalypse
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV
  • Victoria: Revolutions
  • Europa Universalis IV: Res Publica
  • Hearts of Iron III Collection
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sword of Islam
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Call to arms event
  • For the Motherland
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III
  • Stellaris - Path to Destruction bundle
Two of the poeple play-testing it. They were complaining that the extra characters will slow it down too much.

Doesn't look that huge an increase. Did you do anything else that slows down the game? Added a bunch of triggered modifiers? Increased diplomatic range? Added a lot of MTTH-events without pre-triggers?
 

NoxBestia

First Lieutenant
37 Badges
Jul 9, 2014
206
21
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Crusader Kings II
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Sunset Invasion
  • Cities: Skylines - Green Cities
  • Crusader Kings II: Jade Dragon
  • Surviving Mars: Digital Deluxe Edition
  • Cities: Skylines - Parklife Pre-Order
  • Cities: Skylines - Parklife
  • Crusader Kings II: Holy Fury Pre-order
  • Surviving Mars: First Colony Edition
  • Crusader Kings II: Holy Fury
  • Surviving Mars: First Colony Edition
  • Imperator: Rome Sign Up
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Surviving Mars
  • Cities: Skylines - Mass Transit
  • Crusader Kings II: Monks and Mystics
  • Cities: Skylines - Natural Disasters
  • Crusader Kings II: Reapers Due
  • Cities: Skylines - Snowfall
  • Crusader Kings II: Conclave
  • Cities: Skylines - After Dark
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Way of Life
  • Cities: Skylines
  • Europa Universalis IV
Doesn't look that huge an increase. Did you do anything else that slows down the game? Added a bunch of triggered modifiers? Increased diplomatic range? Added a lot of MTTH-events without pre-triggers?
Nope. No triggered modifiers at all. Most events are "triggered only" either by character action or on_action. The one MTTH event I have so far has the following pre-triggers:
Code:
ai = no
only_men = yes
capable_only = yes
min_age = 10
only_playable = yes
 

Silversweeeper

Ichi no Hito
58 Badges
Aug 24, 2012
3.943
2.840
  • Stellaris - Path to Destruction bundle
  • 500k Club
  • Europa Universalis IV: El Dorado
  • Magicka: Wizard Wars Founder Wizard
  • Crusader Kings II: Way of Life
  • Pillars of Eternity
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Stellaris: Distant Stars
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Imperator: Rome Sign Up
  • Imperator: Rome Deluxe Edition
  • Crusader Kings II: Holy Fury
  • Stellaris: Megacorp
  • Europa Universalis IV
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Charlemagne
  • Stellaris Sign-up
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Res Publica
  • Crusader Kings II
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III Complete
  • Magicka
A couple of things:

- It might be more useful for you to compare the amount of time it takes to run the game for X years with different combinations of mods instead of just the number of characters to see how much slower the game is running. While more characters means a slower game, it is not certain that they have a too large impact.

- You can remove the only_playable from your pre-trigger above as ai = no already takes care of that. Also, if you were using all of those pre-triggers but ai = no you would want to put only_playable at the top as it is the strictest condition of the bunch (aside from ai = no) and you want to eliminate as many characters as possible with each check.

- If you have a lot of events triggered from on_actions, try to disable all evens you have added and adding them back one by one to see one or a couple of events have a huge impact. You probably do not want to run those observer games for 100 years unless you have very few events, but run them for a decently long time.

- Make sure that all on_action events have good triggers and pre-triggers. You don't want to have a on_yearly_pulse event fire for every character or to have the trigger set up so that it checks if someone is independent after checking if they are a count or that checks for ai = no last.

- If you have added any targeted decisions, make sure that any of them that the AI can use have sensible filters and aren't taken too frequently by the AI, as it will evaluate taking any targeted decisions against all valid targets every month if the factor is 1, which is computationally expensive if the AI evaluates many characters (and especially if ai_target_filer = all).
 

NoxBestia

First Lieutenant
37 Badges
Jul 9, 2014
206
21
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Crusader Kings II
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Sunset Invasion
  • Cities: Skylines - Green Cities
  • Crusader Kings II: Jade Dragon
  • Surviving Mars: Digital Deluxe Edition
  • Cities: Skylines - Parklife Pre-Order
  • Cities: Skylines - Parklife
  • Crusader Kings II: Holy Fury Pre-order
  • Surviving Mars: First Colony Edition
  • Crusader Kings II: Holy Fury
  • Surviving Mars: First Colony Edition
  • Imperator: Rome Sign Up
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Surviving Mars
  • Cities: Skylines - Mass Transit
  • Crusader Kings II: Monks and Mystics
  • Cities: Skylines - Natural Disasters
  • Crusader Kings II: Reapers Due
  • Cities: Skylines - Snowfall
  • Crusader Kings II: Conclave
  • Cities: Skylines - After Dark
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Way of Life
  • Cities: Skylines
  • Europa Universalis IV
I will definitely add those to the things I check for optimization! Thank you.

I knew that ai = no was supposed to imply player only, but that for earlier version of the game it didn't always work as a pre-trigger. In one of the optimization threads it was recommended to have it to be safe, but you are correct, it should be at the top if I do keep it.

One potential problem with a lot of characters is that I can't guarantee the parent mod or any of the other sub-mods are properly optimized, though the parent mod seems well optimized in the code I have examined. Even if poor event performance is someone else's failure, I don't want my mod to be the catalyst. :)
 

LordPeter

Marjoram
49 Badges
Mar 5, 2012
2.249
382
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Conclave
  • Stellaris Sign-up
  • Hearts of Iron IV: Cadet
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Prison Architect
  • Stellaris - Path to Destruction bundle
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris: Synthetic Dawn
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Stellaris: Distant Stars
  • Stellaris: Megacorp
  • Crusader Kings II: Holy Fury
  • Imperator: Rome
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Way of Life
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
  • Europa Universalis IV
  • Crusader Kings II: Sword of Islam
  • Stellaris
  • Europa Universalis IV: Third Rome
  • Cities: Skylines
  • Crusader Kings II: Jade Dragon
  • Europa Universalis IV: Cradle of Civilization
There are two ways to do it.

One option would be to use count as below.

Code:
if = {
   limit = {
       any_province = {
           count = X
           has_province_modifier = Y
       }
   }
   #DOSTUFF
   clr_global_flag = Z
   break = yes
}
set_global_flag = Z

The other option is to divide it into four events

Code:
# Effect of event 1

set_variable = {
   which = counter
   value = 0
}

any_province = {
   province_event = { id = event2 }
}

province_event = { id = event4 days = 1 }

# Effect of event 2

if = {
   limit = {
       has_province_modifier = X
   }
   FROM = {
       province_event = { id = event3 }
   }
}

# Effect of event 3
change_variable = {
   which = counter
   value = 1
}

# Effect of event 4
if = {
   limit = {
       NOT = {
           check_variable = [
               which = counter
               value = Y
           }
       }
   }
   set_global_flag = Z
}
if = {
   limit = {
       check_variable = [
           which = counter
           value = Y
       }
   }
   clr_global_flag = Z
}
province_event = { id = event1 days = 3650 }

Keep in mind that any_province is a CPU-heavy scope, so use it with care. The first option is nice in that only fires a single event, while the second option might be useful if you e.g. want the province holder to confirm that they want to increase the counter, which may or may not be useful.
Brilliant, thanks!
My confusion stemed from the fact that the wiki's example was
"any_spouse_even_if_dead = { count = 3 }"
which did seem like there were no further limits applicable. Good thing I was mistaken ^^

Yep the warning about the scope is appropriate, I shall use it with care.
The first option is just what I need, as the event will only fire every 10 years just once, for the Pope (via a hidden event), and will do the checks in an immediate block. Thus it should not strain the CPU very much.
The modifiers get also only applied via hidden and immediate events, so no need for character interaction. I basically just wanted to check if there are too few or too many of those in the world, so that the dynamic events don't run into a dead end where either all or no provinces have a modifier.

Thanks again for the quick help, this thread should really be named: Quick Questions, Quick Answers :)
 

Silversweeeper

Ichi no Hito
58 Badges
Aug 24, 2012
3.943
2.840
  • Stellaris - Path to Destruction bundle
  • 500k Club
  • Europa Universalis IV: El Dorado
  • Magicka: Wizard Wars Founder Wizard
  • Crusader Kings II: Way of Life
  • Pillars of Eternity
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Stellaris: Distant Stars
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Imperator: Rome Sign Up
  • Imperator: Rome Deluxe Edition
  • Crusader Kings II: Holy Fury
  • Stellaris: Megacorp
  • Europa Universalis IV
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Charlemagne
  • Stellaris Sign-up
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Res Publica
  • Crusader Kings II
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III Complete
  • Magicka
@LordPeter: It would probably be smarter to fire the event for a province than for the Pope as you'd otherwise end up breaking the chain as soon as the original Pope dies.
 
  • 1
Reactions:

LordPeter

Marjoram
49 Badges
Mar 5, 2012
2.249
382
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Conclave
  • Stellaris Sign-up
  • Hearts of Iron IV: Cadet
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Prison Architect
  • Stellaris - Path to Destruction bundle
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris: Synthetic Dawn
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Stellaris: Distant Stars
  • Stellaris: Megacorp
  • Crusader Kings II: Holy Fury
  • Imperator: Rome
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Way of Life
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
  • Europa Universalis IV
  • Crusader Kings II: Sword of Islam
  • Stellaris
  • Europa Universalis IV: Third Rome
  • Cities: Skylines
  • Crusader Kings II: Jade Dragon
  • Europa Universalis IV: Cradle of Civilization
@LordPeter: It would probably be smarter to fire the event for a province than for the Pope as you'd otherwise end up breaking the chain as soon as the original Pope dies.
I didn't think so. Does it?
I thought it wasn't a problem, as vanilla uses the Pope for some events, too (can't remember what it was), for the cases when only 1 character in the world should fire the event.

And since I chose to go with option #1, my event will - very simplified - look like this (partly pseudocode):
Code:
event = {

    hide_window = yes

    trigger = {
        is_pope = yes
    }

    immediate = {
        if = {
            limit = {
                any_province = {
                    count = X
                    has_province_modifier = Y
                }
            }
            set_global_flag = Z
        }
    }

}
So it will fire immediately for whoever is currently Pope, then immediately sets a global flag. Global flags should not be tied to characters, right?
So then when the event fires again in 10 years, it might fire for a different Pope, but the global flag is still there, and the event can clr or keep it.

I only want the event to fire once, so a province event would not work iirc, as I want to fire it from on_actions (for performance reasons), and there is no way (that I am aware of) to fire it from there for only one (specific?) province.

If I am mistaken again, you may correct me, but I think it should work fine.
Anyway, thanks again for your help, this thread is really helpful :)
 

Silversweeeper

Ichi no Hito
58 Badges
Aug 24, 2012
3.943
2.840
  • Stellaris - Path to Destruction bundle
  • 500k Club
  • Europa Universalis IV: El Dorado
  • Magicka: Wizard Wars Founder Wizard
  • Crusader Kings II: Way of Life
  • Pillars of Eternity
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Stellaris: Distant Stars
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Imperator: Rome Sign Up
  • Imperator: Rome Deluxe Edition
  • Crusader Kings II: Holy Fury
  • Stellaris: Megacorp
  • Europa Universalis IV
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Charlemagne
  • Stellaris Sign-up
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Res Publica
  • Crusader Kings II
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III Complete
  • Magicka
The event would fire roughly ten years later if you use had_global_flag = { flag = Z days = 3650 }, yes (the event offset would make it miss the mark by a few days). However, keep in mind that if you want to fire the event yet again (e.g, if you don't find enough provinces with the modifier) with a delay you will need to clear and reset the flag, as using set_<scope>_flag when it already is set for the scope does not reset the time the scope has had the flag, meaning the Pope would get the event 20-ish days later as ten years have passed since the flag originally was set.

As for firing a province event from on_actions, you could always fire an event for some character (e.g. the Pope) and then fire an event from that event for a certain province (e.g. capital_scope = { province_event = { id = X days = Y} }, if you don't care about which province) if you aren't already in the province scope in on_actions.
 
  • 1
Reactions:

jursamaj

General
125 Badges
Aug 20, 2012
2.360
216
  • Victoria 2: Heart of Darkness
  • Hearts of Iron III
  • Heir to the Throne
  • Knights of Pen and Paper +1 Edition
  • Cities in Motion
  • Europa Universalis IV: Res Publica
  • Victoria: Revolutions
  • Stellaris: Galaxy Edition
  • Stellaris - Path to Destruction bundle
  • Victoria 2: A House Divided
  • Leviathan: Warships
  • Rome: Vae Victis
  • Stellaris
  • Europa Universalis IV: Pre-order
  • Magicka 2 - Signup Campaign
  • Crusader Kings II: Horse Lords
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Mare Nostrum
  • Europa Universalis IV: Call to arms event
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis III Complete
  • Europa Universalis IV: Conquest of Paradise
  • Divine Wind
  • Europa Universalis IV: Art of War
  • Europa Universalis III: Chronicles
  • Crusader Kings II: Way of Life
  • Crusader Kings II: Conclave
  • Europa Universalis III Complete
  • Europa Universalis IV: Common Sense
  • Europa Universalis III Complete
  • Pillars of Eternity
  • Europa Universalis IV
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Stellaris Sign-up
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: No Step Back
A couple of things:

- It might be more useful for you to compare the amount of time it takes to run the game for X years with different combinations of mods instead of just the number of characters to see how much slower the game is running. While more characters means a slower game, it is not certain that they have a too large impact.

- You can remove the only_playable from your pre-trigger above as ai = no already takes care of that. Also, if you were using all of those pre-triggers but ai = no you would want to put only_playable at the top as it is the strictest condition of the bunch (aside from ai = no) and you want to eliminate as many characters as possible with each check.

- If you have a lot of events triggered from on_actions, try to disable all evens you have added and adding them back one by one to see one or a couple of events have a huge impact. You probably do not want to run those observer games for 100 years unless you have very few events, but run them for a decently long time.

- Make sure that all on_action events have good triggers and pre-triggers. You don't want to have a on_yearly_pulse event fire for every character or to have the trigger set up so that it checks if someone is independent after checking if they are a count or that checks for ai = no last.

- If you have added any targeted decisions, make sure that any of them that the AI can use have sensible filters and aren't taken too frequently by the AI, as it will evaluate taking any targeted decisions against all valid targets every month if the factor is 1, which is computationally expensive if the AI evaluates many characters (and especially if ai_target_filer = all).
My understanding (from a prior dev comment) is that the ordering (and to a lesser degree, redundancy) of pre-triggers doesn't matter, because the game automatically optimizes that. The order of evaluation is not determined by the order they're written.
 

jursamaj

General
125 Badges
Aug 20, 2012
2.360
216
  • Victoria 2: Heart of Darkness
  • Hearts of Iron III
  • Heir to the Throne
  • Knights of Pen and Paper +1 Edition
  • Cities in Motion
  • Europa Universalis IV: Res Publica
  • Victoria: Revolutions
  • Stellaris: Galaxy Edition
  • Stellaris - Path to Destruction bundle
  • Victoria 2: A House Divided
  • Leviathan: Warships
  • Rome: Vae Victis
  • Stellaris
  • Europa Universalis IV: Pre-order
  • Magicka 2 - Signup Campaign
  • Crusader Kings II: Horse Lords
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Mare Nostrum
  • Europa Universalis IV: Call to arms event
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Europa Universalis III
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis III Complete
  • Europa Universalis IV: Conquest of Paradise
  • Divine Wind
  • Europa Universalis IV: Art of War
  • Europa Universalis III: Chronicles
  • Crusader Kings II: Way of Life
  • Crusader Kings II: Conclave
  • Europa Universalis III Complete
  • Europa Universalis IV: Common Sense
  • Europa Universalis III Complete
  • Pillars of Eternity
  • Europa Universalis IV
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Stellaris Sign-up
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: No Step Back
I didn't think so. Does it?
I thought it wasn't a problem, as vanilla uses the Pope for some events, too (can't remember what it was), for the cases when only 1 character in the world should fire the event.

And since I chose to go with option #1, my event will - very simplified - look like this (partly pseudocode):
Code:
event = {

    hide_window = yes

    trigger = {
        is_pope = yes
    }

    immediate = {
        if = {
            limit = {
                any_province = {
                    count = X
                    has_province_modifier = Y
                }
            }
            set_global_flag = Z
        }
    }

}
So it will fire immediately for whoever is currently Pope, then immediately sets a global flag. Global flags should not be tied to characters, right?
So then when the event fires again in 10 years, it might fire for a different Pope, but the global flag is still there, and the event can clr or keep it.

I only want the event to fire once, so a province event would not work iirc, as I want to fire it from on_actions (for performance reasons), and there is no way (that I am aware of) to fire it from there for only one (specific?) province.

If I am mistaken again, you may correct me, but I think it should work fine.
Anyway, thanks again for your help, this thread is really helpful :)
I assume you are using the on_decade_pulse, and that 'is_pope = yes' is a custom scripted_trigger. That means it is still having to check each character to decide who is the pope. Granted, it's only once every 10 years, but there's still a more efficient way.

Use an on_chronicle_start hidden event (only fires for the player anyway, so no need for pope check). That event immediately calls a hidden event on province 1. This is your province modifier checking event. At the end of that event, call a repeat_event of the same event to the same province, delay of 3650 days. This will keep repeating the same check every 10 years exactly, with no pope check and no worries about the target changing.
 
  • 2
Reactions: