Hands-On Usage
random_owned_state is commonly used when you need to randomly pick one state from all states owned by a country (player or AI) and perform an operation on it — for example, randomly adding a construction project to one of your states, triggering a resistance event in a random state, or firing an event in whichever state meets a given condition. The prioritize sub-block lets developers bias the selection toward specific states, reducing the unpredictability of pure randomness.
# Randomly add an infrastructure construction project in one European state that has available building slots
random_owned_state = {
prioritize = { 11 12 13 }
limit = {
is_on_continent = europe
free_building_slots = {
building = infrastructure
size > 0
}
}
add_building_construction = {
type = infrastructure
level = 1
instant_build = no
}
}
Synergy
- is_on_continent — Use inside
limit to restrict selection to states on a specific continent, preventing the effect from spreading across your entire global territory.
- free_building_slots — Use inside
limit to check whether a state has remaining building slots, ensuring add_building_construction can legally execute.
- add_building_construction — The most common child effect; triggers a construction task in whichever state is randomly selected.
- set_state_flag — Flags the randomly chosen state to prevent the same state from being hit multiple times within the same event chain (use alongside has_state_flag to exclude already-flagged states).
Common Pitfalls
- Omitting
limit causes the effect to fire on any state: Without a limit block, the game picks completely at random from all owned states, including core industrial regions, puppet states, and other states that should not be affected — leading to unintended results. Always use limit to precisely constrain the target pool.
- Scope confusion causes child effects to error: Once
random_owned_state executes, the internal scope switches to STATE. You cannot directly call effects that belong exclusively to COUNTRY scope (such as add_ideas) inside it. Use owner = { ... } or a similar construct to explicitly jump back to COUNTRY scope before executing such effects.