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

Garnrag

First Lieutenant
125 Badges
Jan 27, 2007
267
74
  • Cities: Skylines Deluxe Edition
  • Europa Universalis: Rome
  • Sengoku
  • Sword of the Stars
  • Sword of the Stars II
  • Teleglitch: Die More Edition
  • Victoria 2
  • Victoria 2: A House Divided
  • Victoria 2: Heart of Darkness
  • Rome: Vae Victis
  • Warlock: Master of the Arcane
  • 500k Club
  • Cities: Skylines
  • Europa Universalis IV: Res Publica
  • Crusader Kings II: Holy Knight (pre-order)
  • Europa Universalis III: Collection
  • Europa Universalis IV: El Dorado
  • Europa Universalis IV: Pre-order
  • Europa Universalis: Rome Collectors Edition
  • Crusader Kings II: Way of Life
  • Pillars of Eternity
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Victoria 3 Sign Up
  • Europa Universalis III: Chronicles
  • Cities in Motion 2
  • 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: Sword of Islam
  • Deus Vult
  • Diplomacy
  • Europa Universalis III
  • Cities in Motion
  • Europa Universalis III Complete
  • Divine Wind
  • Europa Universalis IV
  • 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
  • Heir to the Throne
  • Europa Universalis III Complete
  • Magicka
This might just be a personal boondoggle, but the hivemind knows all.

If one wanted an event to run across either a court or an entire realm and assign a trait to everyone who lacks it, or remove a trait from everyone who has it, how would this need to be structured? I feel cautiously optimistic about my understanding of triggers and effects, but I'm losing my mind in fumbling through the scoping and related syntax.

Grateful for any guidance or signposting if this has been discussed before.
 
  • 1Like
Reactions:
Yep, this is doable. You just need a way to grab the right realm/title/court, and then it's a simple if statement to add and remove traits.

If you want to do it in your own court (or the root character's court, more specifically), it should be as simple as just an effect to grab all courtiers/guests and vassals.

Code:
every_courtier_or_guest = { # Grab every courtier or guest
    if = { # Remove any conflicting traits
        limit = {
            has_trait = callous
        }
        remove_trait = callous
    }
    else_if = {
        limit = {
            has_trait = sadistic
        }
        remove_trait = sadistic
    }
    add_trait = compassionate # Then add the desired trait
}

every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
    if = {
        limit = {
            has_trait = callous
        }
        remove_trait = callous
    }
    else_if = {
        limit = {
            has_trait = sadistic
        }
        remove_trait = sadistic
    }
    add_trait = compassionate
}

As an example, say for some reason I wanted to write an event where one of my children who is at a distant court turns everyone in their new realm (above and below them) into a reveler.

Code:
    random_child = { # Scope into a character
        limit = {
            NOT = { is_in_the_same_court_as = root } # For this, I want a character who is in a different court as a ruler, spouse, hostage, guest, etc.
        }
        top_liege = { # Find their highest-level liege...
            if = { # Make them a reveler
                limit = { NOT = { has_trait = lifestyle_reveler } }
                add_trait = lifestyle_reveler
            }
            every_courtier_or_guest = { # And make all their courtiers/guests revelers
                if = {
                    limit = { NOT = { has_trait = lifestyle_reveler } }
                    add_trait = lifestyle_reveler
                }
            }
            every_vassal_or_below = { # And make all vassals revelers, as well as those vassals' own courtiers
                if = {
                    limit = { NOT = { has_trait = lifestyle_reveler } }
                    add_trait = lifestyle_reveler
                }
                every_courtier_or_guest = {
                    if = {
                        limit = { NOT = { has_trait = lifestyle_reveler } }
                        add_trait = lifestyle_reveler
                    }
                }
            }
        }
    }

I hope that's helpful. If you need more direct advice, let me know and I can walk you through a more specific situation. But basically, just find a way to grab the right character with a list builder (e.g., every_vassal_or_below, every_courtier_or_guest, basically anything that is random_ or every_), or an existing scope (e.g., save a scope called scope:child and then do it to them), or by selecting a specific character with character:123456 (you can find their specific charcter ID in the history files).
 
  • 1
Reactions:
Yep, this is doable. You just need a way to grab the right realm/title/court, and then it's a simple if statement to add and remove traits.

If you want to do it in your own court (or the root character's court, more specifically), it should be as simple as just an effect to grab all courtiers/guests and vassals.

Code:
every_courtier_or_guest = { # Grab every courtier or guest
    if = { # Remove any conflicting traits
        limit = {
            has_trait = callous
        }
        remove_trait = callous
    }
    else_if = {
        limit = {
            has_trait = sadistic
        }
        remove_trait = sadistic
    }
    add_trait = compassionate # Then add the desired trait
}

every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
    if = {
        limit = {
            has_trait = callous
        }
        remove_trait = callous
    }
    else_if = {
        limit = {
            has_trait = sadistic
        }
        remove_trait = sadistic
    }
    add_trait = compassionate
}

