• 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.
How do I tell an event to check the traits and attributes of a character that has a certain character flag, as opposed to the default game behaviour of checking the character the event is happening to?
I don't understand what you mean. Can you explain in more detail, or give an example?
 
I don't understand what you mean. Can you explain in more detail, or give an example?


For example, if you're writing a character event and you use "trait = strong" it will look at the targeted character for the trait, and no one else.

I want the event to look at a character (designated with a character flag) that isn't directly involved in an event. So in this example, check for "trait = strong" on any characters marked using "has_character_flag = { special_char_flag }"
 
For example, if you're writing a character event and you use "trait = strong" it will look at the targeted character for the trait, and no one else.

I want the event to look at a character (designated with a character flag) that isn't directly involved in an event. So in this example, check for "trait = strong" on any characters marked using "has_character_flag = { special_char_flag }"
You'd have to scope to them in the trigger. How you'd scope to them depends on how they're related to the ROOT character. For example, if you want to scope to any realm character with the flag and the strong trait, you'd use:
Code:
any_realm_character = {
    has_character_flag = special_char_flag
    trait = strong
}
And then, to do something to them, you'd use:
Code:
random_realm_character = { # or any_realm_character if you want it to effect everyone that meets the conditions
    limit = {
        has_character_flag = special_char_flag
        trait = strong
    }
    # any effects
}
 
And then, to do something to them, you'd use:
Code:
random_realm_character = { # or any_realm_character if you want it to effect everyone that meets the conditions
    limit = {
        has_character_flag = special_char_flag
        trait = strong
    }
    # any effects
}

Just to clarify, would an instance of this event keep running the search until someone with the proper flag is found? Or would it fire once, and just stop if the randomly-selected individual does not have the relevant flag?
 
