##########################
# Scheme Scripted Effects
##########################

##################################################
# General Scheme Effects

try_to_force_assign_character_to_random_agent_slot_effect = {
	if = {
		limit = {
			$CHAR$ = { is_valid_as_agent_in_any_slot = $SCHEME$ }
		}
		force_assign_character_to_random_agent_slot_effect = {
			SCHEME = $SCHEME$
			CHAR = $CHAR$
			YEARS = $YEARS$
		}
	}
}

force_assign_character_to_random_agent_slot_effect = {
	$SCHEME$ = {
		random_scheme_agent_slot = {
			limit = {
				is_filled = no
				save_temporary_scope_as = slot_temp
				$CHAR$ = { is_valid_as_agent_in_slot = scope:slot_temp }
			}
			save_scope_as = valid_slot
		}
	}
	$CHAR$ = {
		force_add_to_agent_slot = {
			agent_slot = scope:valid_slot
			years = $YEARS$
		}
	}
}

increment_breaches_with_message_effect = {
	scope:owner = {
		send_interface_toast = {
			type = msg_scheme_breached
			title = feed_message.t.scheme_breached
			left_icon = scope:target
			scope:scheme = { add_scheme_breach = 1 }
			play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Scheme_Rework/ep3_mx_sting_schemerework_scheme_suffering_breaches"
		}
	}
}

##################################################
# Ending Effects

# What percentage chance is there that a scheme will be discovered per month?
## tl;dr = generally, 10% of 100 - secrecy rating. So if you have 60% secrecy, that's a 4% chance per month.
hostile_scheme_monthly_discovery_chance_effect = {
	# If we're in the first X months of a scheme, give a grace period.
	if = {
		limit = {
			has_variable = secrecy_grace_period
			var:secrecy_grace_period >= 1
		}
		change_variable = {
			name = secrecy_grace_period
			add = -1
		}
	}
	# Otherwise we want to start checking for discovery.
	else_if = {
		# Without a spymaster, you can't discover schemes.
		## This isn't tooltipped for the person doing the scheming: communicating it (and when it turns on, and when it turns off) would be erratic and spammy, so we just let them think they're getting nice'n'lucky.
		limit = {
			scope:scheme = {
				# Character
				trigger_if = {
					limit = { exists = scheme_target_character.host }
					scheme_target_character.host = { save_temporary_scope_as = breach_host_temp }
				}
				# Title
				trigger_else_if = {
					limit = { exists = scheme_target_title.holder }
					scheme_target_title.holder = { save_temporary_scope_as = breach_host_temp }
				}
				# Fallback
				trigger_else = { always = no }
				scope:breach_host_temp ?= {
					# Second for Adventurers
					trigger_if = { 
						limit = { has_government = landless_adventurer_government }
						court_position:second_camp_officer ?= { save_temporary_scope_as = breach_maker_temp }
					}
					# Spymaster for everyone else
					trigger_else = {
						cp:councillor_spymaster ?= { save_temporary_scope_as = breach_maker_temp }
					}
				}
			}
		}	
		# Sort scopes.
		## Vs. titles.
		if = {
			limit = { exists = scope:target.holder }
			scope:target.holder = { save_scope_as = target }
		}
		## Vs. characters.
		else = {
			scope:target = { save_scope_as = target }
		}
		## Nab the spymaster too.
		scope:breach_maker_temp = { save_scope_as = spymaster }
		# Alright, now we roll for discovery.
		# Save chance for simple debugging
		save_scope_value_as = {
			name = discovery_chance
			value = monthly_scheme_discovery_chance_value
		}
		## ... if scope:target lives at scope:owner's court.
		if = {
			limit = {
				scope:breach_host_temp = scope:owner
				scope:owner != scope:target
				NOT = { exists = scope:scheme.var:had_self_court_discovery }
			}
			random = {
				chance = scope:discovery_chance
				# Either increment breaches.
				if = {
					limit = { scheme_breaches >= scheme_breaches_about_to_hit_limit_value }
					increment_breaches_with_message_effect = yes
				}
				# Or expose us generally.
				else = {
					add_scheme_breach = 1
					scope:owner = { play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Scheme_Rework/ep3_mx_sting_schemerework_scheme_suffering_breaches" }
					set_variable = {
						name = had_self_court_discovery
						value = yes
						years = 3
					}
					scope:owner = {
						if = {
							limit = {
								scope:scheme = { is_savable_murder_scheme_trigger = yes }
							}
							trigger_event = hostile_scheme_discovery.4002
						}
						else = { trigger_event = hostile_scheme_discovery.4001 }
					}
					# Flag that we're discovering something so that on-going events don't fire.
					save_scope_value_as = {
						name = discovery_event_happening
						value = yes
					}
				}
			}
		}
		## ... otherwise they're at different courts.
		else_if = {
			limit = {
				NOR = {
					# You won't expose your own Scheme
					scope:owner = scope:target
					# Spymaster won't expose their own Scheme
					scope:owner = scope:spymaster
					# Spymaster won't expose *your* (liege's) Scheme
					scope:owner = scope:spymaster.liege
					# Spymaster won't expose a scheme if they are an agent of it
					## Secrecy is still relevant, you can still be discovered, just not on the monthly tick.
					scheme_is_character_agent = scope:spymaster
				}
			}
			# Roll to see whether we discover something.
			random = {
				chance = scope:discovery_chance
				# If the scheme isn't exposed, then we do that first.
				if = {
					limit = { is_scheme_exposed = no }
					# Increment our breaches.
					increment_breaches_with_message_effect = yes
					# Fire off an actual warning event.
					scope:target.host ?= { trigger_event = hostile_scheme_discovery.2001 }
					# Flag that we're discovering something so that on-going events don't fire.
					save_scope_value_as = {
						name = discovery_event_happening
						value = yes
					}
				}
				# Else, that means we've hit the limit for the scheme, so we discover and destroy it.
				else_if = {
					limit = { scheme_breaches >= scheme_breaches_about_to_hit_limit_value }
					# Don't forget to increment breaches to max.
					add_scheme_breach = 1
					scope:owner = { play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Scheme_Rework/ep3_mx_sting_schemerework_scheme_suffering_breaches" }
					# Fire off the correct event.
					scope:target.host ?= { trigger_event = hostile_scheme_discovery.1002 }
					# Flag that we're discovering something so that on-going events don't fire.
					save_scope_value_as = {
						name = discovery_event_happening
						value = yes
					}
				}
				# Otherwise, we want to discover an agent.
				else = {
					# Increment our breaches.
					increment_breaches_with_message_effect = yes
					# And reveal an agent, if we can.
					if = {
						limit = {
							any_scheme_agent_character = {
								is_alive = yes
								agent_valid_to_be_discovered_by_spymaster = yes
							}
						}
						ordered_scheme_agent_character = {
							limit = {
								is_alive = yes
								agent_valid_to_be_discovered_by_spymaster = yes
							}
							# Get the least stealthy agent.
							order_by = {
								value = 100
								subtract = intrigue
							}
							save_scope_as = agent
						}
						# If we have a candidate, reveal them.
						scope:target.host ?= { trigger_event = hostile_scheme_discovery.1001 }
						# Flag that we're discovering something so that on-going events don't fire.
						save_scope_value_as = {
							name = discovery_event_happening
							value = yes
						}
					}
				}
			}
		}
	}
}

# Sort the ending for a scheme.
generic_scheme_process_ending_effect = {
	# Grab our scopes.
	save_scope_as = scheme
	scheme_owner = { save_scope_as = owner }
	## Targets.
	scheme_target_character ?= { save_scope_as = target }
	scheme_target_culture ?= { save_scope_as = target }
	scheme_target_faith ?= { save_scope_as = target }
	scheme_target_title ?= { save_scope_as = target }
	# Success roll.
	random = {
		chance = scheme_success_chance
		custom_tooltip = $RESULTS_TOOLTIP$
		save_scope_value_as = {
			name = scheme_successful
			value = yes
		}
		# Interception saves.
		## Unique saves roll.
		### E.g., your dog flings itself in front of an assassin for you.
		if = {
			limit = { is_savable_murder_scheme_trigger = yes }
			# We use a scripted effect so that mods can overwrite it without overwriting the whole block.
			scheme_unique_interception_roll_effect = yes
		}
		## Repeatable saves roll.
		### E.g., your bodyguard flings itself in front of an assassin for you.
		if = {
			limit = { is_savable_murder_scheme_trigger = yes }
			random = {
				chance = scope:target.scheme_intercept_repeatable_chance_total_value
				save_scope_value_as = {
					name = interception_repeatable
					value = yes
				}
			}
		}
	}
	# Secrecy roll.
	## We check this after an interception so that, if a successful scheme is intercepted, we can boost its success a little to compensate.
	if = {
		limit = { is_type_secret = yes }
		## First, determine our secrecy value.
		save_scope_value_as = {
			name = discovery_chance
			value = {
				value = 100
				subtract = scheme_secrecy
				# Boost this up a bit if the scheme was intercepted.
				if = {
					limit = {
						OR = {
							exists = scope:interception_unique
							exists = scope:interception_repeatable
						}
					}
					add = -30
				}
				# And make sure there's always _some_ risk.
				min = 5
			}
		}
		random = {
			chance = scope:discovery_chance
			custom_tooltip = scheme_remain_secret_roll_tt
			save_scope_value_as = {
				name = scheme_discovered
				value = yes
			}
			# Grab an exposer.
			if = {
				limit = { exists = scope:target.host }
				scope:target.host = { save_scope_as = murder_exposer }
			}
			else = {
				scope:target = { save_scope_as = murder_exposer }
			}
			# Set up assorted cosmetics for murders.
			scope:owner = {
				# Portraits.
				save_scope_as = owner_to_reveal
				# Plus a flavour scope we use.
				random_memory = {
					limit = {
						has_memory_category = negative
						has_memory_participant = scope:target
						NOR = { # These read poorly
							has_memory_type = became_rivals
							has_memory_type = became_nemesis
						}
					}
					save_scope_as = bad_memory
				}
			}
		}
	}
	# Process ending on_actions.
	## Scheme intercepted by a unique flag, stopping a killing at the last moment.
	if = {
		limit = { exists = scope:interception_unique }
		scheme_owner = {
			trigger_event = { on_action = pick_unique_murder_intercept_on_action }
		}
	}
	## Scheme intercepted by a repeatable flag, stopping a killing at the last moment.
	else_if = {
		limit = { exists = scope:interception_repeatable }
		scheme_owner = {
			trigger_event = { on_action = pick_repeatable_murder_intercept_on_action }
		}
	}
	## Scheme successful.
	else_if = {
		limit = { exists = scope:scheme_successful }
		# If we have a contract conclusion event to fire, fire it.
		if = {
			limit = { exists = scope:contract_end_success }
			scheme_owner = {
				trigger_event = {
					saved_event_id = scope:contract_end_success
					delayed = yes
				}
			}
		}
		task_contract ?= { complete_task_contract = success_standard }
		trigger_event = { $SUCCESS_EVENT_TYPE$ = $SUCCESS_EVENT_ID$ }
		scope:owner = { 
			play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Scheme_Rework/ep3_mx_sting_schemerework_positive"
			mandala_trickster_increment_successful_schemes_effect = yes
		}		
	}
	## Scheme failed.
	else = {
		# If we have a contract conclusion event to fire, fire it.
		if = {
			limit = { exists = scope:contract_end_failure }
			scheme_owner = {
				trigger_event = {
					saved_event_id = scope:contract_end_failure
					delayed = yes
				}
			}
		}
		task_contract ?= { complete_task_contract = failure_standard }
		trigger_event = { $FAILURE_EVENT_TYPE$ = $FAILURE_EVENT_ID$ }
		scope:owner = { play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Scheme_Rework/ep3_mx_sting_schemerework_negative" }
	}
}

# Roll to see if a one-off factor stops an otherwise-successful murder scheme.
scheme_unique_interception_roll_effect = {
	scope:target = {
		# These are ordered highest % to lowest %: remember to adjust their position in the list if you adjust their percentage likelihood.
		## 50% — Saved by soulmate's sacrifice (boosted).
		if = {
			limit = {
				has_perk = mortal_adoration_perk
				any_relation = {
					type = soulmate
					available_lover_to_sacrifice_in_murder_trigger = { TARGET = scope:target }
				}
			}
			random = {
				chance = 50
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_lover
				}
			}
		}
		## 45% — Family Connections dynasty legacy.
		else_if = {
			limit = {
				dynasty ?= { has_dynasty_perk = guile_legacy_5 }
				NOT = { has_character_flag = guile_legacy_5_save_used }
			}
			random = {
				chance = 45
				save_scope_value_as = {
					name = interception_unique
					value = flag:family_connections_dynleg
				}
			}
		}
		## 30% — Saved by lover's sacrifice (boosted).
		else_if = {
			limit = {
				has_perk = mortal_adoration_perk
				any_relation = {
					type = lover
					available_lover_to_sacrifice_in_murder_trigger = { TARGET = scope:target }
				}
			}
			random = {
				chance = 30
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_lover
				}
			}
		}
		## 20% — Target's warhorse saves them from hired thugs
		else_if = {
			limit = { owns_story_of_type = story_cycle_martial_lifestyle_warhorse }
			random = {
				chance = 20
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_warhorse
				}
			}
		}
		## 20% — Saved by prison pet.
		else_if = {
			limit = {
				is_imprisoned = yes
				has_variable = prison_pet_variable
			}
			random = {
				chance = 20
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_pet_prison
				}
			}
		}
		## 20% — Saved by soulmate's sacrifice (regular).
		else_if = {
			limit = {
				any_relation = {
					type = soulmate
					available_lover_to_sacrifice_in_murder_trigger = { TARGET = scope:target }
				}
			}
			random = {
				chance = 20
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_lover
				}
			}
		}
		## 10% — Saved by lover's sacrifice (regular).
		else_if = {
			limit = {
				any_relation = {
					type = lover
					available_lover_to_sacrifice_in_murder_trigger = { TARGET = scope:target }
				}
			}
			random = {
				chance = 10
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_lover
				}
			}
		}
		## 06% — Saved by cat.
		### Man's _true_ best friend.
		else_if = {
			limit = {
				any_owned_story = { type = story_cycle_pet_cat }
			}
			random = {
				chance = 6
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_cat
				}
			}
		}
		## 05% — Saved by dog.
		else_if = {
			limit = {
				any_owned_story = { type = story_cycle_pet_dog }
			}
			random = {
				chance = 5
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_dog
				}
			}
		}
		## 03% — Saved by due to bilinguality.
		else_if = {
			limit = {
				knows_language_of_culture = scope:owner.culture
				NOR = {
					culture = { has_same_culture_language = scope:owner.culture }
					AND = {
						has_variable_list = bilingual_murder_saves
						is_target_in_variable_list = {
							name = bilingual_murder_saves
							target = scope:owner.culture
						}
					}
				}
			}
			random = {
				chance = 3
				save_scope_value_as = {
					name = interception_unique
					value = flag:knowledge_bilingual
				}
			}
		}
		## 01% — Saved due to mindbreak character.
		else_if = {
			limit = {
				has_variable = mind_broken_victim
				var:mind_broken_victim = {
					is_alive = yes
					NOT = { has_trait = incapable }
				}
			}
			random = {
				chance = 1
				save_scope_value_as = {
					name = interception_unique
					value = flag:sacrifice_mindbreak
				}
			}
		}
		## 00.5% — Saved by having an artefact.
		### Special ridiculously low chance because otherwise this event, which has fun loc, will give _every_ character in the title a 1% chance to nullify any scheme against them.
		else_if = {
			limit = {
				is_available_healthy_adult = yes
				# Gotta be on land.
				exists = location.barony
				# And have a suitable artefact.
				## Which they probably will.
				### Statistically almost always, in fact.
				has_any_artifact = yes
				any_character_artifact = {
					NOT = {  has_variable = saved_from_assassination }
				}
			}
			# Don't tell anyone this is even a possibility, as otherwise it's gonna look weird in the tooltips.
			hidden_effect = {
				random = {
					chance = 1
					# And then reduce the chance even further.
					random = {
						chance = 50
						save_scope_value_as = {
							name = interception_unique
							value = flag:sacrifice_artefact
						}
					}
				}
			}
		}
	}
}

# Reset a scoped scheme, including nixing any modifiers we don't want it to keep.
reset_failed_scheme_effect = {
	reset_scheme_progress = yes
	if = {
		limit = {
			has_scheme_modifier = scheme_end_buff_t2_modifier
		}
		remove_scheme_modifier = scheme_end_buff_t2_modifier
	}
	if = {
		limit = {
			has_scheme_modifier = scheme_end_buff_t3_modifier
		}
		remove_scheme_modifier = scheme_end_buff_t3_modifier
	}
	if = {
		limit = {
			has_scheme_modifier = scheme_end_buff_t4_modifier
		}
		remove_scheme_modifier = scheme_end_buff_t4_modifier
	}
}

##################################################
# General Critical Moment Effects