As an example, say for some reason I wanted to write an event where one of my children who is at a distant court turns everyone in their new realm (above and below them) into a reveler.

Code:
    random_child = { # Scope into a character
        limit = {
            NOT = { is_in_the_same_court_as = root } # For this, I want a character who is in a different court as a ruler, spouse, hostage, guest, etc.
        }
        top_liege = { # Find their highest-level liege...
            if = { # Make them a reveler
                limit = { NOT = { has_trait = lifestyle_reveler } }
                add_trait = lifestyle_reveler
            }
            every_courtier_or_guest = { # And make all their courtiers/guests revelers
                if = {
                    limit = { NOT = { has_trait = lifestyle_reveler } }
                    add_trait = lifestyle_reveler
                }
            }
            every_vassal_or_below = { # And make all vassals revelers, as well as those vassals' own courtiers
                if = {
                    limit = { NOT = { has_trait = lifestyle_reveler } }
                    add_trait = lifestyle_reveler
                }
                every_courtier_or_guest = {
                    if = {
                        limit = { NOT = { has_trait = lifestyle_reveler } }
                        add_trait = lifestyle_reveler
                    }
                }
            }
        }
    }

I hope that's helpful. If you need more direct advice, let me know and I can walk you through a more specific situation. But basically, just find a way to grab the right character with a list builder (e.g., every_vassal_or_below, every_courtier_or_guest, basically anything that is random_ or every_), or an existing scope (e.g., save a scope called scope:child and then do it to them), or by selecting a specific character with character:123456 (you can find their specific charcter ID in the history files).
That is supremely helpful, thank you so much! I'm pretty sure I can take it from here but will shout if I can't debug my own work
 
  • 2Like
Reactions:
That is supremely helpful, thank you so much! I'm pretty sure I can take it from here but will shout if I can't debug my own work
Ugh. I need to "remove_trait = arrogant" on myself, I fear, as I stupidly forgot to take a backup before testing my events; thankfully I can revert to a backup that only costs me a year or so.

Anyway, as for the code something is not working right here - every character is getting the Compassionate trait no matter what they started with. does add_trait = compassionate need to be moved within the if / else_if's brackets?

Separately, I've set up two events here for different traits. When I use the console to trigger event purgelies, purgehurt fires instead! Never seen anything like that before. Can anyone see anything I'm doing wrong there?

Code:
purgehurt={
    
    hidden = yes
        
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = { # Remove any conflicting traits
                limit = {
                    has_trait = callous
                }
                remove_trait = callous
            }
            else_if = {
                limit = {
                    has_trait = sadistic
                }
                remove_trait = sadistic
            }
            add_trait = compassionate # Then add the desired trait
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    has_trait = callous
                }
                remove_trait = callous
            }
            else_if = {
                limit = {
                    has_trait = sadistic
                }
                remove_trait = sadistic
            }
            add_trait = compassionate
        }
    }
}
        ######################
purgelies={
    
    hidden = yes
    
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = { # Remove any conflicting traits
                limit = {
                    has_trait = deceitful
                }
                remove_trait = deceitful
            }
            add_trait = honest # Then add the desired trait
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    has_trait = deceitful
                }
                remove_trait = deceitful
            }
            add_trait = honest
        }
    }
}
 
  • 1Like
Reactions:
Okay, think I've got things mostly working now. I omitted a "namespace =" header for my file, and adding that has fixed the first event in the file being fired every time I trigger a different event. Rookie mistake.

Nesting the add_trait command in line with the remove_trait seems to correctly keep the specific characters in scope for their personality transplant. I've also nested the every_X commands for a bit of recursion, and it seems to work fine. For anyone who's clicked on this hoping to get some ideas for themselves, here's my current evolution of WeeLittleSpoon's code, as complete events.


Code:
namespace = cgpurge

cgpurge.0001={ #cruelty
    
    hidden = yes
        
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = { # Remove any conflicting traits
                limit = {
                    has_trait = callous
                }
                remove_trait = callous
                add_trait = compassionate # Then add the desired trait
            }
            else_if = {
                limit = {
                    has_trait = sadistic
                }
                remove_trait = sadistic
                add_trait = compassionate # Then add the desired trait
            }
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    has_trait = callous
                }
                remove_trait = callous
                add_trait = compassionate
            }
            else_if = {
                limit = {
                    has_trait = sadistic
                }
                remove_trait = sadistic
                add_trait = compassionate
            }
            every_courtier_or_guest  = { # Grab every courtier or guest
                if = { # Remove any conflicting traits
                    limit = {
                        has_trait = callous
                    }
                    remove_trait = callous
                    add_trait = compassionate # Then add the desired trait
                }
                else_if = {
                    limit = {
                        has_trait = sadistic
                    }
                    remove_trait = sadistic
                    add_trait = compassionate # Then add the desired trait
                }
            }
            every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
                if = {
                    limit = {
                        has_trait = callous
                    }
                    remove_trait = callous
                    add_trait = compassionate
                }
                else_if = {
                    limit = {
                        has_trait = sadistic
                    }
                    remove_trait = sadistic
                    add_trait = compassionate
                }
            }
        }
    }
}
        ######################
