Hands-On Usage
random_owned_controlled_state is commonly used in country events or decisions to apply effects to a random state that the country actually owns and controls — for example, constructing fortifications in a random state during wartime, adding manpower, or attaching modifiers. Pairing it with prioritize lets you bias the selection toward specific states, which is ideal for designs like "preferentially reinforce core industrial states."
# The country randomly picks one occupied state that meets the conditions and upgrades its factory construction
random_owned_controlled_state = {
limit = {
is_core_of = ROOT
free_building_slots = {
building = industrial_complex
size > 0
include_locked = no
}
}
prioritize = { 111 112 }
add_extra_state_shared_building_slots = 1
add_building_construction = {
type = industrial_complex
level = 1
instant_build = yes
}
}
Synergy
- is_core_of: Use inside
limit to restrict selection to states that are core territory of the country, preventing resources from being funneled into occupied land.
- free_building_slots: Checks whether the target state still has available building slots, guarding against construction commands silently failing due to no open slots.
- add_state_modifier: Pairs naturally with
random_owned_controlled_state to attach a temporary or permanent state modifier to the randomly selected state — commonly seen in event rewards or disaster penalty scenarios.
- set_state_flag: Stamps a flag on the selected state so that a subsequent
has_state_flag trigger condition can prevent the same state from being picked again.
Common Pitfalls
- Forgetting
limit and hitting unintended states: random_owned_controlled_state draws from all states the country owns and controls. Without a limit, remote overseas territories, colonies, and other peripheral states are all fair game, often producing surprising results. It is strongly recommended to always include at least one is_core_of or has_state_category filter.
prioritize does not mean "guaranteed selection": Beginners often assume that any state ID listed in prioritize will definitely be chosen. In reality, those states must still pass the limit check before they can be prioritized. If a target state fails the limit, the script silently falls back to other qualifying states without throwing an error, creating logic bugs that are easy to miss.