# Sets up which agents are valid to be added to this scheme, then picks which two to suggest.
## We make a bazillion variants here because it's the easiest solution without having to have a dozen+ empty parameters in a single effect.
roll_critical_moment_options_02_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count <= character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_03_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_04_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_05_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_06_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_07_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_08_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_09_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_10_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_11_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_12_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_13_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_14_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_15_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		## Agent type 15.
		save_scope_value_as = {
			name = agent_type_15
			value = flag:$AGENT_TYPE_15$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOT = { scope:agent_type_15 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_15 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_15$
					}
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_16_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		## Agent type 15.
		save_scope_value_as = {
			name = agent_type_15
			value = flag:$AGENT_TYPE_15$
		}
		## Agent type 16.
		save_scope_value_as = {
			name = agent_type_16
			value = flag:$AGENT_TYPE_16$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOT = { scope:agent_type_15 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOT = { scope:agent_type_16 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_15 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_15$
					}
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_16 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_16$
					}
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_17_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		## Agent type 15.
		save_scope_value_as = {
			name = agent_type_15
			value = flag:$AGENT_TYPE_15$
		}
		## Agent type 16.
		save_scope_value_as = {
			name = agent_type_16
			value = flag:$AGENT_TYPE_16$
		}
		## Agent type 17.
		save_scope_value_as = {
			name = agent_type_17
			value = flag:$AGENT_TYPE_17$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOT = { scope:agent_type_15 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOT = { scope:agent_type_16 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOT = { scope:agent_type_17 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_15 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_15$
					}
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_16 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_16$
					}
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_17 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_17$
					}
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_18_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		## Agent type 15.
		save_scope_value_as = {
			name = agent_type_15
			value = flag:$AGENT_TYPE_15$
		}
		## Agent type 16.
		save_scope_value_as = {
			name = agent_type_16
			value = flag:$AGENT_TYPE_16$
		}
		## Agent type 17.
		save_scope_value_as = {
			name = agent_type_17
			value = flag:$AGENT_TYPE_17$
		}
		## Agent type 18.
		save_scope_value_as = {
			name = agent_type_18
			value = flag:$AGENT_TYPE_18$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOT = { scope:agent_type_15 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOT = { scope:agent_type_16 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOT = { scope:agent_type_17 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
			# Agent type 18.
			0 = {
				trigger = {
					NOT = { scope:agent_type_18 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_18$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_18$
				}
				modifier = {
					add = $AGENT_TYPE_18_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_18$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_15 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_15$
					}
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_16 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_16$
					}
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_17 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_17$
					}
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
			# Agent type 18.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_18 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_18$
					}
					scheme_owner = { can_have_$AGENT_TYPE_18$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_18$
				}
				modifier = {
					add = $AGENT_TYPE_18_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_18$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_19_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		## Agent type 15.
		save_scope_value_as = {
			name = agent_type_15
			value = flag:$AGENT_TYPE_15$
		}
		## Agent type 16.
		save_scope_value_as = {
			name = agent_type_16
			value = flag:$AGENT_TYPE_16$
		}
		## Agent type 17.
		save_scope_value_as = {
			name = agent_type_17
			value = flag:$AGENT_TYPE_17$
		}
		## Agent type 18.
		save_scope_value_as = {
			name = agent_type_18
			value = flag:$AGENT_TYPE_18$
		}
		## Agent type 19.
		save_scope_value_as = {
			name = agent_type_19
			value = flag:$AGENT_TYPE_19$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOT = { scope:agent_type_15 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOT = { scope:agent_type_16 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOT = { scope:agent_type_17 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
			# Agent type 18.
			0 = {
				trigger = {
					NOT = { scope:agent_type_18 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_18$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_18$
				}
				modifier = {
					add = $AGENT_TYPE_18_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_18$ }
				}
			}
			# Agent type 19.
			0 = {
				trigger = {
					NOT = { scope:agent_type_19 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_19$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_19$
				}
				modifier = {
					add = $AGENT_TYPE_19_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_19$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_15 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_15$
					}
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_16 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_16$
					}
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_17 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_17$
					}
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
			# Agent type 18.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_18 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_18$
					}
					scheme_owner = { can_have_$AGENT_TYPE_18$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_18$
				}
				modifier = {
					add = $AGENT_TYPE_18_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_18$ }
				}
			}
			# Agent type 19.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_19 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_19$
					}
					scheme_owner = { can_have_$AGENT_TYPE_19$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_19$
				}
				modifier = {
					add = $AGENT_TYPE_19_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_19$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}
roll_critical_moment_options_20_agent_types_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:$OUTPUT_EVENT$
	}
	if = {
		limit = {
			any_scheme_agent_slot = { count < character_max_scheme_agents_value }
			scope:scheme = {
				NOR = {
					has_variable = choice_a
					has_variable = choice_b
				}
			}
		}
		# First, let's determine which types we're using and which we ain't.
		## Agent type 01.
		save_scope_value_as = {
			name = agent_type_01
			value = flag:$AGENT_TYPE_01$
		}
		## Agent type 02.
		save_scope_value_as = {
			name = agent_type_02
			value = flag:$AGENT_TYPE_02$
		}
		## Agent type 03.
		save_scope_value_as = {
			name = agent_type_03
			value = flag:$AGENT_TYPE_03$
		}
		## Agent type 04.
		save_scope_value_as = {
			name = agent_type_04
			value = flag:$AGENT_TYPE_04$
		}
		## Agent type 05.
		save_scope_value_as = {
			name = agent_type_05
			value = flag:$AGENT_TYPE_05$
		}
		## Agent type 06.
		save_scope_value_as = {
			name = agent_type_06
			value = flag:$AGENT_TYPE_06$
		}
		## Agent type 07.
		save_scope_value_as = {
			name = agent_type_07
			value = flag:$AGENT_TYPE_07$
		}
		## Agent type 08.
		save_scope_value_as = {
			name = agent_type_08
			value = flag:$AGENT_TYPE_08$
		}
		## Agent type 09.
		save_scope_value_as = {
			name = agent_type_09
			value = flag:$AGENT_TYPE_09$
		}
		## Agent type 10.
		save_scope_value_as = {
			name = agent_type_10
			value = flag:$AGENT_TYPE_10$
		}
		## Agent type 11.
		save_scope_value_as = {
			name = agent_type_11
			value = flag:$AGENT_TYPE_11$
		}
		## Agent type 12.
		save_scope_value_as = {
			name = agent_type_12
			value = flag:$AGENT_TYPE_12$
		}
		## Agent type 13.
		save_scope_value_as = {
			name = agent_type_13
			value = flag:$AGENT_TYPE_13$
		}
		## Agent type 14.
		save_scope_value_as = {
			name = agent_type_14
			value = flag:$AGENT_TYPE_14$
		}
		## Agent type 15.
		save_scope_value_as = {
			name = agent_type_15
			value = flag:$AGENT_TYPE_15$
		}
		## Agent type 16.
		save_scope_value_as = {
			name = agent_type_16
			value = flag:$AGENT_TYPE_16$
		}
		## Agent type 17.
		save_scope_value_as = {
			name = agent_type_17
			value = flag:$AGENT_TYPE_17$
		}
		## Agent type 18.
		save_scope_value_as = {
			name = agent_type_18
			value = flag:$AGENT_TYPE_18$
		}
		## Agent type 19.
		save_scope_value_as = {
			name = agent_type_19
			value = flag:$AGENT_TYPE_19$
		}
		## Agent type 20.
		save_scope_value_as = {
			name = agent_type_20
			value = flag:$AGENT_TYPE_20$
		}
		# Then we roll for who's getting picked.
		## For var:choice_a.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOT = { scope:agent_type_01 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOT = { scope:agent_type_02 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOT = { scope:agent_type_03 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOT = { scope:agent_type_04 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOT = { scope:agent_type_05 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOT = { scope:agent_type_06 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOT = { scope:agent_type_07 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOT = { scope:agent_type_08 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOT = { scope:agent_type_09 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOT = { scope:agent_type_10 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOT = { scope:agent_type_11 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOT = { scope:agent_type_12 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOT = { scope:agent_type_13 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOT = { scope:agent_type_14 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOT = { scope:agent_type_15 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOT = { scope:agent_type_16 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOT = { scope:agent_type_17 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
			# Agent type 18.
			0 = {
				trigger = {
					NOT = { scope:agent_type_18 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_18$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_18$
				}
				modifier = {
					add = $AGENT_TYPE_18_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_18$ }
				}
			}
			# Agent type 19.
			0 = {
				trigger = {
					NOT = { scope:agent_type_19 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_19$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_19$
				}
				modifier = {
					add = $AGENT_TYPE_19_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_19$ }
				}
			}
			# Agent type 20.
			0 = {
				trigger = {
					NOT = { scope:agent_type_20 = flag:empty }
					scheme_owner = { can_have_$AGENT_TYPE_20$_trigger = yes }
				}
				set_variable = {
					name = choice_a
					value = flag:$AGENT_TYPE_20$
				}
				modifier = {
					add = $AGENT_TYPE_20_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_20$ }
				}
			}
		}
		## And var:choice_b.
		random_list = {
			# Agent type 01.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_01 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_01$
					}
					scheme_owner = { can_have_$AGENT_TYPE_01$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_01$
				}
				modifier = {
					add = $AGENT_TYPE_01_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_01$ }
				}
			}
			# Agent type 02.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_02 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_02$
					}
					scheme_owner = { can_have_$AGENT_TYPE_02$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_02$
				}
				modifier = {
					add = $AGENT_TYPE_02_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_02$ }
				}
			}
			# Agent type 03.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_03 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_03$
					}
					scheme_owner = { can_have_$AGENT_TYPE_03$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_03$
				}
				modifier = {
					add = $AGENT_TYPE_03_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_03$ }
				}
			}
			# Agent type 04.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_04 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_04$
					}
					scheme_owner = { can_have_$AGENT_TYPE_04$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_04$
				}
				modifier = {
					add = $AGENT_TYPE_04_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_04$ }
				}
			}
			# Agent type 05.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_05 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_05$
					}
					scheme_owner = { can_have_$AGENT_TYPE_05$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_05$
				}
				modifier = {
					add = $AGENT_TYPE_05_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_05$ }
				}
			}
			# Agent type 06.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_06 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_06$
					}
					scheme_owner = { can_have_$AGENT_TYPE_06$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_06$
				}
				modifier = {
					add = $AGENT_TYPE_06_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_06$ }
				}
			}
			# Agent type 07.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_07 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_07$
					}
					scheme_owner = { can_have_$AGENT_TYPE_07$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_07$
				}
				modifier = {
					add = $AGENT_TYPE_07_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_07$ }
				}
			}
			# Agent type 08.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_08 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_08$
					}
					scheme_owner = { can_have_$AGENT_TYPE_08$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_08$
				}
				modifier = {
					add = $AGENT_TYPE_08_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_08$ }
				}
			}
			# Agent type 09.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_09 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_09$
					}
					scheme_owner = { can_have_$AGENT_TYPE_09$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_09$
				}
				modifier = {
					add = $AGENT_TYPE_09_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_09$ }
				}
			}
			# Agent type 10.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_10 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_10$
					}
					scheme_owner = { can_have_$AGENT_TYPE_10$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_10$
				}
				modifier = {
					add = $AGENT_TYPE_10_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_10$ }
				}
			}
			# Agent type 11.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_11 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_11$
					}
					scheme_owner = { can_have_$AGENT_TYPE_11$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_11$
				}
				modifier = {
					add = $AGENT_TYPE_11_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_11$ }
				}
			}
			# Agent type 12.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_12 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_12$
					}
					scheme_owner = { can_have_$AGENT_TYPE_12$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_12$
				}
				modifier = {
					add = $AGENT_TYPE_12_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_12$ }
				}
			}
			# Agent type 13.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_13 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_13$
					}
					scheme_owner = { can_have_$AGENT_TYPE_13$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_13$
				}
				modifier = {
					add = $AGENT_TYPE_13_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_13$ }
				}
			}
			# Agent type 14.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_14 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_14$
					}
					scheme_owner = { can_have_$AGENT_TYPE_14$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_14$
				}
				modifier = {
					add = $AGENT_TYPE_14_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_14$ }
				}
			}
			# Agent type 15.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_15 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_15$
					}
					scheme_owner = { can_have_$AGENT_TYPE_15$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_15$
				}
				modifier = {
					add = $AGENT_TYPE_15_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_15$ }
				}
			}
			# Agent type 16.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_16 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_16$
					}
					scheme_owner = { can_have_$AGENT_TYPE_16$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_16$
				}
				modifier = {
					add = $AGENT_TYPE_16_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_16$ }
				}
			}
			# Agent type 17.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_17 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_17$
					}
					scheme_owner = { can_have_$AGENT_TYPE_17$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_17$
				}
				modifier = {
					add = $AGENT_TYPE_17_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_17$ }
				}
			}
			# Agent type 18.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_18 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_18$
					}
					scheme_owner = { can_have_$AGENT_TYPE_18$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_18$
				}
				modifier = {
					add = $AGENT_TYPE_18_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_18$ }
				}
			}
			# Agent type 19.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_19 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_19$
					}
					scheme_owner = { can_have_$AGENT_TYPE_19$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_19$
				}
				modifier = {
					add = $AGENT_TYPE_19_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_19$ }
				}
			}
			# Agent type 20.
			0 = {
				trigger = {
					NOR = {
						scope:agent_type_20 = flag:empty
						var:choice_a = flag:$AGENT_TYPE_20$
					}
					scheme_owner = { can_have_$AGENT_TYPE_20$_trigger = yes }
				}
				set_variable = {
					name = choice_b
					value = flag:$AGENT_TYPE_20$
				}
				modifier = {
					add = $AGENT_TYPE_20_WEIGHT$
					always = yes
				}
				modifier = {
					factor = weight_down_existing_agent_slots_value
					any_scheme_agent_slot = { is_agent_slot_type = $AGENT_TYPE_20$ }
				}
			}
		}
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0001 }
	}
}

# Add an agent type to a scheme.
## When you add a new agent type, add them to the bottom of this effect. Everything else should be taken care of automatically.
select_critical_moment_agents_effect = {
	if = {
		limit = { $CHOICE$ = flag:agent_assassin }
		scope:scheme = { add_agent_slot = agent_assassin }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_assassin
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_lookout }
		scope:scheme = { add_agent_slot = agent_lookout }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_lookout
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_infiltrator }
		scope:scheme = { add_agent_slot = agent_infiltrator }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_infiltrator
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_footpad }
		scope:scheme = { add_agent_slot = agent_footpad }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_footpad
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_alibi }
		scope:scheme = { add_agent_slot = agent_alibi }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_alibi
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_thug }
		scope:scheme = { add_agent_slot = agent_thug }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_thug
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_comrade_in_arms }
		scope:scheme = { add_agent_slot = agent_comrade_in_arms }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_comrade_in_arms
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_socialite }
		scope:scheme = { add_agent_slot = agent_socialite }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_socialite
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_musician }
		scope:scheme = { add_agent_slot = agent_musician }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_musician
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_tumbler }
		scope:scheme = { add_agent_slot = agent_tumbler }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_tumbler
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_poet }
		scope:scheme = { add_agent_slot = agent_poet }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_poet
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_gabbler }
		scope:scheme = { add_agent_slot = agent_gabbler }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_gabbler
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_shill }
		scope:scheme = { add_agent_slot = agent_shill }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_shill
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_diplomat }
		scope:scheme = { add_agent_slot = agent_diplomat }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_diplomat
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_justiciar }
		scope:scheme = { add_agent_slot = agent_justiciar }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_justiciar
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_scribe }
		scope:scheme = { add_agent_slot = agent_scribe }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_scribe
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_cleric }
		scope:scheme = { add_agent_slot = agent_cleric }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_cleric
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_theologian }
		scope:scheme = { add_agent_slot = agent_theologian }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_theologian
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_herald }
		scope:scheme = { add_agent_slot = agent_herald }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_herald
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_wolf_hunter }
		scope:scheme = { add_agent_slot = agent_wolf_hunter }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_wolf_hunter
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_thief }
		scope:scheme = { add_agent_slot = agent_thief }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_thief
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_tutor }
		scope:scheme = { add_agent_slot = agent_tutor }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_tutor
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_poisoner }
		scope:scheme = { add_agent_slot = agent_poisoner }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_poisoner
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_eunuch }
		scope:scheme = { add_agent_slot = agent_eunuch }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_eunuch
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_decoy }
		scope:scheme = { add_agent_slot = agent_decoy }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_decoy
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_muscle }
		scope:scheme = { add_agent_slot = agent_muscle }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_muscle
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_drillmaster }
		scope:scheme = { add_agent_slot = agent_drillmaster }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_drillmaster
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_tracker }
		scope:scheme = { add_agent_slot = agent_tracker }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_tracker
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_physic }
		scope:scheme = { add_agent_slot = agent_physic }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_physic
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_smith }
		scope:scheme = { add_agent_slot = agent_smith }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_smith
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_ambusher }
		scope:scheme = { add_agent_slot = agent_ambusher }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_ambusher
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_bodyguard }
		scope:scheme = { add_agent_slot = agent_bodyguard }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_bodyguard
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_scout }
		scope:scheme = { add_agent_slot = agent_scout }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_scout
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_outrider }
		scope:scheme = { add_agent_slot = agent_outrider }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_outrider
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_bookkeeper }
		scope:scheme = { add_agent_slot = agent_bookkeeper }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_bookkeeper
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_bailiff }
		scope:scheme = { add_agent_slot = agent_bailiff }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_bailiff
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_draughtsman }
		scope:scheme = { add_agent_slot = agent_draughtsman }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_draughtsman
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_planner }
		scope:scheme = { add_agent_slot = agent_planner }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_planner
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_supplier }
		scope:scheme = { add_agent_slot = agent_supplier }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_supplier
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_outcast }
		scope:scheme = { add_agent_slot = agent_outcast }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_outcast
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_wrangler }
		scope:scheme = { add_agent_slot = agent_wrangler }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_wrangler
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_wrangler_speed }
		scope:scheme = { add_agent_slot = agent_wrangler_speed }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_wrangler_speed
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_theologian_success }
		scope:scheme = { add_agent_slot = agent_theologian_success }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_theologian_success
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_cleric_success }
		scope:scheme = { add_agent_slot = agent_cleric_success }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_cleric_success
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_lookout_success }
		scope:scheme = { add_agent_slot = agent_lookout_success }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_lookout_success
		}
	}
	else_if = {
		limit = { $CHOICE$ = flag:agent_lookout_speed }
		scope:scheme = { add_agent_slot = agent_lookout_speed }
		# Error suppression.
		save_scope_value_as = {
			name = $CHOICE$
			value = flag:agent_lookout_speed
		}
	}
	# And remove the variables.
	scope:scheme = {
		remove_variable = choice_a
		remove_variable = choice_b
	}
}