cgpurge.0002={ #lies
    
    hidden = yes
    
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = { # Remove any conflicting traits
                limit = {
                    has_trait = deceitful
                }
                remove_trait = deceitful
                add_trait = honest # Then add the desired trait
            }
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    has_trait = deceitful
                }
                remove_trait = deceitful
                add_trait = honest # Then add the desired trait
            }
            every_courtier_or_guest = { # Grab every courtier or guest
                if = { # Remove any conflicting traits
                    limit = {
                        has_trait = deceitful
                    }
                    remove_trait = deceitful
                    add_trait = honest # Then add the desired trait
                }
            }
            every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
                if = {
                    limit = {
                        has_trait = deceitful
                    }
                    remove_trait = deceitful
                    add_trait = honest # Then add the desired trait
                }
            }
        }
    }
}

I'm also experimenting with something to target a realm's faith-culture combo. Seems to work at the personal court, at least. Still double checking my brackets before I'm sure it'll work but will hopefully have an update in a few.
 
  • 2
Reactions:
Seems to be successful. I imagine the NOT test in the code below is irrelevant, the game won't add the same trait twice, but I've got some bigger plans than just rendering my whole realm a nation of Stepford Wives and this was useful practice with the scopes and triggers.

First event will make anyone of your same faith and culture a witch, for those who really want to embrace a witch cult house and custom religion... (as an aside, I feel like there should be more restrictions on just how far you can deviate a faith (eg Catholicism) before the Rite tenet is invalidated... keeping the Head of Faith spiritual but going for a pro-hedonistic witch cult should really not count as heterodoxy to Catholic theologians!)

Second event was just for a brief giggle, but who knows. Someone out there might be pissed off at a rival nation to enjoy nuking them this way.

Code:
cgpurge.0007={ #apostacy
    
    hidden = yes
    
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = witch
                        }
                }
                add_trait = witch # Then add the desired trait
            }
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = witch
                        }
                }
                add_trait = witch # Then add the desired trait
            }
            every_courtier_or_guest = { # Grab every courtier or guest
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = witch
                            }
                    }
                    add_trait = witch # Then add the desired trait
                }
            }
            every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = witch
                            }
                    }
                    add_trait = witch # Then add the desired trait
                }
            }
        }
    }
}

cgpurge.0009={ #death by dueling banjos
    
    hidden = yes
    
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = inbred
                        }
                }
                add_trait = inbred # Then add the desired trait
            }
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = inbred
                        }
                }
                add_trait = inbred # Then add the desired trait
            }
            every_courtier_or_guest = { # Grab every courtier or guest
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = inbred
                            }
                    }
                    add_trait = inbred # Then add the desired trait
                }
            }
            every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = witch
                            }
                    }
                    add_trait = witch # Then add the desired trait
                }
            }
        }
    }
}

Thanks again, WeeLittleSpoon!
 
  • 1
  • 1Like
Reactions:
Seems to be successful. I imagine the NOT test in the code below is irrelevant, the game won't add the same trait twice, but I've got some bigger plans than just rendering my whole realm a nation of Stepford Wives and this was useful practice with the scopes and triggers.

First event will make anyone of your same faith and culture a witch, for those who really want to embrace a witch cult house and custom religion... (as an aside, I feel like there should be more restrictions on just how far you can deviate a faith (eg Catholicism) before the Rite tenet is invalidated... keeping the Head of Faith spiritual but going for a pro-hedonistic witch cult should really not count as heterodoxy to Catholic theologians!)

Second event was just for a brief giggle, but who knows. Someone out there might be pissed off at a rival nation to enjoy nuking them this way.

Code:
cgpurge.0007={ #apostacy
   
    hidden = yes
   
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = witch
                        }
                }
                add_trait = witch # Then add the desired trait
            }
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = witch
                        }
                }
                add_trait = witch # Then add the desired trait
            }
            every_courtier_or_guest = { # Grab every courtier or guest
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = witch
                            }
                    }
                    add_trait = witch # Then add the desired trait
                }
            }
            every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = witch
                            }
                    }
                    add_trait = witch # Then add the desired trait
                }
            }
        }
    }
}