Just to clarify, would an instance of this event keep running the search until someone with the proper flag is found? Or would it fire once, and just stop if the randomly-selected individual does not have the relevant flag?
Depends on how you implement it - the above suggested pieces of code are only scraps, after all, you'd need to use them in a context.
Here is an example of how they could be combined, I hope the annotations explain it:
Code:
if = {
    # conditions to be fulfilled: At least one character in the realm exists with both the character flag and the "strong" trait. Code below checks for that:
    any_realm_character = {    # <- is fulfilled if at least one character qualifies, but could be multiple as well!
        AND = {    # <- this AND is just for clarification, as it is the default
            has_character_flag = special_char_flag
            trait = strong
        }
    }
    # The following is the "then (do)" part of an if/else structure - that means it will only execute if a character fulfilling the conditions above has been found:
    random_realm_character = { # This will mean only one, randomly chosen character of those that qualified the condtions above will experience the event. Use any_realm_character if you want it to effect everyone that meets the conditions
        limit = {
            has_character_flag = special_char_flag
            trait = strong
        }
        # any effects
    }
}
To answer your question for this example: First the event would search until it has found a character that fulfills the conditions (has the flag and the trait), or until it has checked every character in the realm, and no one qualified.
In the case it found someone (or several!), it will pick one of those that qualified (that's the second scope with the "limit" thing), and execute the effects you specified on that person.
As @Omniscient already noted, you could also use "any_realm_character" instead of "random_realm_character", which would mean the event would scope to all characters that qualified (it could have been several, after all), and execute the effects for all of them.
In the case the condition found no character that qualified the criteria, it will simply do nothing.

Again, this is only an example event (or rather, part of it - you still need all the stuff around it, like an id, a picture etc). Events are incredibly powerful, and you could code other varieties of this event that behave differently. But this is a simple event that probably does what you want.
 
Just to clarify, would an instance of this event keep running the search until someone with the proper flag is found? Or would it fire once, and just stop if the randomly-selected individual does not have the relevant flag?
How often it checks depends on how you construct the event (mean time to happen of triggered on_action), but if the event trigger isn't satisfied, the event won't fire.

If you're asking about random_realm_character, it can only be used in an effect block (immediate or options), never in the trigger block.

Perhaps you could tell us, very specifically, what it is you're trying to do, so we could give more specific advice.
 
Last edited:
How do you make traits show up in the ruler designer? I can't seem to figure it out, I've tried adding customizer = yes and a ruler_designer_cost = x but it just doesn't work. The traits themselves aren't broken though, I can assign those through the console just fine.
 
Perhaps you could tell us, very specifically, what it is you're trying to do, so we could give more specific advice.

Well, it's more I'm trying to understand how to code, which is why I'm using generic examples so I have to do it myself, rather than just posting the exact code and having others do it for me.

But back on the topic of finding characters, is know comparative conditions (relative_power, attribute_diff, opinion_diff) normally have you use specific variables (ROOT and FROM) to determine the targets of the comparison. But would it be possible to replace ROOT or FROM with a targeted search like "{any_realm_character = { has_character_flag = whatever } }"?

For example, taking the standard

Code:
relative_power = { who = FROM power = 2.0 }

and turning it into

Code:
relative_power = { who = {any_realm_character = { has_character_flag = whatever } } power = 2.0 }

is something like that possible, or can you not change variables like that?
 
Can saved event targets be used in dynamic flags? So if I save a certain scope as an event target variable, can I use it in a dynamic flag by appending @ and the name of my scope saved as the event target variable? I didn't find any information about this particular combination on the wiki.

I don't think so.

Is it possible to make a merchant republic hold a new election every set number of years rather than on the death of its doge?

It might be possible to recreate everything except the campaign fund contributions with events, but it might get messy. Not sure if the logic behind the election is visible somewhere or not.
 
Well, it's more I'm trying to understand how to code, which is why I'm using generic examples so I have to do it myself, rather than just posting the exact code and having others do it for me.

But back on the topic of finding characters, is know comparative conditions (relative_power, attribute_diff, opinion_diff) normally have you use specific variables (ROOT and FROM) to determine the targets of the comparison. But would it be possible to replace ROOT or FROM with a targeted search like "{any_realm_character = { has_character_flag = whatever } }"?

For example, taking the standard

Code:
relative_power = { who = FROM power = 2.0 }

and turning it into

Code:
relative_power = { who = {any_realm_character = { has_character_flag = whatever } } power = 2.0 }

is something like that possible, or can you not change variables like that?

No, but you could use PREV to check the previous scope in a scope chain. ((PREVPREV will scope back two, and so on, up to four back) https://ck2.paradoxwikis.com/Scripting#Scope_chain

You can also (and this is probably what you need to do) use dynamic event targets. https://ck2.paradoxwikis.com/Scripting#Event_targets Note that event targets usually cannot be accessed outside of an event chain.
 
So, I tried out the validator, but whenever I run it, it scans the game itself and every single mod in the mod directory, and just dumps a huge list of errors from all of them in one spot. Which is just a giant mess.

Is there any way I can get the validator to scan a specific text file for formatting, or barring that, just a single mod directory? Or do I have to create an entire second game install or move all the mods I don't want scanned?
 
So, I tried out the validator, but whenever I run it, it scans the game itself and every single mod in the mod directory, and just dumps a huge list of errors from all of them in one spot. Which is just a giant mess.

Is there any way I can get the validator to scan a specific text file for formatting, or barring that, just a single mod directory? Or do I have to create an entire second game install or move all the mods I don't want scanned?

Unless it's been updated/changed, there should be a drop-down on the right near the top. By default it says "show all errors". You can change this to "show mod errors"

Below that is a Validation Options, which will let you limit it to certain types of file based on what is ticked.

Below the line containing the game directory path is another empty bar; clicking that, you can type in the file name of your Mod, and it will limit it to that mod.


Edit :
I have a problem with a decision. It's a high-priority, and it is recognised by the reminder icon at the top of the screen (if I hover over it, it says "the following important decisions are available: " and correctly lists my decision), but it does not actually appear in the Decisions tab, even if the potential is 'always = yes'. The Validator shows no errors with the decision.
 
Last edited:
Yes add "host = ROOT" after "prisoner = yes"
Or maybe "host = FROM"

This would still scope to other prisoners the character has as well. If this is part of an event chain, the easiest way is to save them as an event target. Otherwise, set a flag on them, and limit for that.

I'm having issues getting an event to fire, and would like someone to proofread the code to help me find where I went wrong. /QUOTE]

Have you run the code in the validator? I don't see anything offhand, except that extra } before your on_actions. If there something like mismatched braces earlier in the file, that could stop later events from firing


Also, does anyone know if there's an equivalent to targetted decisions for artifacts? destroy_artifact seems to be implemented as a regular decision and it probably doing something hard-coded behind the scenes, but I thought I should check to be sure.
 
This would still scope to other prisoners the character has as well. If this is part of an event chain, the easiest way is to save them as an event target. Otherwise, set a flag on them, and limit for that.

I'm assuming the quoting messed up and you have a question in the last part :p.
Sadly there are no targeted decisions for artifacts, best way is to use regular decisions that scopes to them.
 
I'm assuming the quoting messed up and you have a question in the last part :p.
Sadly there are no targeted decisions for artifacts, best way is to use regular decisions that scopes to them.
You should be able to do a third-party targeted decision that targets yourself, with the artifact as the third party. (Look at the code for the send artifact to china decision for guidance. Note that the Jade dragon decision is an offmap decision, and so doesn't need filter and ai_filter. A regular targeted decision would still need those)
 
How do you make traits show up in the ruler designer? I can't seem to figure it out, I've tried adding customizer = yes and a ruler_designer_cost = x but it just doesn't work. The traits themselves aren't broken though, I can assign those through the console just fine.

I have also just run into another weird bug with the traits, they remove themselves from the player character upon saving. This only happens to the player character, not other characters who have this trait, what could be causing this weird behaviour?