# Stop schemes from overflowing with opportunities forever + tell the player when they should do something.
cap_schemes_and_fire_reminders_effect = {
	if = {
		limit = {
			scheme_agent_charges >= opportunity_cap_value
			scheme_success_chance >= max_scheme_success_chance
		}
		if = {
			limit = {
				scheme_owner = {
					is_ai = no
					NOR = {
						has_character_flag = scheme_critical_moments.0011
						has_variable = opportunities_reminder
					}
				}
			}
			scheme_owner = {
				add_character_flag = currently_in_scheme_reminder
				# supress the 'variable is used but is never set' error, the flag is set through code with the cooldown effect on the event, smh!
				if = {
					limit = {
						always = no
					}
					add_character_flag = scheme_critical_moments.0011
				}
			}
			switch = {
				trigger = scheme_type
				murder = {
					murder_scheme_prep_effect = yes
				}
				abduct = {
					abduct_scheme_prep_effect = yes
				}
				challenge_status = {
					challenge_status_scheme_prep_effect = yes
				}
				claim_throne = {
					claim_throne_scheme_prep_effect = yes
				}
				depose = {
					depose_scheme_prep_effect = yes
				}
				overthrow_regent = {
					overthrow_regent_scheme_prep_effect = yes
				}
				expand_power_base = {
					expand_power_base_scheme_prep_effect = yes
				}
				fabricate_hook = {
					fabricate_hook_scheme_prep_effect = yes
				}
				generate_claim = {
					generate_claim_scheme_prep_effect = yes
				}
				promote = {
					promote_scheme_prep_effect = yes
				}
				slander = {
					slander_scheme_prep_effect = yes
				}
				steal_back_artifact = {
					steal_back_artifact_scheme_prep_effect = yes
				}
				seize_realm = {
					seize_realm_scheme_prep_effect = yes
				}
				found_despotate = {
					found_despotate_scheme_prep_effect = yes
				}
				raid_estate = {
					raid_estate_scheme_prep_effect = yes
				}
				prepare_fire_dromons_scheme = {
					prepare_fire_dromons_scheme_prep_effect = yes
				}
				steal_herd = {
					steal_herd_scheme_prep_effect = yes
				}
				celestial_siphon_treasury = {
					celestial_siphon_treasury_prep_effect = yes
				}
				disbelieve_mandala = {
					disbelieve_mandala_scheme_prep_effect = yes
				}
				coerce_tributary = {
					coerce_tributary_scheme_prep_effect = yes
				}
			}
		}
		# If the player hasn't been reminded once, tell them that their scheme has hit max opportunities.
		scheme_owner = {
			if = {
				limit = {
					is_ai = no
					NOT = { has_variable = opportunities_reminder }
				}
				trigger_event = scheme_critical_moments.0011
			}
		}
	}
}

# Tell schemes to wait for the player's say-so before firing a follow-up event.
suppress_scheme_follow_up_event_till_input_given_effect = {
	save_scope_value_as = {
		name = suppress_next_event
		value = yes
	}
}

# Improve a certain type of modifier attached to the scheme, burning opportunities to do so.
improve_scheme_preparation_burnt_opportunities_modifier_effect = {
	# Cap us at 10.
	if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_10 }
		# We should never be able to take the option at this point, but if we break it somehow, then do nothing rather than doubling up.
	}
	# 9 -> 10.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_09 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_09 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_10 }
	}
	# 8 -> 9.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_08 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_08 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_09 }
	}
	# 7 -> 8.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_07 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_07 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_08 }
	}
	# 6 -> 7.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_06 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_06 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_07 }
	}
	# 5 -> 6.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_05 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_05 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_06 }
	}
	# 4 -> 5.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_04 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_04 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_05 }
	}
	# 3 -> 4.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_03 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_03 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_04 }
	}
	# 2 -> 3.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_02 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_02 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_03 }
	}
	# 1 -> 2.
	else_if = {
		limit = { has_scheme_modifier = $MODIFIER$_level_01 }
		# Clean the previous level.
		hidden_effect = { remove_scheme_modifier = $MODIFIER$_level_01 }
		# Add the new one.
		add_scheme_modifier = { type = $MODIFIER$_level_02 }
	}
	# 0 -> 1.
	else = {
		# Add the first rung..
		add_scheme_modifier = { type = $MODIFIER$_level_01 }
	}
}

##################################################
# AI Usage Critical Moment Effects — Regular Schemes

murder_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1001
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

seduce_scheme_prep_effect = {
	roll_critical_moment_options_07_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1011
		# Lookout
		AGENT_TYPE_01 = agent_lookout
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Infiltrator
		AGENT_TYPE_02 = agent_infiltrator
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Comrade_in_arms
		AGENT_TYPE_03 = agent_comrade_in_arms
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
		# Socialite
		AGENT_TYPE_04 = agent_socialite
		AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
		# Musician
		AGENT_TYPE_05 = agent_musician
		AGENT_TYPE_05_WEIGHT = critical_moment_agent_weight_low_value
		# Tumbler
		AGENT_TYPE_06 = agent_tumbler
		AGENT_TYPE_06_WEIGHT = critical_moment_agent_weight_low_value
		# Poet
		AGENT_TYPE_07 = agent_poet
		AGENT_TYPE_07_WEIGHT = critical_moment_agent_weight_low_value
	}
}

abduct_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1061
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

befriend_scheme_prep_effect = {
	roll_critical_moment_options_04_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1031
		# Socialite
		AGENT_TYPE_01 = agent_socialite
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Infiltrator
		AGENT_TYPE_02 = agent_infiltrator
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Gabbler
		AGENT_TYPE_03 = agent_gabbler
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
		# Shill
		AGENT_TYPE_04 = agent_shill
		AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
	}
}

challenge_status_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1171
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

claim_throne_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1101
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

convert_to_witchcraft_scheme_prep_effect = {
	roll_critical_moment_options_03_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1121
		# Infiltrator
		AGENT_TYPE_01 = agent_infiltrator
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Shill
		AGENT_TYPE_02 = agent_shill
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Alibi
		AGENT_TYPE_03 = agent_alibi
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
	}
}

court_scheme_prep_effect = {
	roll_critical_moment_options_07_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1041
		# Herald
		AGENT_TYPE_01 = agent_herald
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Comrade-in-Arms
		AGENT_TYPE_02 = agent_comrade_in_arms
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Socialite
		AGENT_TYPE_03 = agent_socialite
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
		# Musician
		AGENT_TYPE_04 = agent_musician
		AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_very_low_value
		# Poet
		AGENT_TYPE_05 = agent_poet
		AGENT_TYPE_05_WEIGHT = critical_moment_agent_weight_very_low_value
		# Tumbler
		AGENT_TYPE_06 = agent_tumbler
		AGENT_TYPE_06_WEIGHT = critical_moment_agent_weight_very_low_value
		# Wolf Hunter
		AGENT_TYPE_07 = agent_wolf_hunter
		AGENT_TYPE_07_WEIGHT = critical_moment_agent_weight_microscopic_value
	}
}

damage_legitimacy_scheme_prep_effect = {
	roll_critical_moment_options_03_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.4010
		# Infiltrator
		AGENT_TYPE_01 = agent_infiltrator
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Diplomat
		AGENT_TYPE_02 = agent_diplomat
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Socialite
		AGENT_TYPE_03 = agent_socialite
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_medium_value
	}
}

depose_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1191
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

overthrow_regent_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1091
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

elope_scheme_prep_effect = {
	roll_critical_moment_options_07_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1051
		# Infiltrator
		AGENT_TYPE_01 = agent_infiltrator
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Comrade_in_arms
		AGENT_TYPE_02 = agent_comrade_in_arms
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Socialite
		AGENT_TYPE_03 = agent_socialite
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
		# Alibi
		AGENT_TYPE_04 = agent_alibi
		AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
		# Musician
		AGENT_TYPE_05 = agent_musician
		AGENT_TYPE_05_WEIGHT = critical_moment_agent_weight_very_low_value
		# Poet
		AGENT_TYPE_06 = agent_poet
		AGENT_TYPE_06_WEIGHT = critical_moment_agent_weight_very_low_value
		# Tumbler
		AGENT_TYPE_07 = agent_tumbler
		AGENT_TYPE_07_WEIGHT = critical_moment_agent_weight_very_low_value
	}
}

expand_power_base_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1181
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

fabricate_hook_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1071
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

foster_legitimacy_scheme_prep_effect = {
	roll_critical_moment_options_03_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.4000
		
		# Herald
		AGENT_TYPE_01 = agent_herald
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Diplomat
		AGENT_TYPE_02 = agent_diplomat
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Socialite
		AGENT_TYPE_03 = agent_socialite
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_medium_value
	}
}

generate_claim_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1151
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

learn_language_scheme_prep_effect = {
	roll_critical_moment_options_04_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1081
		# Diplomat
		AGENT_TYPE_01 = agent_diplomat
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Cleric
		AGENT_TYPE_02 = agent_cleric
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Scribe
		AGENT_TYPE_03 = agent_scribe
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
		# Tutor
		AGENT_TYPE_04 = agent_tutor
		AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
	}
}

promote_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1141
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

slander_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1131
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

steal_back_artifact_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1111
	}
	scope:scheme.var:target_artifact = {
		save_scope_as = artifact
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

steal_herd_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1161
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

celestial_siphon_treasury_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1201
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}	
}

celestial_movement_power_promote_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1231
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}	
}

celestial_movement_power_slander_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1234
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}	
}

sway_scheme_prep_effect = {
	roll_critical_moment_options_07_agent_types_effect = {
		# Success results event.
		OUTPUT_EVENT = scheme_critical_moments.1021
		# Herald
		AGENT_TYPE_01 = agent_herald
		AGENT_TYPE_01_WEIGHT = critical_moment_agent_weight_high_value
		# Diplomat
		AGENT_TYPE_02 = agent_diplomat
		AGENT_TYPE_02_WEIGHT = critical_moment_agent_weight_high_value
		# Gabbler
		AGENT_TYPE_03 = agent_gabbler
		AGENT_TYPE_03_WEIGHT = critical_moment_agent_weight_high_value
		# Shill
		AGENT_TYPE_04 = agent_shill
		AGENT_TYPE_04_WEIGHT = critical_moment_agent_weight_medium_value
		# Musician
		AGENT_TYPE_05 = agent_musician
		AGENT_TYPE_05_WEIGHT = critical_moment_agent_weight_low_value
		# Tumbler
		AGENT_TYPE_06 = agent_tumbler
		AGENT_TYPE_06_WEIGHT = critical_moment_agent_weight_low_value
		# Poet
		AGENT_TYPE_07 = agent_poet
		AGENT_TYPE_07_WEIGHT = critical_moment_agent_weight_low_value
	}
}

seize_realm_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2901
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

found_despotate_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.8021
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

raid_estate_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.8035
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

ingratiate_family_scheme_prep_effect = {
	save_scope_as = scheme
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.8051 }
	}
}

prepare_fire_dromons_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.8060
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

disbelieve_mandala_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1211
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

coerce_tributary_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1221
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

coerce_contribution_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1241
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

leverage_contribution_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.1251
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

##################################################
# AI Usage Critical Moment Effects — Contract Schemes

laamp_base_0001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2001
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_0011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2011
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_0021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2021
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_0031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2031
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_0041_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2041
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_1001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2201
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_1011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2211
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_1021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2221
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_1031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2231
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_1041_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2241
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_2001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2401
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_2011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2411
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_2021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2421
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_2031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2431
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_2041_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2441
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_3001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2601
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_3011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2611
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_3021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2621
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_3031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2631
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_3041_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2641
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_4001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2801
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_4011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2811
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_4021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2821
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_4031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2831
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_4041_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2841
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_5001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3001
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_5011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3011
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_5021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3021
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_5031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3031
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_5041_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3041
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_5051_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3051
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_6001_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.6001
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_6011_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.6011
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_6021_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.6021
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_base_6031_contract_scheme_prep_effect = {
	save_scope_as = scheme
	scope:scheme.task_contract ?= { save_scope_as = task_contract }
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.6031
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

protect_minority_vassal_contract_diplomacy_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3201
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

protect_minority_vassal_contract_martial_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3201
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

protect_minority_vassal_contract_intrigue_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3201
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

protect_minority_vassal_contract_learning_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3201
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_prison_break_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3211
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

laamp_help_find_secrets_scheme_prep_effect = {
	save_scope_as = scheme
	task_contract = {
		save_scope_as = task_contract
		var:task_contract_councillor = {
			save_scope_as = task_contract_councillor
		}
	}
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.3221
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

celestial_minister_find_secrets_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.8065
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

##################################################
# Murder Scheme Effects

# Give out the appropriate amount of dread when it's discovered the scoped char murdered someone.
murder_consequences_known_or_exposed_apply_dread_effect = {
	# Don't apply this twice if it's gone out earlier in the chain.
	if = {
		limit = {
			NOT = { exists = scope:murderer_dread_applied }
		}
		# Murdered own close family, king/emperor, or family of king/emperor.
		if = {
			limit = {
				OR = {
					is_close_family_of = $VICTIM$
					$VICTIM$ = {
						tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_kingdom }
					}
				}
			}
			add_dread = major_dread_gain
		}
		# Murdered close family of duke/count.
		else_if = {
			limit = {
				$VICTIM$ = {
					tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_county }
				}
			}
			add_dread = medium_dread_gain
		}
		# Murdered just... some guy. Just a person. Just a lil dude.
		else = { add_dread = minor_dread_gain }
		# And flag that we've gone through this.
		save_scope_value_as = {
			name = murderer_dread_applied
			value = yes
		}
	}
}

# Apply scope:owner's general ending & consequences.
scheme_owner_pov_murder_success_effect = {
	# Murdering your rival gets you some bonus cred.
	## Presumably in how you comport yourself & who's a thorn in your side.
	if = {
		limit = {
			scope:owner = { has_relation_rival = scope:target }
		}
		custom_tooltip = {
			text = murder_outcome_murdered_rival_tt
			add_prestige = medium_prestige_gain
		}
	}
	# Dread for successfully murdering someone and getting discovered.
	if = {
		limit = { exists = scope:scheme_discovered }
		murder_consequences_known_or_exposed_apply_dread_effect = { VICTIM = scope:target }
	}
	# Piety, if appropriate.
	if = {
		limit = {
			faith = { has_doctrine_parameter = piety_gain_from_successful_intrigue_schemes }
		}
		add_piety = minor_piety_gain
	}
	# Stress.
	## Murdered a rival.
	if = {
		limit = {
			scope:owner = { has_relation_rival = scope:target }
		}
		stress_impact = {
			base = murder_base_stress_value
			vengeful = massive_stress_impact_loss
			sadistic = minor_stress_impact_loss
			callous = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
	}
	## Murdered someone helpless.
	else_if = {
		limit = {
			scope:target = {
				OR = {
					is_adult = no
					is_incapable = yes
				}
			}
		}
		stress_impact = {
			base = murder_base_stress_value
			sadistic = major_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
		}
	}
	## Murdered anyone else.
	else = {
		stress_impact = {
			base = murder_base_stress_value
			sadistic = minor_stress_impact_loss
			callous = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}
	# Aaaaand show our other consequences.
	show_as_tooltip = {
		murder_success_kill_effect = { REASON = $REASON$ }
	}
}

# Actually kill scope:target.
murder_success_kill_effect = {
	# If the scheme was discovered, reveal the murderer immediately.
	if = {
		limit = { exists = scope:scheme_discovered }
		# Kill the target.
		known_murder_effect = {
			VICTIM = scope:target
			MURDERER = scope:owner
			EXPOSER = scope:murder_exposer
		}
		# Kill them. Kill them all.
		murder_success_kill_entourage_too_effect = {
			KNOWN_UNKNOWN = known
			EXPOSER_REASON_PRE = EXPOSER
			EXPOSER_REASON_POST = scope:murder_exposer
			SHOW_UNKNOWN_ASSAILANT_TOOLTIP = no
		}
	}
	# Otherwise, we process this anonymously.
	else = {
		# For scope:owner, we only show the effects as tooltips.
		if = {
			limit = { this = scope:owner }
			show_as_tooltip = {
				unknown_murder_effect = {
					VICTIM = scope:target
					MURDERER = scope:owner
					REASON = $REASON$
				}
			}
			# Kill them. Kill them all.
			show_as_tooltip = {
				murder_success_kill_entourage_too_effect = {
					KNOWN_UNKNOWN = unknown
					EXPOSER_REASON_PRE = REASON
					EXPOSER_REASON_POST = death_mysterious
					SHOW_UNKNOWN_ASSAILANT_TOOLTIP = no
				}
			}
		}
		# Whereas for the target, we process the whole lot.
		else_if = {
			limit = { this = scope:target }
			custom_tooltip = murder_unknown_murder_against_you_was_successful
			hidden_effect = {
				unknown_murder_effect = {
					VICTIM = scope:target
					MURDERER = scope:owner
					REASON = $REASON$
				}
			}
			# Kill them. Kill them all.
			murder_success_kill_entourage_too_effect = {
				KNOWN_UNKNOWN = unknown
				EXPOSER_REASON_PRE = REASON
				EXPOSER_REASON_POST = death_mysterious
				SHOW_UNKNOWN_ASSAILANT_TOOLTIP = yes
			}
		}
	}
}

# If appropriate, kill off a bunch of the folks travelling with scope:target.
murder_success_kill_entourage_too_effect = {
	scope:owner ?= {
		if = {
			limit = { has_variable_list = entourage_members_to_kill }
			save_temporary_scope_value_as = {
				name = show_unknown_assailant_tooltip
				value = $SHOW_UNKNOWN_ASSAILANT_TOOLTIP$
			}
			every_in_list = {
				variable = entourage_members_to_kill
				save_temporary_scope_as = to_be_killed
				if = {
					limit = { scope:show_unknown_assailant_tooltip = yes }
					custom_tooltip = murder_unknown_murder_against_you_was_successful_other
				}
				$KNOWN_UNKNOWN$_murder_effect = {
					VICTIM = scope:to_be_killed
					MURDERER = scope:owner
					$EXPOSER_REASON_PRE$ = $EXPOSER_REASON_POST$
				}
			}
		}
	}
}

# Distribute murder failure effects.
murder_failure_effect = {
 	# Add Watchful Modifier to the target
	scope:target = {
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
	# If the attempt was discovered, process the consequences of that.
	if = {
		limit = { exists = scope:scheme_discovered }
		# If we're a clan this affects unity
		## Landed victims cost more unity.
		if = {
			limit = {
				scope:target = { is_landed = yes }
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:owner
				TARGET = scope:target
				VALUE = medium_unity_loss
				DESC = clan_unity_murder_attempted.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		## For unlanded characters, we don't care as much, but you still lose some.
		else = {
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:owner
				TARGET = scope:target
				VALUE = minor_unity_loss
				DESC = clan_unity_murder_attempted.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		## Tag scope:owner with a separate scope for portraits...
		scope:owner = {
			save_scope_as = owner_to_reveal
			# ... and apply a little dread.
			add_dread = minor_dread_gain
		}
		## Point out that yeah, attempted murder will sour someone's opinion of you.
		attempted_murder_opinion_effect = {
			VICTIM = scope:target
			MURDERER = scope:owner
		}
	}
	# Otherwise, we just add a murder attempt secret.
	else = {
		# Make sure we don't inadvertently reveal the scheme to the target.
		if = {
			limit = { this = scope:owner }
			scope:owner = {
				add_secret = {
					type = secret_murder_attempt
					target = scope:target
				}
			}
		}
	}
	# Lastly, if our imaginary friend put us up to this, then we address that.
	scope:owner = {
		if = {
			limit = {
				any_owned_story = {
					type = story_cycle_imaginary_friend
					var:imaginary_friend_murder_target ?= scope:target
				}
			}
			trigger_event = {
				id = bp2_yearly.2024
				days = 4
			}
		}
	}
}

# If appropriate, murder anyone travelling with scope:target.
murder_entourage_list_effect = {
	# Pick three random entourage members to kill
	scope:target = {
		current_travel_plan = {
			random_entourage_character = {
				limit = {
					this != scope:target
				}
				scope:owner = {
					add_to_variable_list = {
						name = entourage_members_to_kill
						target = prev
					}
				}
			}
			random_entourage_character = {
				limit = {
					NOR = {
						this = scope:target
						this = scope:owner
						scope:owner = {
							is_target_in_variable_list = {
								name = entourage_members_to_kill
								target = prev
							}
						}
					}
				}
				scope:owner = {
					add_to_variable_list = {
						name = entourage_members_to_kill
						target = prev
					}
				}
			}
			random_entourage_character = {
				limit = {
					NOR = {
						this = scope:target
						this = scope:owner
						scope:owner = {
							is_target_in_variable_list = {
								name = entourage_members_to_kill
								target = prev
							}
						}
					}
				}
				scope:owner = {
					add_to_variable_list = {
						name = entourage_members_to_kill
						target = prev
					}
				}
			}
		}
	}
}

# Restart's the current murder scheme, setting all its variables and such back to zero.
restart_murder_scheme_effect = {
	show_as_tooltip = {
		start_scheme = {
			type = murder
			target_character = scope:target
		}
	}
	hidden_effect = {
		scope:scheme = {
			# Track how many times we've restarted, so we can reset progress.
			increment_variable_effect = {
				VAR = scheme_reset_to_zero_value
				VAL = scheme_success_chance
			}
			# Reset our scheme.
			reset_failed_scheme_effect = yes
		}
	}
}

# Process the death result for anyone who dies during the murder interception.
murder_interception_handle_extra_deaths_effect = {
	if = {
		limit = { exists = scope:scheme_discovered }
		known_murder_effect = {
			VICTIM = $VICTIM$
			MURDERER = scope:owner
			EXPOSER = scope:target
		}
	}
	else = {
		unknown_murder_effect = {
			VICTIM = $VICTIM$
			MURDERER = scope:owner
			REASON = $REASON$
		}
	}
}

# Adds either "Plush and Unremarkable Carpet" modifier if character is Iranian, otherwise adds "Plush and Exotic Carpet"
add_carpet_modifier_effect = {
	if = {
		limit = {
			has_fp3_dlc_trigger = yes
			culture = { has_cultural_pillar = heritage_iranian }
		}
		add_character_modifier = {
			modifier = persian_has_plush_carpet_modifier
			days = 3650
		}
	}
	else = {
		add_character_modifier = {
			modifier = has_plush_carpet_modifier
			days = 3650
		}
	}
}

# If trying to lure a child to push off a roof, try to pick something tangible to tempt them with.
## The things I do for script hygiene.
rooftop_murder_lure_for_child_effect = {
	random_list = {
		# Dog.
		25 = {
			trigger = {
				scope:target = { any_owned_story = { type = story_cycle_pet_dog } }
			}
			save_scope_value_as = {
				name = child_pushed_dog
				value = yes
			}
		}
		# Cat.
		## You monster.
		25 = {
			trigger = {
				scope:target = { any_owned_story = { type = story_cycle_pet_cat } }
			}
			save_scope_value_as = {
				name = child_pushed_cat
				value = yes
			}
			random = {
				chance = 60
				save_scope_value_as = {
					name = cat_survives
					value = yes
				}
			}
		}
		# Toy.
		25 = {
			trigger = {
				scope:target = { has_variable = child_toy_variable }
			}
			save_scope_value_as = {
				name = child_pushed_toy
				value = yes
			}
		}
		# Else nothing.
		1 = {}
	}
}

grab_best_agent_murderer_effect = {
	scope:scheme = {
		random_scheme_agent_slot = {
			limit = {
				is_agent_slot_type = agent_assassin
				is_filled = yes
			}
			alternative_limit = { is_filled = yes }
			slot_character = { save_scope_as = assassin }
		}
		# Plus generate a back-up, in case we need it.
		random_dummy_gender_assassin_effect = yes
	}
}

##################################################
# Seduce Scheme Effects

#Milestone should be 1 or 2, outcome should be success or failure
seduce_ongoing_add_scheme_modifier_effect = {
	scope:scheme = {
		add_scheme_modifier = {
			type = seduce_$OUTCOME$_$MILESTONE$_modifier
		}
	}
}

seduce_ongoing_possible_outcomes_tooltip_effect = {
	show_as_tooltip = {
		random_list = {
			1 = {
				desc = seduce_ongoing_possible_outcomes_tooltip_effect.success.desc
				show_chance = no
				seduce_ongoing_add_scheme_modifier_effect = { MILESTONE = $MILESTONE$ OUTCOME = success }
			}
			1 = {
				desc = seduce_ongoing_possible_outcomes_tooltip_effect.failure.desc
				show_chance = no
				seduce_ongoing_add_scheme_modifier_effect = { MILESTONE = $MILESTONE$ OUTCOME = failure }
			}
		}
	}
}

#To add CHARACTER to a list that block seduction schemes from being initiated
## use in the scope of the character that blocks CHARACTER (i.e. the scheme target's scope)
seduction_block_character_effect = {
	if = {
		limit = { root = scope:target }
		custom_tooltip = seduce_outcome.permanent_block

		hidden_effect = {
			add_opinion = {
				target = $CHARACTER$
				modifier = seduce_permanent_blocker_opinion
			}
		}
	}
	else_if = {
		limit = {
			exists = scope:target
			scope:target = {
				is_alive = yes
			}
		}
		add_opinion = {
			target = $CHARACTER$
			modifier = seduce_permanent_blocker_opinion
		}
	}
}

seduction_cooldown_for_character_effect = {
	if = {
		limit = { root = scope:target }
		custom_tooltip = seduce_outcome.cooldown

		hidden_effect = {
			add_opinion = {
				target = $CHARACTER$
				modifier = seduce_regular_cooldown_opinion
			}
		}
	}
	else = {
		add_opinion = {
			target = $CHARACTER$
			modifier = seduce_regular_cooldown_opinion
		}
	}
}

owner_seduce_outcome_success_send_discovery_event_effect = {
	hidden_effect = {
		if = {
			limit = { exists = scope:scheme_discovered }
			trigger_event = {
				id = seduce_outcome.2900
				days = 3
			}
		}
	}
}

owner_seduce_outcome_become_lovers_option_effects = {
	show_as_tooltip = { set_relation_lover = scope:target }
	add_character_flag = { #to assure that this is when the relationship is set
		flag = consummation_and_relationship
		days = 10
	}

	reverse_add_opinion = {
		target = scope:target
		modifier = romance_opinion
		opinion = 20
	}

	if = {
		limit = {
			faith = {
				has_doctrine_parameter = piety_gain_from_successful_intrigue_schemes
			}	
		}
		add_piety = minor_piety_gain
	}

	if = {
		limit = {
			has_government = landless_adventurer_government
			has_perk = mortal_adoration_perk
			scope:target = { is_ruler = yes }
		}
		add_contact = scope:target
		add_hook_if_possible_default_length_effect = {
			TARGET = scope:target 
			TYPE = manipulation_hook
		}
	}

	if = {
		limit = {
			dynasty ?= {
				has_dynasty_perk = fp1_adventure_legacy_2
			}	
		}
		add_prestige = fp1_adventure_legacy_2_prestige_value
	}

	if = {
		limit = {
			is_close_family_of = scope:target
		}
		create_character_memory = {
			type = seduced_family
			
			participants = {
				family_member = scope:target
			}
		}
	}

	owner_seduce_outcome_success_send_discovery_event_effect = yes
}

owner_seduce_outcome_just_sex_effects = {
	reverse_add_opinion = {
		target = scope:target
		modifier = romance_opinion
		opinion = 20
	}

	if = {
		limit = {
			faith = {
				has_doctrine_parameter = piety_gain_from_successful_intrigue_schemes
			}	
		}
		add_piety = minor_piety_gain
	}

	if = {
		limit = {
			dynasty ?= {
				has_dynasty_perk = fp1_adventure_legacy_2
			}	
		}
		add_prestige = fp1_adventure_legacy_2_prestige_value
	}

	owner_seduce_outcome_success_send_discovery_event_effect = yes
}

#In most cases, it makes more sense to actually apply the sex effect in the target's events (which are after the owner's events). This is because A) you don't want any pop-ups for the target before they have recieved their event and B) because some effects won't get a tooltip for being applied if they were already applied before. The only exception is when the owner is a player and the target is an AI.

 target_seduce_outcome_sex_effect = {
	scope:target = {
		if = {
			limit = {
				NAND = {
					scope:owner = { is_ai = no }
					scope:target = { is_ai = yes }
				}
			}
			had_sex_with_effect = {
				CHARACTER = scope:owner
				PREGNANCY_CHANCE = seduce_pregnancy_chance
			}
		}
		else = {
			show_as_tooltip = {
				had_sex_with_effect = {
					CHARACTER = scope:owner
					PREGNANCY_CHANCE = seduce_pregnancy_chance
				}
			}
		}
	}
}

owner_seduce_outcome_sex_effect = {
	scope:owner = {
		if = {
			limit = {
				scope:owner = { is_ai = no }
				scope:target = { is_ai = yes }
			}
			had_sex_with_effect = {
				CHARACTER = scope:target
				PREGNANCY_CHANCE = seduce_pregnancy_chance
			}
		}
		else = {
			show_as_tooltip = {
				had_sex_with_effect = {
					CHARACTER = scope:owner
					PREGNANCY_CHANCE = seduce_pregnancy_chance
				}
			}
		}
	}
}


seduce_outcome_discovered_expose_secrets_and_adultery_effect = {
	extramarital_sex_attempt_exposure_consequences_with_target_effect = { TARGET = $CHARACTER$ SPOUSE_EVENT = yes } #Adds trait
	if = {
		limit = { relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = $CHARACTER$ } }
		random_secret = {
			type = secret_incest
			expose_secret = $EXPOSER$
		}
	}
	if = {
		limit = { relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = $CHARACTER$ } }
		random_secret = {
			type = secret_homosexual
			expose_secret = $EXPOSER$
		}
	}
}

seduce_outcome_failure_discovered_apply_secrets_effect = {
	give_incest_secret_or_nothing_with_target_effect = { CHARACTER = scope:target }
	give_homosexual_secret_or_nothing_with_target_effect = { CHARACTER = scope:target }
}

seduce_outcome_success_discovered_effect = {
	if = {
		limit = {
			any_secret = {
				type = secret_lover
				OR = {
					secret_target = scope:target
					secret_target = scope:owner
				}
			}
		}
		random_secret = { #Revealing the secret will send events for both lovers
			type = secret_lover
			limit = {
				OR = {
					secret_target = scope:target
					secret_target = scope:owner
				}
			}
			expose_secret = scope:target_liege
		}
	}
	else = {
		scope:owner = { seduce_outcome_discovered_expose_secrets_and_adultery_effect = { CHARACTER = scope:target EXPOSER = scope:target_liege } }
		scope:target = { seduce_outcome_discovered_expose_secrets_and_adultery_effect = { CHARACTER = scope:owner EXPOSER = scope:target_liege } }
	}
}

seduce_outcome_publicised_attempted_crimes_or_nothing_effect = {
	$TARGET$ = {
		#Grab everyone relevant who might be interested in the attempt.
		every_close_family_member = { add_to_list = relevant_parties }
		every_consort = {
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		if = {
			limit = {
				liege ?= {
					NOT = { is_in_list = relevant_parties }
				}
			}
			add_to_list = relevant_parties
		}
		if = {
			limit = {
				court_owner ?= {
					NOT = { is_in_list = relevant_parties }
				}
			}
			add_to_list = relevant_parties
		}
		every_vassal = {
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		every_relation = {
			type = friend
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		every_relation = {
			type = lover
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		$OWNER$ = {
			every_close_family_member = {
				limit = {
					NOT = { is_in_list = relevant_parties }
				}
				add_to_list = relevant_parties
			}
		}

		#Adulterer
		if = {
			limit = {
				$OWNER$ = { is_married = yes }
				trait_is_shunned_or_criminal_in_faith_trigger = {
					TRAIT = trait:adulterer
					FAITH = this.faith
					GENDER_CHARACTER = $OWNER$
				}
			}
			every_in_list = {
				list = relevant_parties
				limit = {
					#Filter out anyone who wouldn't care about this.
					NOR = {
						#Kids too young to understand the bias have no prejudice.
						is_adult = no
						#Not compos mentis.
						has_trait = incapable
						#People who are adulterers.
						has_trait = adulterer
						#The person doing the seducing don't think less of themselves either.
						this = $OWNER$
					}
					#And who count the action as adulterous.
					trait_is_shunned_or_criminal_in_faith_trigger = {
						TRAIT = trait:adulterer
						FAITH = faith
						GENDER_CHARACTER = $OWNER$
					}
				}
				custom = characters_close_to_target_who_dislike_adultery
				#Apply attempt opinion effects.
				add_opinion = {
					modifier = adulterer_advances_on_relevant_character
					target = $OWNER$
				}
			}
		}

		#Fornicator
		if = {
			limit = {
				$OWNER$ = { is_married = no }
				trait_is_shunned_or_criminal_in_faith_trigger = {
					TRAIT = trait:fornicator
					FAITH = faith
					GENDER_CHARACTER = $OWNER$
				}
			}
			every_in_list = {
				list = relevant_parties
				limit = {
					#Filter out anyone who wouldn't care about this.
					NOR = {
						#Kids too young to understand the bias have no prejudice.
						is_adult = no
						#Not compos mentis.
						has_trait = incapable
						#People who are fornicators.
						has_trait = fornicator
						#The person doing the seducing don't think less of themselves either.
						this = $OWNER$
					}
					#And who count the action to be fornication.
					trait_is_shunned_or_criminal_in_faith_trigger = {
						TRAIT = trait:fornicator
						FAITH = this.faith
						GENDER_CHARACTER = $OWNER$
					}
				}
				custom = characters_close_to_target_who_dislike_fornication
				#Apply attempt opinion effects.
				add_opinion = {
					modifier = fornicator_advances_on_relevant_character
					target = $OWNER$
				}
			}
		}

		#Incestuous
		if = {
			limit = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = $OWNER$ }
			}
			every_in_list = {
				list = relevant_parties
				limit = {
					#Filter out anyone who wouldn't care about this.
					NOR = {
						#Kids too young to understand the bias have no prejudice.
						is_adult = no
						#Not compos mentis.
						has_trait = incapable
						#People who are incestuous.
						has_trait = incestuous
						#Or who don't count the action as incestuous.
						faith = {
							faith_allows_marriage_consanguinity_trigger = {
								CHARACTER_1 = $OWNER$
								CHARACTER_2 = $TARGET$
							}
						}
						#The person doing the seducing don't think less of themselves either.
						this = $OWNER$
					}
				}
				custom = characters_close_to_target_who_dislike_incest
				#Apply attempt opinion effects.
				add_opinion = {
					modifier = incestuous_advances_on_relevant_character
					target = $OWNER$
				}
			}
		}

		#Sodomite
		if = {
			limit = {
				relation_with_character_is_sodomy_trigger = { CHARACTER = $OWNER$ }
			}
			every_in_list = {
				list = relevant_parties
				limit = {
					#Filter out anyone who wouldn't care about this.
					NOR = {
						#Kids too young to understand the bias have no prejudice.
						is_adult = no
						#Not compos mentis.
						has_trait = incapable
						#People who are sodomites themselves.
						has_trait = sodomite
						#Males who could be sodomites.
						AND = {
							is_male = yes
							OR = {
								has_sexuality = bisexual
								has_sexuality = homosexual
							}
						}
						#Or who don't count the action as incestuous.
						faith = {
							faith_allows_marriage_consanguinity_trigger = {
								CHARACTER_1 = $OWNER$
								CHARACTER_2 = $TARGET$
							}
						}
						#The person doing the seducing don't think less of themselves either.
						this = $OWNER$
					}
					#And, finally, must actually be fussed about sodomy to begin with.
					relation_between_characters_is_sodomy_in_my_faith_trigger = {
						CHARACTER_1 = $OWNER$
						CHARACTER_2 = $TARGET$
					}
				}
				custom = characters_close_to_target_who_dislike_sodomy
				#Apply attempt opinion effects.
				add_opinion = {
					modifier = sodomite_advances_on_relevant_character
					target = $OWNER$
				}
			}
		}
	}
}

set_relation_lover_through_seduction_effect = {
	$CHARACTER$ = { save_scope_as = second_character }
	if = { #To save a potential important object to be used later on
		limit = {
			exists = scope:scheme
			scope:scheme = { has_variable = object_of_importance }
			NOT = { has_variable_list = lover_object_of_importance }
		}
		add_to_variable_list = {
			name = lover_object_of_importance
			target = scope:scheme.var:object_of_importance
		}
		add_to_variable_list = {
			name = lover_object_of_importance
			target = scope:second_character
		}
	}
	else_if = { #you can save two different seduction objects
		limit = {
			exists = scope:scheme
			scope:scheme = { has_variable = object_of_importance }
			has_variable_list = lover_object_of_importance
			NOT = { has_variable_list = lover_object_of_importance_2 }
		}
		add_to_variable_list = {
			name = lover_object_of_importance_2
			target = scope:scheme.var:object_of_importance
		}
		add_to_variable_list = {
			name = lover_object_of_importance_2
			target = scope:second_character
		}
	}
	scope:scheme = {
		end_scheme = yes
	}
	if = { # Safeguard because so much stuff can happen
		limit = {
			NOT = { has_relation_lover = scope:second_character }
		}
		scope:second_character = {
			set_relation_lover = {
				target = prev
				reason = $REASON$
				province = $LOCATION$
			}
		}
	}
}

set_object_of_significance_effect = {
	if = {
		limit = {
			scope:scheme = {
				NOT = { has_variable = object_of_importance }
			}
		}
		scope:scheme = {
			random_list = {
				1 = {
					set_variable = {
						name = object_of_importance
						value = flag:rose
					}
				}
				1 = {
					set_variable = {
						name = object_of_importance
						value = flag:sea_shell
					}
				}
			}
		}
	}
}

set_random_religious_text_effect = {
	random_list = {
		1 = {
			#Christian
			trigger = { OR = { faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion faith.religion = religion:eastern_orthodox_religion } }
			save_scope_value_as = {
				name = religious_book_title
				value = flag:golden_legend
			}
		}
		1 = {
			#Christian
			trigger = { OR = { faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion faith.religion = religion:eastern_orthodox_religion } }
			save_scope_value_as = {
				name = religious_book_title
				value = flag:city_of_god
			}
		}
		1 = {
			#Christian
			trigger = {
				OR = { faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion faith.religion = religion:eastern_orthodox_religion }
				NOT = { faith = faith:orthodox }
			}
			save_scope_value_as = {
				name = religious_book_title
				value = flag:summa_theologica
			}
		}
		1 = {
			#Christian
			trigger = {
				OR = { faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion faith.religion = religion:eastern_orthodox_religion }
				NOT = { faith = faith:orthodox }
			}
			save_scope_value_as = {
				name = religious_book_title
				value = flag:sic_et_non
			}
		}
		1 = {
			#Christian Orthodox
			trigger = {
				faith = faith:orthodox
			}
			save_scope_value_as = {
				name = religious_book_title
				value = flag:chrysostomos
			}
		}
		1 = {
			#Christian Orthodox
			trigger = {
				faith = faith:orthodox
			}
			save_scope_value_as = {
				name = religious_book_title
				value = flag:symeon_menologion
			}
		}
		1 = {
			#Christian Orthodox
			trigger = {
				faith = faith:orthodox
			}
			save_scope_value_as = {
				name = religious_book_title
				value = flag:god_and_christ
			}
		}
		1 = {
			#Muslim
			trigger = { faith.religion = religion:islam_religion }
			save_scope_value_as = {
				name = religious_book_title
				value = flag:the_small_book_on_theism
			}
		}
		1 = {
			#Muslim
			trigger = { faith.religion = religion:islam_religion }
			save_scope_value_as = {
				name = religious_book_title
				value = flag:modern_philosophy
			}
		}
		1 = {
			#Any
			save_scope_value_as = {
				name = religious_book_title
				value = flag:stories_from_holy_book
			}
		}
	}
}

set_random_entertainment_text_effect = {
	random_list = {
		1 = {
			#Germanic language
			trigger = {
				root.culture = {
					OR = {
						has_cultural_parameter = anglic_group_language_param
					}
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:beowulf
			}
		}
		1 = {
			#Germanic language
			trigger = { 
				root.culture = {
					OR = {
						has_cultural_pillar = language_central_germanic
						has_cultural_pillar = language_norse
						has_cultural_pillar = language_anglic
					}
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:niebelungenlied
			}
		}
		1 = {
			#Latin
			trigger = { root.culture = { has_cultural_pillar = language_italian } }
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:song_of_roland
			}
		}
		1 = {
			#Welsh saga
			trigger = {
				OR = {
					root.culture = { has_cultural_pillar = language_brythonic }
					root.culture = { has_cultural_pillar = language_goidelic }
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:mabinogi
			}
		}
		1 = {
			#Greek
			trigger = { root.culture = { has_cultural_pillar = language_greek } }
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:digenes_akrites
			}
		}
		###New Works
		1 = {
			#Any for now
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:hitchhikers
			}
		}
		1 = {
			#Any for now
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:dune
			}
		}
		1 = {
			#Any for now
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:hobbit
			}
		}
		1 = {
			#Any for now
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:lotr
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = anglic_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:narnia
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = anglic_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:foundation
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = anglic_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:nineteen_eighty_four
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { 
						OR = {
							has_cultural_parameter = west_hispanic_group_language_param
							has_cultural_parameter = middle_hispanic_group_language_param
							has_cultural_parameter = east_hispanic_group_language_param
						} 
					}
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:one_hundred_years
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = french_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:les_drames
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = french_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:le_club
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = french_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:les_chevaliers
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { 
						OR = {
							has_cultural_parameter = anglic_group_language_param
							has_cultural_parameter = middle_german_group_language_param
						} 
					}
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:the_shell_seekers
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { 
						OR = {
							has_cultural_parameter = anglic_group_language_param
							has_cultural_parameter = middle_german_group_language_param
						} 
					}
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:pillars
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = middle_german_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:perfume
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { 
						OR = {
							has_cultural_parameter = east_north_germanic_group_language_param
							has_cultural_parameter = west_north_germanic_group_language_param
						} 
					}
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:faceless
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = lausatian_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:the_alchemist
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = east_slavic_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:the_brothers
			}
		}
		1 = {
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:one_thousand
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = anglic_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:nineteen_eighty_four
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = latin_sprachbund_language_param } 
					root.religion = religion:novelist_religion 
					root.religion = religion:catholic_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:the_divine_comedy
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { 
						OR = {
							has_cultural_parameter = latin_sprachbund_language_param
							has_cultural_parameter = greek_sprachbund_language_param
						} 
					}
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:the_odyssey
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { 
						OR = {
							has_cultural_parameter = latin_sprachbund_language_param
							has_cultural_parameter = greek_sprachbund_language_param
						} 
					}
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:war_and_peace
			}
		}
		1 = {
			trigger = { 
				OR = { 
					root.culture = { has_cultural_parameter = albanian_group_language_param } 
					root.religion = religion:novelist_religion 
				}
			}
			save_scope_value_as = {
				name = entertainment_book_title
				value = flag:the_pyramid
			}
		}
	}
}

set_random_informative_text_effect = {
	random_list = {
		1 = {
			#Arabic
			trigger = {
				OR = {
					root.culture = { has_cultural_pillar = heritage_arabic }
					root.culture = { has_cultural_pillar = language_arabic }
				}
			}
			save_scope_value_as = {
				name = informative_book_title
				value = flag:on_the_judgement_of_the_stars
			}
		}
		1 = {
			#Arabic
			trigger = {
				OR = {
					scope:culture ?= { has_cultural_pillar = heritage_arabic }
					scope:culture ?= { has_cultural_pillar = language_arabic }
				}
			}
			save_scope_value_as = {
				name = informative_book_title
				value = flag:the_perfect_state
			}
		}
		1 = {
			#"Any"
			save_scope_value_as = {
				name = informative_book_title
				value = flag:spiritual_medicine
			}
		}
		1 = {
			#Latin
			trigger = {
				root.capital_province ?= { geographical_region = world_europe }
			}
			save_scope_value_as = {
				name = informative_book_title
				value = flag:trotula
			}
		}
		1 = {
			#Jewish/Any
			save_scope_value_as = {
				name = informative_book_title
				value = flag:the_improvement_of_the_moral_qualities
			}
		}
		1 = {
			#Welsh (Anyone in the British Isles)
			trigger = {
				root.capital_province ?= { geographical_region = world_europe_west_britannia }
			}
			save_scope_value_as = {
				name = informative_book_title
				value = flag:armes_prydein
			}
		}
		1 = {
			#Anywhere around the Mediterrenean
			trigger = {
				root.capital_province ?= {
					OR = {
						geographical_region = world_europe
						geographical_region = world_africa_north_east
						geographical_region = world_africa_north_west
					}
				}
			}
			save_scope_value_as = {
				name = informative_book_title
				value = flag:almagest
			}
		}
		1 = {
			#Greek
			trigger = { root.culture = { has_cultural_pillar = language_greek } }
			save_scope_value_as = {
				name = informative_book_title
				value = flag:anekdota
			}
		}
		1 = {
			#Greek
			trigger = { root.culture = { has_cultural_pillar = language_greek } }
			save_scope_value_as = {
				name = informative_book_title
				value = flag:chronographia
			}
		}
	}
}

#To set up a location to use for the sex scene custom loc key
set_random_sex_scene_location_effect = {
	hidden_effect = {
		if = {
			limit = { NOT = { has_variable = sex_scene_location } }
			random_list = {
				20 = {
					set_variable = {
						name = sex_scene_location
						value = flag:garden
					}
				}
				20 = {
					set_variable = {
						name = sex_scene_location
						value = flag:private_chamber
					}
				}
				20 = {
					set_variable = {
						name = sex_scene_location
						value = flag:stable
					}
				}
				20 = {
					set_variable = {
						name = sex_scene_location
						value = flag:copse
					}
				}
				20 = {
					set_variable = {
						name = sex_scene_location
						value = flag:kitchen
					}
				}
			}
		}
	}
}

#To transfer the location used in the sex scene custom loc key from one character to another
transfer_sex_scene_location_to_character_effect = {
	if = {
		limit = {
			has_variable = sex_scene_location
		}
		if = {
			limit = {
				var:sex_scene_location = flag:garden
			}
			$CHARACTER$ = {
				set_variable = {
					name = sex_scene_location
					value = flag:garden
				}
			}
		}
		else_if = {
			limit = {
				var:sex_scene_location = flag:private_chamber
			}
			$CHARACTER$ = {
				set_variable = {
					name = sex_scene_location
					value = flag:private_chamber
				}
			}
		}
		else_if = {
			limit = {
				var:sex_scene_location = flag:stable
			}
			$CHARACTER$ = {
				set_variable = {
					name = sex_scene_location
					value = flag:stable
				}
			}
		}
		else_if = {
			limit = {
				var:sex_scene_location = flag:copse
			}
			$CHARACTER$ = {
				set_variable = {
					name = sex_scene_location
					value = flag:copse
				}
			}
		}
		else_if = {
			limit = {
				var:sex_scene_location = flag:kitchen
			}
			$CHARACTER$ = {
				set_variable = {
					name = sex_scene_location
					value = flag:kitchen
				}
			}
		}
	}
}

##################################################
# Abduct Scheme Effects

#Sets up the Outcome Roll values
abduct_outcome_roll_setup_effect = {
	#Discovery Roll setup
	save_scope_value_as = {
		name = discovery_chance
		value = {
			value = 100
			subtract = scope:scheme.scheme_secrecy
		}
	}
}

#Roll to check whether a Abduct Scheme is a success or a failure, and whether the owner is discovered
abduct_outcome_roll_effect = {
	#SUCCESS ROLL
	random = {
		chance = scope:scheme.scheme_success_chance
		custom_tooltip = abduct_successful_roll_tt
		scope:owner = { mandala_trickster_increment_successful_schemes_effect = yes }
		save_scope_value_as = {
			name = scheme_successful
			value = yes
		}
	}
	### End Success roll
	#DISCOVERY ROLL
	custom_label = abduct_success_discovery_tt
	random = {
		chance = scope:discovery_chance
		custom_tooltip = abduct_become_discovered_roll_tt
		save_scope_value_as = {
			name = scheme_discovered
			value = yes
		}
	}
	### End Discovery roll

	hidden_effect = {
		#FIRE CORRECT ON ACTIONS
		if = {
			limit = {
				exists = scope:scheme_successful
			}
			trigger_event = {
				on_action = abduct_succeeded
			}
		}
		else = {
			trigger_event = {
				on_action = abduct_failed
			}
		}
	}
}

#Used in the immediate of the Scheme Owner's success event
abduct_success_effect = {
	
	scope:target = {
		add_character_flag = {
			flag = was_abducted_block_notification_event
			days = 2
		}
		trigger_event = abduct_outcome.5001
	}

	hard_imprison_character_effect = {
		TARGET = scope:target
		IMPRISONER = scope:owner
	}
	
	if = {
		limit = {
			exists = scope:owner.house
			exists = scope:target.house
		}
		scope:owner.house = {
			change_house_relation_effect = {
				HOUSE = scope:target.house
				VALUE = house_relation_damage_medium_value
				REASON = abduction
				CHAR = scope:owner
				TARGET_CHAR = scope:target
				TITLE = scope:dummy_gender
			}
		}
	}
}

abduct_failure_effect = {
	#Add Watchful Modifier to the target
	scope:target = {
		show_as_tooltip = {
			add_character_modifier = {
				modifier = watchful_modifier
				days = watchful_modifier_duration
			}
		}
	}

	scope:target = {
		trigger_event = abduct_outcome.5002
	}
}

successful_abduct_outcome_event_option_effect = {
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = piety_gain_from_successful_intrigue_schemes
			}	
		}
		add_piety = minor_piety_gain
	}

	scope:scheme ?= {
		end_scheme = yes
	}
}

##################################################
# Befriend Scheme Effects

successful_befriend_potential_friend_effect = {
	$CHARACTER$ = {
		if = { #Always leads to a potential friendship
			limit = {
				NOR = {
					has_relation_potential_friend = root
					has_relation_friend = root
				}
			}
			if = { #Remove potential rival relation if you have it
				limit = {
					has_relation_potential_rival = root
				}
				remove_relation_potential_rival = root
			}
			set_relation_potential_friend = root
		}
		if = {
			limit = {
				number_of_traits_in_common = {
					target = root
					value >= 3
				}
			}
			$CHARACTER$ = {
				add_opinion = {
					modifier = friendliness_opinion
					target = root
					opinion = 30
				}
			}
		}
		else = {
			$CHARACTER$ = {
				add_opinion = {
					modifier = friendliness_opinion
					target = root
					opinion = 20
				}
			}
		}
	}
}

successful_befriend_critical_change_effect = {
	$CHARACTER$ = {
		hidden_effect = {
			if = { #Remove potential rival relation if you have it
				limit = {
					has_relation_potential_rival = root
				}
				remove_relation_potential_rival = root
			}
		}
		if = { #Set friend relation
			limit = {
				NOT = { has_relation_friend = root  }
			}
			if = {
				limit = {
					exists = scope:relationship_reason_location
				}
				set_relation_friend = { reason = $REASON$ target = root province = scope:relationship_reason_location }
			}
			else = {
				set_relation_friend = { reason = $REASON$ target = root }
			}
		}
		else_if = { #Fallback
			limit = {
				has_relation_friend = root
			}
			$CHARACTER$ = {
				add_opinion = {
					modifier = friendliness_opinion
					target = root
					opinion = 40
				}
			}
		}
	}
	if = {
		limit = {
			has_government = landless_adventurer_government
			has_perk = friendly_counsel_perk
			$CHARACTER$ = { is_ruler = yes }
		}
		add_contact = $CHARACTER$
	}
}

failed_befriend_opinion_change_effect = {
	$CHARACTER$ = {
		add_opinion = {
			modifier = refusal_opinion
			target = root
			opinion = -5
		}
		hidden_effect = {
			set_relation_potential_friend = root
		}
	}
}

failed_befriend_opinion_critical_change_effect = {
	$CHARACTER$ = {
		add_opinion = {
			modifier = disastrous_befriend_attempt_opinion
			target = root
		}
		if = {
			limit = {
				NOR = {
					has_relation_potential_rival = root
					has_relation_rival = root
				}
			}
			hidden_effect = { set_relation_potential_rival = root }
		}
		else_if = { #If you already are potential rivals, you have a chance of becoming Rivals
			limit = {
				has_relation_potential_rival = root
				NOT = {  has_relation_rival = root }
			}
			hidden_effect = { remove_relation_potential_rival = root }
			set_relation_rival = {
				target = root
				reason = rival_disastrous_befriend_attempt
			}
		}
	}
}

##################################################
# Claim Throne Scheme Effects

#Sets up the Outcome Roll values
claim_throne_outcome_roll_setup_effect = {
	# Find appropriate title
	scope:target = {
		primary_title = {
			save_scope_as = target_title
		}
	}
	# Discovery Roll setup
	save_scope_value_as = {
		name = discovery_chance
		value = {
			value = 100
			subtract = scope:scheme.scheme_secrecy
		}
	}
}

claim_throne_check_target_title_effect = {
	# In case something has happened to the target_title, we try to reset it here:
	if = {
		limit = {
			OR = {
				NOT = { exists = scope:target_title } # The title could somehow disappear
				NOT = {
					scope:target_title = { # The title might feasibly pass to someone else
						holder ?= scope:target

					}
				}
			}
		}
		scope:target = {
			primary_title = { # We just assign the target's primary title as the new target title
				save_scope_as = target_title
			}
		}
	}

	# Rivalry check is done here, since it's run in every outcome
	if = {
		limit = {
			OR = {
				exists = scope:scheme_successful
				exists = scope:scheme_discovered
			}
			NOT = { has_relation_rival = scope:target }
		}
		hidden_effect = {
			random = {
				chance = 30
				modifier = {
					add = 30
					has_relation_potential_rival = scope:target
				}
				modifier = {
					exists = scope:scheme_discovered
					add = 30
				}
				modifier = {
					has_relation_friend = scope:target
					add = -25
				}

				save_scope_value_as = {
					name = set_rivalry
					value = yes
				}
			}
		}
	}
}

#Roll to check whether a Claim Throne Scheme is a success or a failure, and whether the owner is discovered
claim_throne_outcome_roll_effect = {
	#SUCCESS ROLL
	random = {
		chance = scope:scheme.scheme_success_chance
		custom_tooltip = claim_throne_successful_roll_tt
		scope:owner = { mandala_trickster_increment_successful_schemes_effect = yes }
		save_scope_value_as = {
			name = scheme_successful
			value = yes
		}
	}
	### End Success roll
	#DISCOVERY ROLL
	custom_description_no_bullet = {
		text = claim_throne_success_discovery_warning_effect
	}
	random = {
		chance = scope:discovery_chance
		custom_tooltip = claim_throne_become_discovered_roll_tt
		save_scope_value_as = {
			name = scheme_discovered
			value = yes
		}
	}
	### End Discovery roll

	hidden_effect = {
		#FIRE CORRECT ON ACTIONS
		if = {
			limit = {
				exists = scope:scheme_successful
			}
			trigger_event = {
				on_action = claim_throne_succeeded
				days = 3
			}
		}
		else = {
			trigger_event = {
				on_action = claim_throne_failed
				days = 3
			}
		}
	}
}

#Used in the immediate of the Scheme Owner's success event
claim_throne_success_effect = {
	# Note that the Claim itself is added in successful_claim_throne_outcome_event_option_effect

	if = {
		limit = {
			exists = scope:scheme_discovered
		}
		# Trigger the response event for the target (actual opinion is set here)
		scope:target = {
			trigger_event = claim_throne_outcome.5001
		}
		
		show_as_tooltip = { # Target dislikes you
			scope:target = {
				add_opinion = {
					target = scope:owner
					modifier = claim_my_throne_success_discovered_opinion
				}
			}
		}
	}
	else = {
		# Trigger the response event for the target (actual opinion is set here)
		scope:target = {
			trigger_event = claim_throne_outcome.5002
		}
		show_as_tooltip = {
			scope:target = {
				add_opinion = {
					target = scope:owner
					modifier = claim_my_throne_success_undiscovered_opinion
					years = 10
				}
			}
		}
	}
}

claim_throne_failure_effect = {
	add_prestige = claim_throne_discovered_failure_prestige_loss
	scope:target = {
		# Fire notification event for target
		trigger_event = claim_throne_outcome.5003
		show_as_tooltip = {
			add_opinion = {
				target = scope:owner
				modifier = claim_my_throne_failure_opinion
				years = 10
			}
			if = {
				limit = { exists = scope:set_rivalry }
				set_relation_rival = {
					target = scope:owner
					reason = rival_claimed_throne_failed
				}
			}
		}
	}
}

successful_claim_throne_event_option_effect = {
	if = {
		limit = {
			exists = scope:scheme_discovered
		}
		add_prestige = claim_throne_discovered_prestige_loss
	}
	show_as_tooltip = {
		scope:target = {
			if = {
				limit = { exists = scope:set_rivalry }
				set_relation_rival = {
					target = scope:owner
					reason = rival_claimed_throne
				}
			}
			if = {
				limit = { exists = scope:scheme_discovered }
				add_opinion = {
					target = scope:owner
					modifier = claim_my_throne_success_discovered_opinion
				}
			}
			else = {
				add_opinion = {
					target = scope:owner
					modifier = claim_my_throne_success_undiscovered_opinion
					years = 10
				}
			}
		}
	}

	scope:scheme = {
		end_scheme = yes
	}

	add_pressed_claim = scope:target_title
}

claim_throne_decline_execution_effect = {
	custom_tooltip = do_not_execute_claim_throne_tooltip
	scope:scheme = { 
		reset_failed_scheme_effect = yes
	}
}

claim_throne_set_mythical_founder_variable_effect = {
	if = {
		limit = {
			AND = { # Charles Martell
				OR = {
					scope:target_title = title:k_france
					scope:target_title = title:e_france
				}
				current_date > 1000.1.1
			}
		}
		set_variable = {
			name = mythical_founder
			value = flag:charles_martell
		}
	}
#	else_if = { # Alexander
#		limit = {
#			OR = {			
#				scope:target_title = title:k_thessalonika
#				scope:target_title = title:k_hellas
#				scope:target_title = title:k_egypt
#				AND = {
#					OR = {
#						scope:target_title = title:k_persia
#						scope:target_title = title:e_persia
#					}
#					NOR = {
#						root.faith.religion = religion:islam_religion
#						root.faith.religion = religion:zoroastrianism_religion
#					}
#				}
#				scope:target_title = title:k_anatolia
#			}
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:alexander
#		}
#	}
#	else_if = { # Lech
#		limit = {
#			scope:target_title = title:k_poland # Lech
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:lech
#		}
#	}
#	else_if = { # Czech
#		limit = {
#			scope:target_title = title:k_bohemia # Lech
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:czech
#		}
#	}
#	else_if = { # Rus
#		limit = {
#			OR = { # Rus
#				scope:target_title = title:k_white_rus
#				scope:target_title = title:k_ruthenia
#				scope:target_title = title:e_russia
#			}
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:rus
#		}
#	}
#	else_if = { # Arthur
#		limit = {
#			OR = {
#				scope:target_title = title:k_wales
#				scope:target_title = title:k_cornwall
#				scope:target_title = title:k_england
#				scope:target_title = title:e_britannia
#			}
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:arthur
#		}
#	}
#	else_if = { # Belisarius
#		limit = {
#			OR = {
#				scope:target_title = title:k_italy
#				scope:target_title = title:k_romagna
#				scope:target_title = title:k_sardinia
#				scope:target_title = title:e_italy
#				scope:target_title = title:h_roman_empire
#				scope:target_title = title:h_eastern_roman_empire
#			}
#			faith = faith:orthodox
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:belisarius
#		}
#	}
#	else_if = { # Romulus
#		limit = {
#			OR = {
#				scope:target_title = title:k_italy
#				scope:target_title = title:k_romagna
#				scope:target_title = title:k_sardinia
#				scope:target_title = title:e_italy
#				scope:target_title = title:h_roman_empire
#				scope:target_title = title:h_eastern_roman_empire
#			}
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:romulus
#		}
#	}
#	else_if = { # Ardashir
#		limit = {
#			OR = {
#				scope:target_title = title:k_persia
#				scope:target_title = title:e_persia
#			}
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:ardashir
#		}
#	}
#	else_if = { # The Pharaohs
#		limit = {
#			scope:target_title = title:k_egypt
#			NOT = { religion = religion:islam_religion }
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:pharaohs
#		}
#	}
#	else_if = { # The Visigothic Kings
#		limit = {
#			OR = {
#				scope:target_title = title:k_castille
#				scope:target_title = title:k_aragon
#				scope:target_title = title:k_navarra
#				scope:target_title = title:k_andalusia
#				scope:target_title = title:k_portugal
#				scope:target_title = title:e_spain
#			}
#			NOT = { religion = religion:islam_religion }
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:visigothic_kings
#		}
#	}
#	else_if = { # Abd al-Rahman
#		limit = {
#			OR = {
#				scope:target_title = title:k_castille
#				scope:target_title = title:k_aragon
#				scope:target_title = title:k_navarra
#				scope:target_title = title:k_andalusia
#				scope:target_title = title:k_portugal
#				scope:target_title = title:e_spain
#			}
#			religion = religion:islam_religion
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:abd_al_rahman
#		}
#	}
#	else_if = { # Zenobia
#		limit = {
#			OR = {
#				scope:target_title = title:k_syria
#				scope:target_title = title:k_mesopotamia
#			}
#			NOT = { religion = religion:islam_religion }
#		}
#		set_variable = {
#			name = mythical_founder
#			value = flag:zenobia
#		}
#	}
	else = {
		set_variable = {
			name = mythical_founder
			value = flag:fallback
		}
	}
}

##################################################
# Elope Scheme Effects

elope_opinion_list_builder_effect = {
	$OWNER$ = {
		every_spouse = {
			limit = { NOT = { this = $TARGET$ } }
			add_to_temporary_list = $LIST_NAME$
		}
	}
	$TARGET$ = {
		every_spouse = {
			limit = { NOT = { this = $OWNER$ } }
			add_to_temporary_list = $LIST_NAME$
		}
		liege = {
			if = {
				limit = {
					NOR = {
						is_in_list = $LIST_NAME$
						this = $OWNER$
					}
				}
				add_to_temporary_list = $LIST_NAME$
			}
		}
	}
}

elope_success_effect = {
	elope_opinion_list_builder_effect = { OWNER = $OWNER$ TARGET = $TARGET$ LIST_NAME = elope_opinion_list }

	#Because this can be used in events or interaction window, we save root_scope here
	if = {
		limit = { exists = scope:actor }
		scope:actor = { save_temporary_scope_as = root_scope }
	}
	else = {
		root = { save_temporary_scope_as = root_scope }
	}

	#Target prisoner release
	$TARGET$ = {
		if = {
			limit = { is_imprisoned = yes }
			release_from_prison = yes
		}
	}

	$OWNER$ = {
		#Tooltip for marriage
		show_as_tooltip = {
			if = {
				limit = { is_female = yes }
				marry_matrilineal = $TARGET$
			}
			else = {
				marry = $TARGET$
			}
		}

		#Owner's personal consequences (hidden or not), divorce happens here
		if = {
			limit = {
				scope:root_scope = $OWNER$
			}	
			elope_success_personal_consequences_effect = { CHARACTER = $OWNER$ }
		}
		else = {
			hidden_effect = { elope_success_personal_consequences_effect = { CHARACTER = $OWNER$ } }
		}
	}

	#Opinions
	ordered_in_list = {
		list = elope_opinion_list
		max = 10 #To make sure we include all
		check_range_bounds = no
		order_by = ai_vengefulness

		#Towards owner
		if = {
			limit = {
				OR = { #Owner wants to see everything, root wants to see their own
					scope:root_scope = $OWNER$
					scope:root_scope = this
				}
			}
			elope_success_opinion_rivalry_effect = { CHARACTER = $OWNER$ }
		}
		else = {
			hidden_effect = { elope_success_opinion_rivalry_effect = { CHARACTER = $OWNER$ } }
		}

		#Towards target
		if = {
			limit = { scope:root_scope = this } #Root wants to see their own
			elope_success_opinion_rivalry_effect = { CHARACTER = $TARGET$ }
		}
		else = {
			hidden_effect = { elope_success_opinion_rivalry_effect = { CHARACTER = $TARGET$ } }
		}
	}


	hidden_effect = {
		#Target's personal consequences, divorce happens here
		elope_success_personal_consequences_effect = { CHARACTER = $TARGET$ }

		#Marriage
		$OWNER$ = { #We do this last so old spouses remain when we run personal consequences effect
			if = {
				limit = { is_female = yes }
				marry_matrilineal = $TARGET$
			}
			else = {
				marry = $TARGET$
			}
		}
	}
}

elope_failure_discovered_effect = {
	elope_opinion_list_builder_effect = { OWNER = $OWNER$ TARGET = $TARGET$ LIST_NAME = elope_opinion_list }

	#Expose lover secret
	$OWNER$ = {
		random_secret = {
			type = secret_lover
			limit = {
				secret_target = $TARGET$
			}
			
			if = {
				limit = { $DISCOVERER$ = { is_ai = yes } }
				expose_secret = $DISCOVERER$
			}
			else = {
				reveal_to = $DISCOVERER$
			}
		}
	}

	#Opinions
	ordered_in_list = {
		list = elope_opinion_list
		max = 10 #To make sure we include all
		check_range_bounds = no
		order_by = ai_vengefulness

		#Towards owner
		if = {
			limit = {
				OR = { #Owner wants to see everything, root wants to see their own
					root = $OWNER$
					root = this
				}
			}
			elope_failure_discovered_opinion_rivalry_effect = { CHARACTER = $OWNER$ }
		}
		else = {
			hidden_effect = { elope_failure_discovered_opinion_rivalry_effect = { CHARACTER = $OWNER$ } }
		}

		#Towards target
		if = {
			limit = { root = this } #Root wants to see their own
			elope_failure_discovered_opinion_rivalry_effect = { CHARACTER = $TARGET$ }
		}
		else = {
			hidden_effect = { elope_failure_discovered_opinion_rivalry_effect = { CHARACTER = $TARGET$ } }
		}
	}
}

elope_success_opinion_rivalry_effect = {
	#Crime opinion
	add_opinion = {
		target = $CHARACTER$
		modifier = elopement_opinion
	}

	#Rivalry
	if = {
		limit = {
			can_set_relation_rival_trigger = { CHARACTER = $CHARACTER$ }
			is_ai = yes
			trigger_if = {
				limit = { is_spouse_of = $CHARACTER$ }
				ai_vengefulness >= low_positive_ai_value
			}
			trigger_else = {
				ai_vengefulness > 0
			}
		}
		if = {
			limit = {
				can_set_relation_nemesis_trigger = { CHARACTER = $CHARACTER$ }
				ai_vengefulness >= medium_positive_ai_value
			}
			set_relation_nemesis = {
				reason = nemesis_elopement
				copy_reason = rival
				target = $CHARACTER$
			}
		}
		else = {
			set_relation_rival = {
				target = $CHARACTER$
				reason = rival_eloped
			}
		}
	}
	else_if = {
		limit = {
			can_set_relation_potential_rival_trigger = { CHARACTER = $CHARACTER$ }
		}
		hidden_effect = { set_relation_potential_rival = $CHARACTER$ }
	}
}

elope_success_personal_consequences_effect = {
	$CHARACTER$ = {

		#Divorce
		if = {
			limit = {
				is_married = yes
			}
			every_spouse = {
				save_temporary_scope_as = eloper_divorcee

				divorce_effect = {
					DIVORCER = $CHARACTER$
					DIVORCEE = scope:eloper_divorcee
				}
				if = {
					limit = { has_relation_lover = $CHARACTER$ }
					remove_relation_lover = $CHARACTER$
				}
			}

			#Divorce consequences
			if = {
				limit = { faith = { NOT = { has_doctrine = doctrine_divorce_allowed } } }
				add_prestige_level = -1
				add_piety_level = -1

				if = {
					limit = {
						faith = { has_doctrine = tenet_communion }
						NOT = { has_trait = excommunicated }
					}
					add_trait = excommunicated
				}
			}
		}

		#Break betrothal
		if = {
			limit = { is_betrothed = yes }
			reverse_add_opinion = {
				modifier = broke_betrothal_opinion
				target = betrothed
			}
			break_betrothal = betrothed
			if = {
				limit = {
					has_been_promised_grand_wedding = yes
				}
				break_grand_wedding_betrothal_effect = yes
			}
		}

		#End concubinage
		if = {
			limit = { is_concubine = yes }
			liege = {
				remove_concubine = $CHARACTER$

				if = {
					limit = { has_relation_lover = $CHARACTER$ }
					remove_relation_lover = $CHARACTER$
				}
			}
			add_prestige_level = -1
		}
	}
}

elope_failure_discovered_opinion_rivalry_effect = {
	add_opinion = {
		target = $CHARACTER$
		modifier = attempted_elopement_opinion
	}

	#Rivalry
	if = {
		limit = {
			can_set_relation_potential_rival_trigger = { CHARACTER = $CHARACTER$ }
		}
		hidden_effect = { set_relation_potential_rival = $CHARACTER$ }
	}
}

##################################################
# Fabricate Hook Scheme Effects

fabricate_hook_assign_appropriate_type_effect = {
	debug_log = "Running Fabricate Hook's Assign Appropriate Hook effect"
	assert_if = {
		limit = {
			scope:owner = {
				has_strong_hook = scope:target
			}
		}
		text = "The Fabricate Hook Scheme Owner already has a Strong Hook on the Target! Why is this effect running?"
	}
	assert_if = {
		limit = {
			scope:target = { is_ruler = yes }
			NOT = { exists = scope:strong_hook_against_ruler }
			scope:owner = { has_hook = scope:target }
		}
		text = "The Owner has a hook against a ruler target, and the strong hook roll failed. Something has gone wrong to get here!"
	}

	save_scope_value_as = {
		name = hook_type
		value = flag:$TYPE$
	}
	# Go through the Hook types, and assign the appropriate one
	if = {
		limit = {
			scope:hook_type = flag:loyalty_hook
		}
		# Check rulers first (to give weaker Hooks)
		if = {
			limit = {
				scope:target = { is_ruler = yes }
				NOT = { exists = scope:strong_hook_against_ruler } # Set by on_ready in the Scheme
			}
			send_interface_toast = {
				title = fabricate_hook_gained_indebted_title
				left_icon = scope:target
				add_hook = {
					type = indebted_hook
					target = scope:target
				}
			}
		}
		else = {
			send_interface_toast = {
				title = fabricate_hook_gained_loyalty_title
				left_icon = scope:target
				add_hook = {
					type = loyalty_hook
					target = scope:target
				}
			}
		}
	}
	else_if = {
		limit = {
			scope:hook_type = flag:fabrication_hook
		}
		# Check rulers first (to give weaker Hooks)
		if = {
			limit = {
				scope:target = { is_ruler = yes }
				NOT = { exists = scope:strong_hook_against_ruler } # Set by on_ready in the Scheme
			}
			send_interface_toast = {
				title = fabricate_hook_gained_manipulation_title
				left_icon = scope:target
				add_hook = {
					type = manipulation_hook
					target = scope:target
				}
			}
		}
		else = {
			send_interface_toast = {
				title = fabricate_hook_gained_indebted_title
				left_icon = scope:target
				add_hook = {
					type = fabrication_hook
					target = scope:target
				}
			}
		}
	}
	else_if = {
		limit = {
			scope:hook_type = flag:life_threat_hook
		}
		debug_log = "Attempting to set life threat hook"
		# Check rulers first (to give weaker Hooks)
		if = {
			limit = {
				scope:target = { is_ruler = yes }
				NOT = { exists = scope:strong_hook_against_ruler } # Set by on_ready in the Scheme
			}
			debug_log = "Trying to set regular threat hook against ruler"
			send_interface_toast = {
				title = fabricate_hook_gained_threat_title
				left_icon = scope:target
				add_hook = {
					type = threat_hook
					target = scope:target
				}
				scope:target = {
					add_opinion = {
						target = scope:owner
						modifier = fabricate_hook_threatened_me
						years = 10
					}
				}
			}
		}
		else = {
			if = {
				limit = { exists = scope:strong_hook_against_ruler }
				debug_log = "Trying to set life_threat_hook against a ruler"
			}
			else = {
				debug_log = "Setting life_threat_hook against non-ruler"
				assert_if = {
					limit = { scope:target = { is_ruler = yes } }
					text = "There is no ruler strong hook roll, but we're still trying to set a life_threat_hook on them!"
				}
			}
			send_interface_toast = {
				title = fabricate_hook_gained_threat_title
				left_icon = scope:target
				add_hook = {
					type = life_threat_hook
					target = scope:target
				}
				scope:target = {
					add_opinion = {
						target = scope:owner
						modifier = fabricate_hook_threatened_me
						years = 10
					}
				}
			}
		}
	}
	# Error catch
	else = {
		assert_if = {
			limit = { always = yes } # It should never get here
			text = "Fabricate Hook assignment effect did not have a Hook type set when trying to assign a Hook!"
		}
	}
}

fabricate_hook_block_scheme_owner_from_further_schemes_effect = {
	add_opinion = {
		target = scope:owner
		modifier = fabricated_hook_against_court_opinion
		years = 5
	}
	custom_tooltip = fabricate_hook_i_may_not_fabricate_again
}

fabricate_hook_discovery_effect = {
	show_as_tooltip = { # Target dislikes you
		custom_tooltip = fabricate_hook_i_may_not_fabricate_again
		scope:target = {
			add_opinion = {
				target = scope:owner
				modifier = fabricated_hook_against_court_opinion
				years = 5
			}
		}
		if = {
			limit = {
				exists = scope:target.court_owner
				scope:target != scope:target.court_owner
			}
			scope:target.court_owner = {
				add_opinion = {
					target = scope:owner
					modifier = fabricated_hook_against_court_opinion
					years = 5
				}
			}
		}
	}

	hidden_effect  = {
		# Set a blocker for Fabricating further Hooks against Court in question
		if = {
			limit = {
				exists = scope:target.court_owner
			}
			scope:target.court_owner = {
				send_interface_message = {
					type = fabricate_hook_bad_message
					left_icon = scope:owner
					title = hostile_scheme_discovery.3002.t

					if = {
						limit = {
							scope:owner != scope:target.court_owner
						}
						fabricate_hook_block_scheme_owner_from_further_schemes_effect = yes
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = scope:target.court_owner }
					scope:target.court_owner != scope:target
				}
			}
			scope:target = {
				add_opinion = {
					target = scope:owner
					modifier = fabricated_hook_against_court_opinion
					years = 5
				}
			}
		}
	}
}

#Used in event options
fabricate_hook_success_effect = {
	fabricate_hook_assign_appropriate_type_effect = {
        TYPE = $TYPE$ # Sets the correct hook type to give
    }
    if = {
        limit = { exists = scope:scheme_discovered }
        fabricate_hook_discovery_effect = yes
    }
    if = {
        limit = { exists = scope:scheme }
        scope:scheme = {
            end_scheme = yes
        }
    }
}

fabricate_hook_decline_execution_effect = {
	scope:scheme = {
		add_scheme_modifier = {
			type = fabricate_hook_building_influence_modifier
		}
		custom_tooltip = restart_scheme_tt
		reset_failed_scheme_effect = yes
	}
}

fabricate_hook_success_notification_event_effect = {
	custom_tooltip = fabricate_hook_hook_gained_on_you
	if = {
		limit = {
			exists = scope:scheme_discovered
			scope:target = scope:target.court_owner
		}
		fabricate_hook_block_scheme_owner_from_further_schemes_effect = yes
	}
}

##################################################
# Sway Scheme Effects

sway_end_effect = {
	if = {
		limit = {
			scope:target = {
				NOT = {
					has_opinion_modifier = {
						target = scope:owner
						modifier = scheme_sway_opinion
						value >= sway_max_value # 100 by default
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:scheme
			}
			scope:scheme = {
				reset_failed_scheme_effect = yes
			}
		}
		if = {
			limit = {
				exists = scope:scheme_successful
			}
			custom_tooltip = sway_continue
		}
		else = {
			custom_tooltip = sway_try_again
		}
		
		scope:owner = { # The AI never stops swaying unless we force it to, this makes them use a more even spread of schemes
			if = {
				limit = {
					is_ai = yes
					scope:target = {
						NAND = {
							is_vassal_of = scope:owner
							is_a_faction_member = yes
							opinion = {
								target = scope:owner
								value < 100
							}
						}
					}
				}
				if = { # Sway your realm priest for a long time
					limit = {
						scope:target = {
							is_theocratic_lessee = yes
							opinion = {
								target = scope:owner
								value <= 50
							}
						}
					}
					random = {
						chance = 10
						scope:scheme = {
							end_scheme = yes
						}
					}
				}
				else_if = {
					limit = {
						scope:target = {
							opinion = {
								target = scope:owner
								value < -25
							}
						}
					}
					random = {
						chance = 10
						scope:scheme = {
							end_scheme = yes
						}
					}
				}
				else_if = {
					limit = {
						scope:target = {
							opinion = {
								target = scope:owner
								value < 0
							}
						}
					}
					random = {
						chance = 30
						scope:scheme = {
							end_scheme = yes
						}
					}
				}
				else_if = {
					limit = {
						scope:target = {
							opinion = {
								target = scope:owner
								value < 35
							}
						}
					}
					random = {
						chance = 50
						scope:scheme = {
							end_scheme = yes
						}
					}
				}
				else = {
					scope:scheme = {
						end_scheme = yes
					}
				}
			}
		}
	}
	else = {
		#hidden_effect = { # What was this ever supposed to achieve?
		#	remove_opinion = {
		#		target = scope:owner
		#		modifier = scheme_sway_opinion
		#	}
		#	add_opinion = {
		#		target = scope:owner
		#		modifier = scheme_sway_opinion
		#		opinion = 100
		#	}
		#}
		scope:owner = {
			send_interface_toast = {
				title = sway_complete
				left_icon = scope:target
				scope:scheme = {
					end_scheme = yes
				}
			}
		}
	}
}

sway_ongoing_1002_outcome_effect = {
	if  = {
		limit = {
			exists = scope:believer
			has_relation_friend = scope:believer
		}
		show_as_tooltip = { theology_3021_a_success_effect = yes }
	}
	else = {
		random_list = {
			1 = {
				desc = diplomacy_majesty.0004.success.tt
				show_chance = no
				show_as_tooltip = {
					scope:compliment_receiver = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = 10
						}
					}
				}
			}
			1 = {
				desc = diplomacy_majesty.0004.failure.tt
				show_chance = no
				show_as_tooltip = {
					scope:compliment_receiver = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = -5
						}
					}
				}
			}
		}
	}

	hidden_effect = {
		if = {
			limit = {
				exists = scope:compliment_outcome
				scope:compliment_outcome = flag:good
			}
			trigger_event = sway_ongoing.1003
		}
		else_if = { #Is treated as a good outcome here
			limit = {
				exists = scope:compliment_outcome
				scope:compliment_outcome = flag:neutral
			}
			trigger_event = sway_ongoing.1003
		}
		else_if = {
			limit = {
				exists = scope:compliment_outcome
				scope:compliment_outcome = flag:bad
			}
			trigger_event = sway_ongoing.1004
		}
	}
}

##################################################
# Court Scheme Effects

court_success_prestige_effect = {

	if = {
		limit = { court_love_is_shunned_or_criminal_trigger = no }  #Only if it's not a taboo courtship

		#Whose tier matters?
		if = {
			limit = {
				scope:target = {
					is_ruler = no
					exists = liege
					OR = {
						is_spouse_of = this.liege
						is_close_or_extended_family_of = this.liege
					}
				}
			}
			scope:target = { liege = { save_scope_as = prestige_comparison } }
		}
		else = {
			scope:target = { save_scope_as = prestige_comparison }
		}

		#Epic
		if = {
			limit = {
				#They are at least two levels above you or empire level
				OR = {
					tier_difference = {
						target = scope:prestige_comparison
						value <= -2
					}
					scope:prestige_comparison.highest_held_title_tier = tier_empire
				}
			}
			add_prestige = massive_prestige_gain
		}
		#Great
		else_if = {
			limit = {
				OR = {
					#They are one level above you or kingdom level
					tier_difference = {
						target = scope:prestige_comparison
						value = -1
					}
					scope:prestige_comparison.highest_held_title_tier = tier_kingdom
				}
			}
			add_prestige = major_prestige_gain
		}
		#Good
		else_if = {
			limit = {
				#They're your level or duchy level
				OR = {
					scope:prestige_comparison.highest_held_title_tier = this.highest_held_title_tier
					scope:prestige_comparison.highest_held_title_tier = tier_duchy
				}
			}
			add_prestige = medium_prestige_value
		}
		#Okay
		else_if = {
			limit = {
				#They're at least county level
				scope:prestige_comparison.highest_held_title_tier >= tier_county
			}
			add_prestige = minor_prestige_value
		}
		#Everything else (everyone targeting barons/unlanded)
		else = {
			add_prestige = miniscule_prestige_value
		}
	}
}

court_ongoing_1010_good_duel_outcome_effect = {
	add_prestige = medium_prestige_gain
	scope:scheme = {
		add_scheme_modifier = {
			type = courting_act_of_heroism_modifier
		}
	}
}

court_ongoing_fetch_gift_modifier_effect = {
	#Wolf pelt
	if = {
		limit = { 
			scope:target = { has_character_flag = court_ongoing_wolf_pelt_flag }
			has_royal_court = yes # Since these are court artifacts and serve no real purpose to those without a court
		}
		create_artifact_animal_hide_effect = {
			OWNER = scope:target
			HUNTER = scope:target
			LEGENDARY = no
			ANIMAL = flag:wolf
		}
	} 
	# Necklace
	else_if = {
		limit = { 
			scope:target = { has_character_flag = court_ongoing_necklace_flag }
		}
		create_artifact_necklace_effect = {
			OWNER = scope:target
			SMITH = scope:target
		}
		hidden_effect_new_object = {
			scope:newly_created_artifact = {
				flag_as_trash_artifact = yes
			}
		}
	}
	# Flower
	else_if = {
		limit = { 
			scope:target = { has_character_flag = court_ongoing_orchid_flag }
		}
		save_scope_value_as = {
			name = flower_species
			value = flag:flower_type_orchid
		}
		create_artifact_pressed_flower_effect = { OWNER = scope:target } 
		clear_saved_scope = flower_species
		hidden_effect_new_object = {
			scope:newly_created_artifact = {
				flag_as_trash_artifact = yes
			}
		}
	}
	else = {
		add_character_modifier = {
			modifier = $GIFT$_modifier
			years = 20
		}
	}
}

court_ongoing_fetch_gift_target_outcome_effect = {
	hidden_effect = {
		scope:target = {
			if = {
				limit = { is_ai = no }
			}
			save_temporary_scope_value_as = {
				name = gift_outcome
				value = flag:$OUTCOME$
			}

			if = {
				limit = {
					scope:gift_outcome = flag:success
				}
				send_interface_toast = {
					title = court_ongoing.1021.$GIFT$.success
					left_icon = scope:owner
					court_ongoing_fetch_gift_modifier_effect = { GIFT = $GIFT$ }
				}
			}
			else_if = {
				limit = {
					scope:gift_outcome = flag:failure
				}
				send_interface_toast = {
					title = court_ongoing.1021.$GIFT$.failure
					left_icon = scope:owner
				}
			}
			#Flag clean up 
			remove_character_flag = court_ongoing_wolf_pelt_flag
			remove_character_flag = court_ongoing_necklace_flag
			remove_character_flag = court_ongoing_orchid_flag
		}
	}
}

court_ongoing_1030_dog_modifier_effect = {
	if = {
		limit = {
			NOT = { has_character_flag = had_dog_story }
		}
		start_dog_story_cycle_effect = yes
	}
}

court_ongoing_1030_cat_modifier_effect = {
	 if = {
		limit = {
			NOT = { has_character_flag = had_cat_story }
		}
		start_cat_story_cycle_effect = yes
	}
}

court_ongoing_1030_eagle_modifier_effect = {
	 if = {
		limit = {
			NOT = { has_character_flag = had_eagle_story }
		}
		save_scope_value_as = {
			name = eagle_capture_method
			value = flag:gift
		}
		start_eagle_story_cycle_effect = yes
	}
}

court_ongoing_1030_failure_effect = {
	reverse_add_opinion = {
		target = scope:target
		modifier = disappointed_opinion
		opinion = -10
	}
}

court_ongoing_1100_outcome_effect = {
	show_as_tooltip = {
		random_list = {
			1 = {
				desc = court_ongoing.1100.success.tt
				show_chance = no
				scope:scheme = {
					add_scheme_modifier = {
						type = courting_charm_modifier
					}
				}
			}
			1 = {
				desc = court_ongoing.1100.neutral.tt
				show_chance = no
			}
			1 = {
				desc = court_ongoing.1100.failure.tt
				show_chance = no
				reverse_add_opinion = {
					target = scope:target
					modifier = insult_opinion
					opinion = -10
				}
			}
		}
	}

	hidden_effect = {
		scope:target = {
			trigger_event = {
				id = court_ongoing.1101
				days = { 3 7 }
			}
		}
	}
}

court_consummate_effect = {
	if = {
		limit = { this = scope:owner }
		
	}
	else = {
		set_relation_soulmate = scope:owner
	}
}

court_kiss_effect = {
	
	hidden_effect = {
		if = {
			limit = { NOT = { has_relation_potential_lover = scope:target } }
			set_relation_potential_lover = scope:target
		}
	}
}

target_success_opinion_bonus_effect = {
	reverse_add_opinion = {
		target = scope:owner
		modifier = love_opinion
		opinion = 30
	}
}

end_court_scheme_effect = {
	save_temporary_scope_value_as = {
		name = court_outcome
		value = flag:$OUTCOME$
	}

	scope:owner = {
		# SUCCESS: SOULMATES
		# (This is the only one which target also needs to see, run it in owner scope in show_as_tooltip first and then execute in target's scope)
		if = {
			limit = { scope:court_outcome = flag:success_soulmate }
			
			scope:target = { set_relation_soulmate = { reason = $REASON$ target = prev } }
			if = {
				limit = {
					NOR = {
						has_sexuality = asexual
						scope:target = { has_sexuality = asexual }
					}
				}
				had_sex_with_effect = { #Run this in target scope because owner has own tooltip
					CHARACTER = scope:target
					PREGNANCY_CHANCE = pregnancy_chance
				}
			}		
			reverse_add_opinion = {
				target = scope:target
				modifier = romance_scheme_courtship_opinion #Blocks courtship
			}

			#Maybe break of existing lover relationships
			hidden_effect = {
				scope:target = {
					if = {
						limit = {
							has_trait = lustful
							is_ai = yes
							any_relation = {
								type = lover
								this != scope:owner
							}
						}
						every_relation = {
							type = lover
							random = {
								chance = 90
								opinion_modifier = { #Less likely if they really like the lover
									who = scope:target
									opinion_target = this
									multiplier = -0.5
									min = -20
								}
								modifier = { #More likely if they have more lovers
									add = 10
									scope:target = {
										any_relation = {
											type = lover
											count >= 2
										}
									}
								}
								lover_breakup_effect = {
									BREAKER = scope:target
									LOVER = this
								}
							}
						}
					}
				}
			}
		}
		# SUCCESS: KISS
		else_if = {
			limit = { scope:court_outcome = flag:success_kiss }
			custom_tooltip = court_outcome.kiss.tt
			reverse_add_opinion = {
				target = scope:target
				modifier = romance_scheme_courtship_opinion #Blocks courtship
			}
		}
		# FAILURE: SOFT
		else_if = {
			limit = { scope:court_outcome = flag:failure_soft }
			#Shared effect with Seduce because failure in one scheme should block the other
			scope:target = { seduction_cooldown_for_character_effect = { CHARACTER = scope:owner } }
		}
		# FAILURE: HARD
		else_if = {
			limit = { scope:court_outcome = flag:failure_hard }
			#Shared effect with Seduce because failure in one scheme should block the other
			scope:target = { seduction_block_character_effect = { CHARACTER = scope:owner } }
		}
		
		# Tradition bonuses
		if = {
			limit = {
				OR = {
					scope:court_outcome = flag:success_soulmate
					scope:court_outcome = flag:success_kiss
				}
				culture = {
					has_cultural_parameter = romance_scheme_bonuses
				}
				exists = dynasty
			}
			dynasty = {
				add_dynasty_prestige = minor_dynasty_prestige_gain
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:court_outcome = flag:failure_soft
					scope:court_outcome = flag:failure_hard
				}
				culture = {
					has_cultural_parameter = romance_scheme_bonuses
				}
			}
			add_stress = medium_stress_impact_gain
		}
	}

	scope:scheme = { end_scheme = yes }
}

##################################################
# Steal Back Artefact Scheme Effects

#Used in the immediate of the Scheme Owner's success event
steal_back_artifact_success_effect = {
	scope:target = {
		add_opinion = {
			target = scope:owner
			modifier = stole_artifact_from_me
		}
		# Feud score
		scope:owner.house = {
			change_house_relation_feud_score_effect = {
				TARGET = scope:owner.house
				REASON = stole_artifact
				VALUE = house_feud_medium_counter_value
			}
		}
		# Contracts
		hidden_effect = {
			if = {
				limit = {
					any_character_task_contract = {
						task_contract_type  = laamp_steal_artifact_contract
						var:task_contract_target ?= scope:target
					}
				}
				random_character_task_contract = {
					task_contract_type  = laamp_steal_artifact_contract
					limit = {
						var:task_contract_target ?= scope:target
					}
					complete_task_contract = success_standard
				}
			}
		}
	}
}

steal_back_artifact_failure_effect = {
	#Add Watchful Modifier to the target
	scope:target = {	
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
		add_opinion = {
			target = scope:owner
			modifier = attempted_to_steal_artifact_from_me
		}
	}
}

##################################################
# Scheme Start Effects

## Start a (non-contract) scheme with agents
#
# Arguments:
#  SCHEME_TYPE - Type of scheme
#  TARGET_TYPE - What type of thing to target (character or title)
#  TARGET_SCOPE - Individual game object to target (character or title)
#  AGENT_1..5 - Scheme agent slots for the scheme.
begin_scheme_with_agents_effect = {
	save_scope_as = scheme_launcher

	# Flag that we _don't_ need more agents.
	set_variable = {
		name = agents_added
		value = yes
		days = 1
	}

	# Start the scheme.
	start_scheme = {
		type = $SCHEME_TYPE$
		$TARGET_TYPE$ = $TARGET_SCOPE$

		save_scope_as = new_scheme
	}

	# Assign agent slots et al. to the newly created scheme.
	scope:new_scheme ?= {
		# Add our starting agents.
		add_agent_slot = $AGENT_1$
		add_agent_slot = $AGENT_2$
		add_agent_slot = $AGENT_3$
		add_agent_slot = $AGENT_4$
		add_agent_slot = $AGENT_5$

		# Assign initial agents for non-player schemers.
		if = {
			limit = {
				scope:scheme_launcher = {
					is_ai = yes
				}
			}
			auto_assign_scheme_agents = yes
		}

		# If we have a custom charge threshold to complete, set that here.
		## Overthrow Regent.
		if = {
			limit = { scheme_type = overthrow_regent }
			set_variable = {
				name = custom_charge_threshold
				value = 1
			}
		}
		# Set up our grace period.
		set_variable = {
			name = secrecy_grace_period
			value = secrecy_grace_character_total_starting_value
		}
	}

	open_view = {
		view = intrigue_window
		player = scope:new_scheme.scheme_owner
	}
}

begin_contract_scheme_with_agents_effect = {
	# Log our scheme launcher so that we can refer to them down the line.
	save_scope_as = scheme_launcher
	# Flag that we _don't_ need more agents.
	set_variable = {
		name = agents_added
		value = yes
		days = 1
	}
	every_scheme = { add_to_list = current_schemes_list }
	# check if you have to attach a contract to the scheme
	# Now start the scheme.
	start_scheme = {
		type = $SCHEME_TYPE$
		$TARGET_TYPE$ = $TARGET_SCOPE$
		contract = $TASK_CONTRACT$
	}
	# And grab the scheme's scope.
	random_scheme = {
		limit = {
			NOT = { is_in_list = current_schemes_list }
		}
		save_scope_as = new_scheme
	}
	scope:new_scheme ?= {
		# Add our starting agents.
		add_agent_slot = $AGENT_1$
		add_agent_slot = $AGENT_2$
		add_agent_slot = $AGENT_3$
		add_agent_slot = $AGENT_4$
		add_agent_slot = $AGENT_5$
		# If we have a custom charge threshold to complete, set that here.
		## Overthrow Regent.
		if = {
			limit = { scheme_type = overthrow_regent }
			set_variable = {
				name = custom_charge_threshold
				value = 1
			}
		}
		# Set up our grace period.
		set_variable = {
			name = secrecy_grace_period
			value = secrecy_grace_character_total_starting_value
		}
		set_variable = {
			name = attached_task_contract
			value = $TASK_CONTRACT$
		}
	}
	$TASK_CONTRACT$ = {
		set_variable = {
			name = attached_scheme
			value = scope:new_scheme
		}
	}
	open_view = {
		view = intrigue_window
		player = scope:new_scheme.scheme_owner
	}
}

begin_scheme_basic_effect = {
	# Log our scheme launcher so that we can refer to them down the line.
	save_scope_as = scheme_launcher
	# Log all the currently on-going schemes.
	## We do it this way being we can't guarantee mutually exclusive targets with non-character scheme targets any more: we can't just look for "X's murder scheme against Y", because X might be plotting against no target whatsoever and have multiple schemes of that type against nothing.
	every_scheme = { add_to_list = current_schemes_list }
	# Now start the scheme.
	start_scheme = {
		type = $SCHEME_TYPE$
		$TARGET_TYPE$ = $TARGET_SCOPE$
	}
	# And grab the scheme's scope.
	random_scheme = {
		limit = {
			NOT = { is_in_list = current_schemes_list }
		}
		save_scope_as = new_scheme
	}
	scope:new_scheme ?= {
		# If we have a custom charge threshold to complete, set that here.
		## Sway.
		if = {
			limit = { scheme_type = sway }
			set_variable = {
				name = custom_charge_threshold
				value = 5
			}
		}
	}
}

add_scheme_starting_opportunities_intrigue_effect = {
	if = {
		limit = { scheme_owner.intrigue >= scheme_starting_opportunities_per_intrigue_threshold_value }
		change_opportunities = {
			value = scheme_owner.intrigue
			subtract = scheme_starting_opportunities_per_intrigue_threshold_value
			divide = scheme_starting_opportunities_per_intrigue_increment_value
			ceiling = yes
			max = 4
		}
	}
}

##################################################
# Scheme Pulse Action Effects

# How many months should we wait before another pulse action can be queued?
scheme_pulse_action_sort_cooldown_effect = {
	set_variable = {
		name = scheme_pulse_action_on_cooldown
		value = yes
		months = 8
	}
}

##################################################
# Countermeasure Effects

inform_player_of_relevant_countermeasure_activated_effect = {
	every_player = {
		limit = {
			any_scheme = {
				scheme_target_character ?= root
				has_variable = apply_countermeasures
			}
		}
		send_interface_message = {
			type = msg_countermeasure_change
			title = countermeasures.t.target_changes
			desc = countermeasures.desc.$COUNTERMEASURE$
			right_icon = root
		}
	}
}

dispute_borders_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.8001
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

subsume_province_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.8011
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}

raid_estate_opinion_effect = {
	$TARGET$ = { save_temporary_scope_as = target_temp }
	$OWNER$ = { save_temporary_scope_as = owner_temp }
	scope:target_temp.house.house_head ?= {
		# OPINION
		add_opinion = {
			target = scope:owner_temp
			modifier = raided_estate_crime
		}
		# FEUD
		if = {
			limit = { has_relation_rival = scope:owner_temp }
			if = {
				limit = { valid_for_feud_events_with_target_trigger = { TARGET = scope:owner_temp } }
				house_feud_start_effect = {
					# Feuding House Head
					ACTOR = scope:target_temp
					# Target House Head
					TARGET = scope:owner_temp
					# Feud Reason
					REASON = raid_estate
					# House Member attacker if relevant 
					ATTACKER = scope:target_temp
					# House Member victim if relevant
					VICTIM = scope:owner_temp
				}
			}
		}
		# RELATION
		progress_towards_rival_effect = {
			REASON = rival_raid_estate
			CHARACTER = scope:owner_temp
			OPINION = 0
		}
	}
	# VICTIM OPINION
	every_in_list = {
		list = target_victims
		if = {
			limit = { exists = scope:scheme_maim }
			add_opinion = {
				target = scope:owner_temp
				modifier = raid_estate_maimed_opinion
			}
		}
	}
	scope:target_temp.house = {
		# HOUSE RELATION
		change_house_relation_effect = {
			HOUSE = scope:owner_temp.house
			VALUE = house_relation_damage_major_value
			REASON = raided_estate
			CHAR = scope:owner_temp
			TARGET_CHAR = scope:target_temp
			TITLE = scope:dummy_gender
		}
		# OTHER MEMBER OPINION
		every_house_member = {
			custom = every_other_raid_estate_house_member_tt
			limit = {
				NOR = {
					this = scope:target_temp
					is_in_list = target_victims
				}
			}
			add_opinion = {
				target = scope:owner_temp
				modifier = raid_estate_house_opinion
			}
		}
	}
	# CRIME
	scope:owner_temp.top_liege ?= {
		if = {
			limit = {
				this != scope:owner_temp
				this != scope:target_temp
				NOT = { scope:owner_temp.var:raid_estate_permission ?= scope:target_temp.house }
			}
			add_opinion = {
				target = scope:owner_temp
				modifier = raid_estate_vassal_crime
			}
		}
	}
}

education_5_scheme_progress_effect = {
	if = {
		limit = {
			scope:actor = { has_trait = education_$SKILL$_5 }
		}
		scope:new_scheme ?= {
			add_scheme_progress = {
				value = scheme_progress_gain
				multiply = 3
			}
		}
	}
}

steal_herd_success_effect = {
	if = {
		limit = {
			scope:target = {
				exists = domicile
				domicile.herd > 0
			}
		}
		scope:target = {
			if = {
				limit = {
					scope:owner = {
						OR = {
							is_vassal_of = scope:target
							is_liege_or_above_of = scope:target
						}
					}
				}
				add_opinion = {
					target = scope:owner
					modifier = stole_my_herd_crime
				}
			}
			else = {
				add_opinion = {
					target = scope:owner
					modifier = stole_my_herd
				}
			}
			if = {
				limit = {
					is_independent_ruler = no
					liege = {
						NOT = { is_liege_or_above_of = scope:owner }
					}
				}
				liege = {
					add_opinion = {
						target = scope:owner
						modifier = stole_vassals_herd
					}
				}
			}
			custom_tooltip = {
				text = steal_herd_vassal_tt
				every_powerful_vassal = {
					limit = { 
						NOR = { 
							this = scope:target
							this = scope:owner
						} 
					}
					add_opinion = {
						target = scope:owner
						modifier = stole_lieges_herd
					}
				}
			}
		}
		scope:owner = {
			if = {
				limit = {
				   scope:scheme = { exists = var:steal_herd_low }
				}
				if = {
					limit = {
						has_character_flag = steal_herd_extra
					}
					scope:target = {
						pay_herd = {
							target = scope:owner
							value = {
								value = domicile.ten_percent_current_herd_value
								max = scope:owner.domicile.fifty_percent_current_herd_value
							}
						}
					}
				}
				else = {
					scope:target = {
						pay_herd = {
							target = scope:owner
							value = {
								value = domicile.five_percent_current_herd_value
								max = scope:owner.domicile.fifty_percent_current_herd_value
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					scope:scheme = { exists = var:steal_herd_normal }
				}
				if = {
					limit = {
						has_character_flag = steal_herd_extra
					}
					scope:target = {
						pay_herd = {
							target = scope:owner
							value = {
								value = domicile.fifteen_percent_current_herd_value
								max = scope:owner.domicile.fifty_percent_current_herd_value
							}
						}
					}
				}
				else = {
					scope:target = {
						pay_herd = {
							target = scope:owner
							value = {
								value = domicile.ten_percent_current_herd_value
								max = scope:owner.domicile.fifty_percent_current_herd_value
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					scope:scheme = { exists = var:steal_herd_high }
				}
				if = {
					limit = {
						has_character_flag = steal_herd_extra
					}
					scope:target = {
						pay_herd = {
							target = scope:owner
							value = {
								value = domicile.twenty_percent_current_herd_value
								max = scope:owner.domicile.fifty_percent_current_herd_value
							}
						}
					}
				}
				else = {
					scope:target = {
						pay_herd = {
							target = scope:owner
							value = {
								value = domicile.fifteen_percent_current_herd_value
								max = scope:owner.domicile.fifty_percent_current_herd_value
							}
						}
					}
				}
			}
		}
	}
	
	scope:owner = {
		if = {
			limit = {
				has_character_flag = steal_herd_money
			}
			scope:target = {
				pay_short_term_gold = {
					target = scope:owner
					gold = medium_gold_value
				}
			}
			remove_character_flag = steal_herd_money
		}

		if = {
			limit = {
				has_character_flag = steal_herd_extra
			}
			remove_character_flag = steal_herd_extra
		}
	}
}

steal_herd_failure_effect = {
	#Add Watchful Modifier to the target
	scope:target = {	
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}

		add_opinion = {
			target = scope:owner
			modifier = attempted_to_steal_herd_crime
		}
	}
	#Lose some prestige
	scope:owner = {
		add_prestige = minor_prestige_loss
	}
}

purge_ai_scheme_slots_effect = {
	scope:scheme = {
		if = {
			limit = {
				any_scheme_agent_slot = {
					is_filled = no
				}
			}
			every_scheme_agent_slot = {
				limit = {
					is_filled = no
				}
				save_scope_as = slot_purge
				prev = { remove_agent_slot = scope:slot_purge }
			}
		}
	}
}

coup_ceremonial_liege_scheme_prep_effect = {
	save_scope_as = scheme
	save_scope_value_as = {
		name = follow_up_event
		value = event_id:scheme_critical_moments.2921
	}
	if = {
		limit = {
			NOT = { exists = scope:suppress_next_event }
		}
		scheme_owner = { trigger_event = scheme_critical_moments.0002 }
	}
}