cgpurge.0009={ #death by dueling banjos
   
    hidden = yes
   
    immediate = {
        every_courtier_or_guest = { # Grab every courtier or guest
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = inbred
                        }
                }
                add_trait = inbred # Then add the desired trait
            }
        }

        every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
            if = {
                limit = {
                    is_adult = yes
                    culture = root.culture
                    faith = root.faith
                    NOT = {
                        has_trait = inbred
                        }
                }
                add_trait = inbred # Then add the desired trait
            }
            every_courtier_or_guest = { # Grab every courtier or guest
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = inbred
                            }
                    }
                    add_trait = inbred # Then add the desired trait
                }
            }
            every_vassal_or_below = { # Do the same for all vassals and their vassals; if you also want to do it to their courts, you can just add the above effect into this one, doing it to all of their courtiers too
                if = {
                    limit = {
                        is_adult = yes
                        culture = root.culture
                        faith = root.faith
                        NOT = {
                            has_trait = witch
                            }
                    }
                    add_trait = witch # Then add the desired trait
                }
            }
        }
    }
}

Thanks again, WeeLittleSpoon!
You can also give a limit to every_courtier_or_guest. For example, you could move the adult, culture, faith, and witch checks into the limit when looking for the right characters, but there's nothing wrong with the way you've done it. I'm sure one way is technically better for performance than the other, but effectively it doesn't matter here, I just wanted to mention it.

Anyway, as for the code something is not working right here - every character is getting the Compassionate trait no matter what they started with. does add_trait = compassionate need to be moved within the if / else_if's brackets?

Separately, I've set up two events here for different traits. When I use the console to trigger event purgelies, purgehurt fires instead! Never seen anything like that before. Can anyone see anything I'm doing wrong there?
Sorry, that's my fault. I misunderstood what you wanted. I wrote that to give everyone Compassionate, regardless of what they had to start. If you want to convert everyone who is the opposite of a trait to the new trait, then yes, you should do it the way you've corrected it to, putting the add_trait in the if statement. However, as I mentioned above, another way to do it is to target everyone who has the trait (or in the case of the Witch, who doesn't have the trait) when selecting them for the every_courtier_or_guest or every_vassal_or_below.

Code:
every_courtier_or_guest = {
    limit = { # Grab only the characters who have these traits
        OR = {
            has_trait = callous
            has_trait = sadistic
        }
    }
    if = { # Remove the callous trait
        limit = { has_trait = callous }
        remove_trait = callous
    }
    else = { # Since everyone we've grabbed must have either callous or sadistic, we don't even need a limit for this--here, if they're not callous, they must be sadistic
        remove_trait = sadistic
    }
    add_trait = compassionate # You can put the add_trait outside of the if statement again because only the characters who already have callous or sadistic are being selected; this can be advantageous because this way we only have to write this effect once, instead of inside of each if branch
}

every_courtier_or_guest = {
    limit = {
        is_adult = yes
        culture = root.culture
        faith = root.faith
        NOT = { has_trait = inbred }
    }
    add_trait = inbred
}

There's really no need to change the way you've written it, in this case. It will still give the same result to what you're already doing, I just wanted to demo it as it takes a couple fewer lines to write and read, and that can just make it easier to keep track of what you've written, instead of having a bunch of nested effects (which I do way too often, and I can tell you from experience that my script quickly becomes a web of indecipherable madness).

If you're doing something like this, you can also create local scripted effects to keep your code clean. You can create scripted effects to be used anywhere in the common\scripted_effects folder, but you can also create local ones and put them in the same file that is to call on them. For example, one way to write the cgpurge.0007 event could be to reuse that bit that gives the witch trait. Instead of copying and pasting the whole effect each time it's used like we were doing earlier, you can just create a scripted effect, and then call it with its name. This makes it easier to make changes to the effect, and it takes up less space in the file.

Code:
scripted_effect cgpurge_0007_add_witch_trait_effect = { # This goes in the event file where it is being used, before it is used
    if = {
        limit = {
            is_adult = yes
            culture = root.culture
            faith = root.faith
            NOT = {
                has_trait = witch
            }
        }
        add_trait = witch
    }
}

cgpurge.0007={ #apostacy
    hidden = yes

    immediate = {
        every_courtier_or_guest = {
            cgpurge_0007_add_witch_trait_effect = yes
        }

        every_vassal_or_below = {
            cgpurge_0007_add_witch_trait_effect = yes

            every_courtier_or_guest = {
                cgpurge_0007_add_witch_trait_effect = yes
            }

            every_vassal_or_below = {
                cgpurge_0007_add_witch_trait_effect = yes
            }
        }
    }
}

Note: I didn't test these, so if you put these into your files verbatim and they don't work, it's because I've made a typo somewhere, but the overall idea is sound.
 
  • 1
Reactions: