# Faction tags need to start with 'faction_'

# Supported types:
# liege_titles, liege_titles_w_claimant, character

# The succession law factions have hard coded elements to ensure that the correct heir is shown in Plot and 
# Faction interfaces and that AI faction members vote for laws in accordance with the faction goal.
# The valid tags correspond to the law name: faction_succ_seniority, faction_succ_primogeniture, etc.

###############
# FACTIONS
###############

# Court faction: desires more power for vassals
faction_court = {
	type = liege_titles
	
	# Plotter scope
	potential = {
		is_playable = yes
		independent = no
		is_nomadic = no
		prisoner = no
		is_adult = yes
		primary_title = { holy_order = no }
		is_landed = yes
		NOT = { trait = incapable }
		liege = {
			is_nomadic = no
			NOR = {
				character = ROOT
				has_character_flag = faction_court_war
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		OR = {
			NOT = { has_character_flag = former_faction_leader }
			had_character_flag = { flag = former_faction_leader days = 7 }
		}
		NOT = {
			any_faction_backer = {
				in_faction = faction_court
				NOT = { has_character_flag = removed_from_leadership }
				higher_real_tier_than = ROOT
			}
		}
		NOR = {
			in_revolt = yes
			in_faction = faction_prosperity
			in_faction = faction_glory
			in_faction = faction_tradition
		}
	}
	
	# Target scope (ROOT = liege title, FROM = faction leader)
	allow = {
		is_primary_holder_title = yes
		FROM = { primary_title = { is_primary_type_title = no } }
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			independent = no
			is_nomadic = no
			prisoner = no
			is_adult = yes
			is_landed = yes
			OR = {
				has_character_flag = will_join_civil_war
				NOR = {
					is_inaccessible_trigger = yes
					in_faction = faction_prosperity
					in_faction = faction_glory
					in_faction = faction_tradition
				}
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 100
		modifier = {
			factor = 0
			FROM = {
				NOT = { has_character_flag = faction_court_supporter }
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					controls_religion = yes
					rightful_religious_head_scope = { character = PREV }
				}
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = king
				liege = { real_tier = emperor }
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = duke
				liege = { real_tier = king }
			}
		}
		modifier = {
			factor = 0
			current_heir = { character = FROM }
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100
		modifier = {
			factor = 0
			NOR = {
				ROOT = { has_character_flag = faction_court_supporter }
				AND = {
					ROOT = { has_character_flag = will_join_civil_war }
					FROM = {
						has_character_flag = civil_war_faction_leader
						pf_not_regular_faction_war_trigger = no
					}
				}
			}
		}
		modifier = {
			factor = 10
			ROOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}	

# Prosperity faction: desires wealth and a healthy economy
faction_prosperity = {
	type = liege_titles
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		NOT = { trait = incapable }
		liege = {
			is_nomadic = no
			NOR = {
				character = ROOT
				has_character_flag = faction_prosperity_war
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		OR = {
			NOT = { has_character_flag = former_faction_leader }
			had_character_flag = { flag = former_faction_leader days = 7 }
		}
		NOT = {
			any_faction_backer = {
				in_faction = faction_prosperity
				NOT = { has_character_flag = removed_from_leadership }
				higher_real_tier_than = ROOT
			}
		}
		NOR = {
			in_revolt = yes
			in_faction = faction_court
			in_faction = faction_glory
			in_faction = faction_tradition
		}
	}

	# Target scope (ROOT = liege title, FROM = faction leader)
	allow = {
		is_primary_holder_title = yes
		FROM = { primary_title = { is_primary_type_title = no } }
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			independent = no
			is_nomadic = no
			prisoner = no
			is_adult = yes
			is_landed = yes
			OR = {
				has_character_flag = will_join_civil_war
				NOR = {
					is_inaccessible_trigger = yes
					in_faction = faction_court
					in_faction = faction_glory
					in_faction = faction_tradition
				}
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 100
		modifier = {
			factor = 0
			FROM = {
				NOT = { has_character_flag = faction_prosperity_supporter }
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					controls_religion = yes
					rightful_religious_head_scope = { character = PREV }
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = king
				liege = { real_tier = emperor }
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = duke
				liege = { real_tier = king }
			}
		}
		modifier = {
			factor = 0
			current_heir = { character = FROM }
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
	}
		
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100
		modifier = {
			factor = 0
			NOR = {
				ROOT = { has_character_flag = faction_prosperity_supporter }
				AND = {
					ROOT = { has_character_flag = will_join_civil_war }
					FROM = {
						has_character_flag = civil_war_faction_leader
						pf_not_regular_faction_war_trigger = no
					}
				}
			}
		}
		modifier = {
			factor = 10
			ROOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}	

# Glory faction: desires prestige and the spoils of war
faction_glory = {
	type = liege_titles
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		NOT = { trait = incapable }
		liege = {
			is_nomadic = no
			NOR = {
				character = ROOT
				has_character_flag = faction_glory_war
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		OR = {
			NOT = { has_character_flag = former_faction_leader }
			had_character_flag = { flag = former_faction_leader days = 7 }
		}
		NOT = {
			any_faction_backer = {
				in_faction = faction_glory
				NOT = { has_character_flag = removed_from_leadership }
				higher_real_tier_than = ROOT
			}
		}
		NOR = {
			in_revolt = yes
			in_faction = faction_court
			in_faction = faction_prosperity
			in_faction = faction_tradition
		}
	}

	# Target scope (ROOT = liege title, FROM = faction leader)
	allow = {
		is_primary_holder_title = yes
		FROM = { primary_title = { is_primary_type_title = no } }
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			independent = no
			is_nomadic = no
			prisoner = no
			is_adult = yes
			is_landed = yes
			OR = {
				has_character_flag = will_join_civil_war
				NOR = {
					is_inaccessible_trigger = yes
					in_faction = faction_prosperity
					in_faction = faction_court
					in_faction = faction_tradition
				}
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 100
		modifier = {
			factor = 0
			FROM = {
				NOT = { has_character_flag = faction_glory_supporter }
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					controls_religion = yes
					rightful_religious_head_scope = { character = PREV }
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = king
				liege = { real_tier = emperor }
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = duke
				liege = { real_tier = king }
			}
		}
		modifier = {
			factor = 0
			current_heir = { character = FROM }
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100
		modifier = {
			factor = 0
			NOR = {
				ROOT = { has_character_flag = faction_glory_supporter }
				AND = {
					ROOT = { has_character_flag = will_join_civil_war }
					FROM = {
						has_character_flag = civil_war_faction_leader
						pf_not_regular_faction_war_trigger = no
					}
				}
			}
		}
		modifier = {
			factor = 10
			ROOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}	

# Tradition faction: desires piety and support for religion
faction_tradition = {
	type = liege_titles
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		liege = {
			is_nomadic = no
			religion = ROOT
			NOR = {
				character = ROOT
				has_character_flag = faction_tradition_war
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		OR = {
			NOT = { has_character_flag = former_faction_leader }
			had_character_flag = { flag = former_faction_leader days = 7 }
		}
		NOT = {
			any_faction_backer = {
				in_faction = faction_tradition
				NOT = { has_character_flag = removed_from_leadership }
				higher_real_tier_than = ROOT
			}
		}
		NOR = {
			trait = incapable
			trait = excommunicated
			in_revolt = yes
			in_faction = faction_court
			in_faction = faction_prosperity
			in_faction = faction_glory
		}
	}

	# Target scope (ROOT = liege title, FROM = faction leader)
	allow = {
		is_primary_holder_title = yes
		FROM = { primary_title = { is_primary_type_title = no } }
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			independent = no
			is_nomadic = no
			prisoner = no
			is_adult = yes
			is_landed = yes
			OR = {
				has_character_flag = will_join_civil_war
				NOR = {
					is_inaccessible_trigger = yes
					trait = excommunicated
					liege = { NOT = { religion = PREV } }
					in_faction = faction_prosperity
					in_faction = faction_glory
					in_faction = faction_court
				}
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 100
		modifier = {
			factor = 0
			FROM = {
				NOT = { has_character_flag = faction_tradition_supporter }
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					controls_religion = yes
					rightful_religious_head_scope = { character = PREV }
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = king
				liege = { real_tier = emperor }
			}
		}
		modifier = {
			factor = 10
			FROM = {
				real_tier = duke
				liege = { real_tier = king }
			}
		}
		modifier = {
			factor = 0
			current_heir = { character = FROM }
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100
		modifier = {
			factor = 0
			NOR = {
				ROOT = { has_character_flag = faction_tradition_supporter }
				AND = {
					ROOT = { has_character_flag = will_join_civil_war }
					FROM = {
						has_character_flag = civil_war_faction_leader
						pf_not_regular_faction_war_trigger = no
					}
				}
			}
		}
		modifier = {
			factor = 10
			ROOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				trait = cynical
				NOT = { has_character_flag = will_join_civil_war }
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}	

# Institute Succession by Seniority
faction_succ_seniority = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		faction_council_trigger = yes
		liege = {
			is_feudal = yes
			has_imperial_government_trigger = no
			is_vice_royalty = no
			NOR = {
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		NOR = {
			in_revolt = yes
			trait = incapable
			religion_group = muslim
			religion_group = indian_group
			religion = celtic_pagan
			in_faction = faction_succ_primogeniture
			in_faction = faction_succ_feudal_elective
			in_faction = faction_succ_gavelkind
			in_faction = faction_separatist
		}
		
		OR = {
			# Is not affected by a Crown Law title
			NOT = { crownlaw_title = { always = yes } }
			# The Crown Law title holder is my liege
			crownlaw_title = { holder_scope = { is_liege_of = ROOT } }
			# king's peace has not been enforced
			AND = {
				will_liege_enforce_peace = no
				has_liege_enforced_peace = no
			}
		}
	}
	
	# Target scope
	allow = {
		OR = {
			is_law_potential = succ_institute_seniority
			is_law_potential = succ_elective_to_seniority
		}
		OR = {
			is_primary_holder_title = yes
			higher_tier_than = DUKE
		}
		holder_scope = {
			NOT = {
				any_war = { war_title = ROOT }
			}
		}
		FROM = {
			primary_title = {
				OR = {
					emf_laws_crownlaw_title_medium_ca_plus_trigger = yes
					emf_laws_holder_has_late_adminstration_plus_trigger = yes
					custom_tooltip = {
						text = emf_laws_ctt_patrician_not_primary_title
						holder_scope = {
							is_patrician = yes
							OR = {
								is_merchant_republic = no
								PREV = {
									is_primary_holder_title = no
								}
								NOR = {
									in_revolt = yes
									succ_law_title = {
										title = PREVPREV
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			prisoner = no
			is_nomadic = no
			faction_council_trigger = yes
			OR = {
				NOT = { is_inaccessible_trigger = yes }
				has_character_flag = will_join_civil_war
			}
			is_adult = yes
			OR = {
				NOR = {
					in_faction = faction_succ_primogeniture
					in_faction = faction_succ_feudal_elective
					in_faction = faction_succ_gavelkind
					in_faction = faction_separatist
				}
				has_character_flag = will_join_civil_war
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				religion_group = muslim
				religion_group = indian_group
				religion = celtic_pagan
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 1
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		modifier = {
			factor = 0
			holder_scope = { is_married = FROM }
		}
		modifier = {
			factor = 0
			current_heir = {
				OR = {
					character = FROM
					is_married = FROM
					is_primary_heir = FROM
					is_friend = FROM
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
		modifier = {
			factor = 0
			NOR = {
				has_title_flag = former_seniority
				FROM = {
					OR = {
						culture_group = east_slavic
						culture_group = west_slavic
						culture_group = south_slavic
						culture = hungarian
						culture = ethiopian
					}
				}
				heir_under_seniority_law = {
					OR = {
						character = FROM
						is_married = FROM
						is_primary_heir = FROM
					}
					trait = ambitious
					diplomacy = 12
				}
				heir_under_seniority_law = {
					OR = {
						is_friend = FROM
						is_lover = FROM
					}
					NOR = {
						trait = content
						trait = humble
						trait = greedy
						trait = slothful
						trait = envious
					}
					diplomacy = 12
				}	
			}
		}
		modifier = {
			factor = 0
			#either has to be the seniority heir or the seniority heir is a dynasty member/ally I like better than my liege
			NOR = {
				would_be_heir_under_law = { who = FROM law = seniority }
				heir_under_seniority_law = {
					OR = {
						dynasty = FROM
						is_married = FROM
						is_friend = FROM
						is_lover = FROM
					}
					FROM = { opinion_diff = { first = PREV second = LIEGE value = 25 as_if_liege = yes } }
					reverse_opinion = { who = FROM value = 0 }
				}
			}
		}
		modifier = {
			factor = 0
			#either has to be the seniority heir or I can't like the current heir a lot more than the seniority heir
			NOR = {
				would_be_heir_under_law = { who = FROM law = seniority }
				heir_under_seniority_law = {
					ROOT = {
						current_heir = {
							FROM = {
								NOT = { opinion_diff = { first = PREV second = PREVPREVPREV value = 40 as_if_liege = yes } }
							}
						}
					}
				}
			}
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			heir_under_seniority_law = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
			}
			holder_scope = {
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					FROM = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			FROM = { 
				opinion = { who = LIEGE value = 0 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}			
			}
		}
		modifier = {
			factor = 0
			FROM = { 
				opinion = { who = LIEGE value = 20 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}			
			}
		}
		modifier = {
			factor = 0.1
			FROM = {
				opinion = { who = LIEGE value = 20 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}				
			}
		}
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = 40 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}				
			}
		}
		modifier = {
			factor = 0.20
			FROM = { pacifist = yes }
		}
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = 0 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1
		modifier = {
			factor = 1000
			has_character_flag = will_join_civil_war
			FROM = {
				has_character_flag = demands_seniority
				has_character_flag = civil_war_faction_leader
			}
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}
		modifier = {
			factor = 0
			preparing_invasion = yes
		}
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					OR = {
						character = ROOT
						is_married = ROOT
						is_primary_heir = ROOT
						is_friend = ROOT
					}
				}
			}
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				holder_scope = { is_married = ROOT }
			}
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				heir_under_seniority_law = {
					OR = {
						NOT = { compare_cultures_ROOT_trigger = yes }
						NOT = { religion = ROOT }
					}
				}
			}
			liege = {
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					ROOT = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_ROOT_trigger = yes
						religion = ROOT
					}
				}
			}
		}		
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				heir_under_seniority_law = {
					ROOT = {
						OR = {
							AND = {
								NOT = { in_faction = faction_succ_seniority }
								opinion_diff = {
									first = LIEGE
									second = PREV
									value = -10 # I don't like the pretender enough
									as_if_liege = yes
								}
							}
							AND = {
								in_faction = faction_succ_seniority
								opinion_diff = {
									first = LIEGE
									second = PREV
									value = 10
									as_if_liege = yes
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			#either has to be the seniority heir or the seniority heir is a dynasty member/ally I like better than my liege
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				NOR = {
					would_be_heir_under_law = { who = ROOT law = seniority }
					heir_under_seniority_law = {
						ROOT = { opinion_diff = { first = PREV second = LIEGE value = 25 as_if_liege = yes } }
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
		}
		modifier = {
			factor = 2
			#I like the seniority heir a LOT more than my liege
			FROMFROM = {
				heir_under_seniority_law = {
					ROOT = { opinion_diff = { first = PREV second = LIEGE value = 40 as_if_liege = yes } }
					reverse_opinion = { who = ROOT value = 0 }
				}
			}
		}
		modifier = {
			factor = 0
			#either has to be the seniority heir or I can't like the current heir a lot more than the seniority heir
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				NOR = {
					would_be_heir_under_law = { who = ROOT law = seniority }
					heir_under_seniority_law = {
						PREV = {
							current_heir = {
								ROOT = {
									NOT = { opinion_diff = { first = PREV second = PREVPREVPREV value = 40 as_if_liege = yes } }
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 0 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}		
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 20 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}		
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 20 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}		
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 40 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 0.01
			trait = content
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.01
			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
	}

	success = {
		has_law = succ_seniority
	}
	abort = {
		always = no		# Factions will abort if the Potential or Allow triggers are no longer valid
	}
	abort_effect = {
	}
	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_succ_seniority
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Institute Succession by Primogeniture
faction_succ_primogeniture = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		faction_council_trigger = yes
		liege = {
			NOT = { government = chinese_imperial_government }
			is_feudal = yes
			is_vice_royalty = no
			NOR = {
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		NOR = {
			in_revolt = yes
			trait = incapable
			religion_group = muslim
			religion = celtic_pagan
			in_faction = faction_succ_seniority
			in_faction = faction_succ_feudal_elective
			in_faction = faction_succ_gavelkind
			in_faction = faction_separatist
		}
		
		OR = {
			# Is not affected by a Crown Law title
			NOT = { crownlaw_title = { always = yes } }
			# The Crown Law title holder is my liege
			crownlaw_title = { holder_scope = { is_liege_of = ROOT } }
			# king's peace has not been enforced
			AND = {
				will_liege_enforce_peace = no
				has_liege_enforced_peace = no
			}
		}
	}
	
	# Target scope
	allow = {
		OR = {
			is_law_potential = succ_institute_primogeniture
			is_law_potential = succ_elective_to_primogeniture
		}
		OR = {
			is_primary_holder_title = yes
			higher_tier_than = DUKE
		}
		holder_scope = {
			NOT = {
				any_war = { war_title = ROOT }
			}
		}
		FROM = {
			primary_title = {
				OR = {
					emf_laws_crownlaw_title_high_ca_plus_trigger = yes
					emf_laws_holder_has_late_adminstration_plus_trigger = yes
					custom_tooltip = {
						text = emf_ctt_holds_viceroyalty
						hidden_tooltip = {
							holder_scope = { any_demesne_title = { is_vice_royalty = yes } }
						}
					}
				}
			}
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			prisoner = no
			is_nomadic = no
			faction_council_trigger = yes
			OR = {
				NOT = { is_inaccessible_trigger = yes }
				has_character_flag = will_join_civil_war
			}
			is_adult = yes
			OR = {
				NOR = {
					in_faction = faction_succ_seniority
					in_faction = faction_succ_feudal_elective
					in_faction = faction_succ_gavelkind
					in_faction = faction_separatist
				}
				has_character_flag = will_join_civil_war
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				religion_group = muslim
				religion = celtic_pagan
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}	

	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 1
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		modifier = {
			factor = 0
			holder_scope = { is_married = FROM }
		}
		modifier = {
			factor = 0
			current_heir = {
				OR = {
					character = FROM
					is_married = FROM
					is_primary_heir = FROM
					is_friend = FROM
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
		modifier = {
			factor = 2
			has_title_flag = former_primogeniture
		}
		modifier = {
			factor = 0
			NOR = {
				has_title_flag = former_primogeniture
				heir_under_primogeniture_law = {
					OR = {
						character = FROM
						is_married = FROM
						is_primary_heir = FROM
					}
					trait = ambitious
					diplomacy = 12
				}
				heir_under_primogeniture_law = {
					OR = {
						is_friend = FROM
						is_lover = FROM
					}
					NOR = {
						trait = content
						trait = humble
						trait = greedy
						trait = slothful
						trait = envious
					}
					diplomacy = 12
				}	
			}
		}
		modifier = {
			factor = 0
			#either has to be the primogeniture heir or the primogeniture heir is a dynasty member/ally I like better than my liege
			NOR = {
				would_be_heir_under_law = { who = FROM law = primogeniture }
				heir_under_primogeniture_law = {
					OR = {
						dynasty = FROM
						is_married = FROM
						is_friend = FROM
						is_lover = FROM
					}
					FROM = { opinion_diff = { first = PREV second = LIEGE value = 25 as_if_liege = yes } }
					reverse_opinion = { who = FROM value = 0 }
				}
			}
		}
		modifier = {
			factor = 0
			#either has to be the primogeniture heir or I can't like the current heir a lot more than the primogeniture heir
			NOR = {
				would_be_heir_under_law = { who = FROM law = primogeniture }
				heir_under_primogeniture_law = {
					ROOT = {
						current_heir = {
							FROM = {
								NOT = { opinion_diff = { first = PREV second = PREVPREVPREV value = 40 as_if_liege = yes } }
							}
						}
					}
				}
			}
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			heir_under_primogeniture_law = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
			}
			holder_scope = {
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					FROM = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			FROM = { 
				opinion = { who = LIEGE value = 0 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}			
			}
		}
		modifier = {
			factor = 0
			FROM = { 
				opinion = { who = LIEGE value = 20 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}			
			}
		}
		modifier = {
			factor = 0.1
			FROM = {
				opinion = { who = LIEGE value = 20 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}				
			}
		}
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = 40 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}				
			}
		}
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = 0 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1
		modifier = {
			factor = 1000
			has_character_flag = will_join_civil_war
			FROM = {
				has_character_flag = demands_primogeniture
				has_character_flag = civil_war_faction_leader
			}
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}
		modifier = {
			factor = 0
			preparing_invasion = yes
		}
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					OR = {
						character = ROOT
						is_married = ROOT
						is_primary_heir = ROOT
						is_friend = ROOT
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = { is_married = ROOT }
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					PREV = {
						heir_under_primogeniture_law = {
							character = PREVPREV
						}
					}
				}
			}
		}
		modifier = {
			factor = 2
			FROMFROM = { has_title_flag = former_primogeniture }
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				heir_under_primogeniture_law = {
					OR = {
						NOT = { compare_cultures_ROOT_trigger = yes }
						NOT = { religion = ROOT }
					}
				}
			}
			liege = {
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					ROOT = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_ROOT_trigger = yes
						religion = ROOT
					}
				}
			}
		}		
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				heir_under_primogeniture_law = {
					ROOT = {
						OR = {
							AND = {
								NOT = { in_faction = faction_succ_primogeniture }
								opinion_diff = {
									first = LIEGE
									second = PREV
									value = -10 # I don't like the pretender enough
									as_if_liege = yes
								}
							}
							AND = {
								in_faction = faction_succ_primogeniture
								opinion_diff = {
									first = LIEGE
									second = PREV
									value = 10
									as_if_liege = yes
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			#either has to be the primogeniture heir or the primogeniture heir is someone I like better than my liege
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				NOR = {
					would_be_heir_under_law = { who = ROOT law = primogeniture }
					heir_under_primogeniture_law = {
						ROOT = { opinion_diff = { first = PREV second = LIEGE value = 25 as_if_liege = yes } }
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
		}
		modifier = {
			factor = 2
			#I like the primogeniture heir a LOT more than my liege
			FROMFROM = {
				heir_under_primogeniture_law = {
					ROOT = { opinion_diff = { first = PREV second = LIEGE value = 40 as_if_liege = yes } }
					reverse_opinion = { who = ROOT value = 0 }
				}
			}
		}
		modifier = {
			factor = 0
			#either has to be the primogeniture heir or I can't like the current heir a lot more than the primogeniture heir
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				NOR = {
					would_be_heir_under_law = { who = ROOT law = primogeniture }
					heir_under_primogeniture_law = {
						PREV = {
							current_heir = {
								ROOT = {
									NOT = { opinion_diff = { first = PREV second = PREVPREVPREV value = 40 as_if_liege = yes } }
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 0 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}		
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 20 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}		
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 20 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}		
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 40 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 0.01
			trait = content
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.01
			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
	}

	success = {
		has_law = succ_primogeniture
	}	
	abort = {
		always = no		# Factions will abort if the Potential or Allow triggers are no longer valid
	}
	abort_effect = {
	}
	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_succ_primogeniture
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Institute Succession by Gavelkind
faction_succ_gavelkind = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		faction_council_trigger = yes
		liege = {
			has_imperial_government_trigger = no
			OR = {
				is_feudal = yes
				is_tribal = yes
			}
			is_vice_royalty = no
			NOR = {
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		NOR = {
			in_revolt = yes
			trait = incapable
			religion_group = muslim
			religion = celtic_pagan
			in_faction = faction_succ_primogeniture
			in_faction = faction_succ_feudal_elective
			in_faction = faction_succ_seniority
			in_faction = faction_separatist
		}
		
		OR = {
			# Is not affected by a Crown Law title
			NOT = { crownlaw_title = { always = yes } }
			# The Crown Law title holder is my liege
			crownlaw_title = { holder_scope = { is_liege_of = ROOT } }
			# king's peace has not been enforced
			AND = {
				will_liege_enforce_peace = no
				has_liege_enforced_peace = no
			}
		}
	}
	
	# Target scope
	allow = {
		OR = {
			is_law_potential = succ_institute_gavelkind
			is_law_potential = succ_elective_to_gavelkind
		}
		OR = {
			is_primary_holder_title = yes
			higher_tier_than = DUKE
		}
		holder_scope = {
			NOT = {
				any_war = { war_title = ROOT }
			}
		}
		FROM = { primary_title = { is_primary_type_title = no } }
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			prisoner = no
			is_nomadic = no
			faction_council_trigger = yes
			OR = {
				NOT = { is_inaccessible_trigger = yes }
				has_character_flag = will_join_civil_war
			}
			is_adult = yes
			OR = {
				NOR = {
					in_faction = faction_succ_primogeniture
					in_faction = faction_succ_feudal_elective
					in_faction = faction_succ_seniority
					in_faction = faction_separatist
				}
				has_character_flag = will_join_civil_war
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				religion_group = muslim
				religion = celtic_pagan
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}	

	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 1
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		modifier = {
			factor = 0
			holder_scope = { is_married = FROM }
		}
		modifier = {
			factor = 0
			current_heir = {
				OR = {
					character = FROM
					is_married = FROM
					is_primary_heir = FROM
					is_friend = FROM
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
		#holder does not have more than one eligible heir
		modifier = {
			factor = 0
			holder_scope = {
				NOT = {
					any_child = {
						OR = {
							AND = {
								is_female = no
								ROOT = {
									NOT = { has_law = enatic_succession }
									NOT = { has_law = enatic_cognatic_succession }
								}
							}
							AND = {
								is_female = yes
								ROOT = {
									NOT = { has_law = agnatic_succession }
									NOT = { has_law = cognatic_succession }
								}
							}
						}
						dynasty = PREV
						NOR = {
							trait = bastard
							trait = disinherited
							is_dumb_trigger = yes
							trait = inbred
							trait = incapable
							trait = lunatic
						}
						count = 2
					}
				}
			}
		}
		#do not switch from Feudal Elective/Elective Gavelkind
		modifier = {
			factor = 0
			OR = {
				has_law = succ_feudal_elective
				has_law = succ_elective_gavelkind
			}
		}
		#cannot be formed by counts except under dukes
		modifier = {
			factor = 0
			OR = {
				FROM = { higher_tier_than = COUNT }
				holder_scope = { lower_tier_than = KING }
			}
		}
		modifier = {
			factor = 0
			NOR = {
				#was formerly gavelkind
				has_title_flag = former_gavelkind
				#is of an appropriate culture
				FROM = {
					OR = {
						is_tribal = yes
						culture_group = north_germanic
						culture_group = central_germanic
						culture_group = west_germanic
					}
				}
				#holder has another eligible child I like more than the current heir
				holder_scope = {
					any_child = {
						diplomacy = 12
						OR = {
							character = FROM
							is_married = FROM
							is_friend = FROM
							is_lover = FROM
							ROOT = {
								current_heir = {
									FROM = {
										opinion_diff = { first = PREVPREVPREV second = PREV value = 25 as_if_liege = yes }
										opinion = { who = PREVPREVPREV value = 0 }
									}
								}
							}
						}
						NOR = {
							any_heir_title = { title = ROOT }
							trait = bastard
							trait = disinherited
							is_dumb_trigger = yes
							trait = inbred
							trait = incapable
							trait = lunatic
							trait = content
							trait = humble
						}
						OR = {
							AND = {
								is_female = no
								ROOT = {
									NOT = { has_law = enatic_succession }
									NOT = { has_law = enatic_cognatic_succession }
								}
							}
							AND = {
								is_female = yes
								ROOT = {
									NOT = { has_law = agnatic_succession }
									NOT = { has_law = cognatic_succession }
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			NOR = {
				#I am a child of the holder who can inherit
				holder_scope = {
					FROM = {
						OR = {
							NOT = { is_child_of = PREV }
							trait = bastard
							AND = {
								is_female = yes
								ROOT = {
									OR = {
										has_law = agnatic_succession
										has_law = cognatic_succession
									}
								}
							}
							AND = {
								is_female = no
								ROOT = {
									OR = {
										has_law = enatic_succession
										has_law = enatic_cognatic_succession
									}
								}
							}
						}
					}
				}
				#any non-heir eligible child of the holder is someone I would support
				holder_scope = {
					any_child = {
						OR = {
							dynasty = FROM
							is_married = FROM
							is_friend = FROM
							is_lover = FROM
						}
						NOR = {
							any_heir_title = { title = ROOT }
							trait = bastard
							trait = disinherited
							is_dumb_trigger = yes
							trait = inbred
							trait = incapable
							trait = lunatic
							trait = content
							trait = humble
						}
						reverse_opinion = { who = FROM value = 25 }
						OR = {
							AND = {
								is_female = no
								ROOT = {
									NOT = { has_law = enatic_succession }
									NOT = { has_law = enatic_cognatic_succession }
								}
							}
							AND = {
								is_female = yes
								ROOT = {
									NOT = { has_law = agnatic_succession }
									NOT = { has_law = cognatic_succession }
								}
							}
						}
					}
				}
			}
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			holder_scope = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					FROM = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			FROM = { 
				opinion = { who = LIEGE value = 0 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}			
			}
		}
		modifier = {
			factor = 0
			FROM = { 
				opinion = { who = LIEGE value = 20 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}			
			}
		}
		modifier = {
			factor = 0.1
			FROM = {
				opinion = { who = LIEGE value = 20 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}				
			}
		}
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = 40 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}				
			}
		}
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = 0 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1
		modifier = {
			factor = 1000
			has_character_flag = will_join_civil_war
			FROM = {
				has_character_flag = demands_gavelkind
				has_character_flag = civil_war_faction_leader
			}
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}
		modifier = {
			factor = 0
			preparing_invasion = yes
		}
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = { character = ROOT }
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = { is_married = ROOT }
			}
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			liege = {
				OR = {
					NOT = { culture = ROOT }
					NOT = { religion = ROOT }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					ROOT = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_ROOT_trigger = yes
						religion = ROOT
					}
				}
			}
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			OR = {
				AND = {
					NOT = { in_faction = faction_succ_gavelkind }
					opinion_diff = {
						first = LIEGE
						second = FROM
						value = 10 # I like my liege rather a lot more than the faction leader
						as_if_liege = yes
					}
				}
				AND = {
					in_faction = faction_succ_gavelkind
					opinion_diff = {
						first = LIEGE
						second = FROM
						value = 25
						as_if_liege = yes
					}
				}
			}
		}
		#holder does not have more than one eligible heir
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					NOT = {
						any_child = {
							OR = {
								AND = {
									is_female = no
									ROOT = {
										NOT = { has_law = enatic_succession }
										NOT = { has_law = enatic_cognatic_succession }
									}
								}
								AND = {
									is_female = yes
									ROOT = {
										NOT = { has_law = agnatic_succession }
										NOT = { has_law = cognatic_succession }
									}
								}
							}
							dynasty = PREV
							NOR = {
								trait = bastard
								trait = disinherited
								trait = slow
								trait = dull
								trait = imbecile
								trait = inbred
								trait = incapable
								trait = lunatic
							}
							count = 2
						}
					}
				}
			}
		}
		#do not switch from Feudal Elective/Elective Gavelkind
		modifier = {
			factor = 0
			FROMFROM = {
				OR = {
					has_law = succ_feudal_elective
					has_law = succ_elective_gavelkind
				}
			}
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 0 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}		
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 20 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}		
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 20 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}		
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			opinion = { who = LIEGE value = 40 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 0.01
			trait = content
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.01
			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
	}

	success = {
		has_law = succ_gavelkind
	}
	abort = {
		always = no		# Factions will abort if the Potential or Allow triggers are no longer valid
	}
	abort_effect = {
	}
	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_succ_gavelkind
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Institute Succession by Feudal Elective
faction_succ_feudal_elective = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_nomadic = no
		is_adult = yes
		primary_title = { holy_order = no }
		OR = {
			NOT = { has_dlc = "Zeus" }
			is_voter = no
			is_nomadic = yes
			is_tribal = yes
			liege = {
				OR = {
					is_council_content = no
					NOT = { primary_title = { has_law = war_voting_power_1 } }
				}
			}
		}
		liege = {
			is_feudal = yes
			is_vice_royalty = no
			NOR = {
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		NOR = {
			in_revolt = yes
			trait = incapable
			religion_group = muslim
			religion_group = indian_group
			religion = celtic_pagan
			in_faction = faction_succ_primogeniture
			in_faction = faction_succ_seniority
			in_faction = faction_succ_gavelkind
			in_faction = faction_separatist
		}
		
		OR = {
			# Is not affected by a Crown Law title
			NOT = { crownlaw_title = { always = yes } }
			# The Crown Law title holder is my liege
			crownlaw_title = { holder_scope = { is_liege_of = ROOT } }
			# king's peace has not been enforced
			AND = {
				will_liege_enforce_peace = no
				has_liege_enforced_peace = no
			}
		}
	}
	
	# Target scope (ROOT = liege title, FROM = faction leader)
	allow = {
		OR = {
			is_law_potential = succ_institute_feudal_elective
			is_law_potential = succ_elective_to_feudal_elective
		}
		OR = {
			is_primary_holder_title = yes
			higher_tier_than = DUKE
		}
		NOR = {
			has_law = crown_authority_1
			has_law = crown_authority_2
			has_law = crown_authority_3
			has_law = crown_authority_4
		}
		#the liege title is either de jure to my titles or is titular and primary title
		OR = {
			AND = {
				is_titular = no
				FROM = { any_demesne_title = { de_jure_liege_or_above = ROOT } }
			}
			is_primary_holder_title = yes
		}
		holder_scope = {
			NOT = {
				any_war = { war_title = ROOT }
			}
		}
		FROM = { primary_title = { is_primary_type_title = no } }
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			prisoner = no
			is_nomadic = no
			OR = {
				NOT = { has_dlc = "Zeus" }
				is_voter = no
				is_nomadic = yes
				liege = {
					OR = {
						is_council_content = no
						NOT = { primary_title = { has_law = war_voting_power_1 } }
					}
				}
			}
			OR = {
				NOT = { is_inaccessible_trigger = yes }
				has_character_flag = will_join_civil_war
			}
			is_adult = yes
			OR = {
				NOR = {
					in_faction = faction_succ_primogeniture
					in_faction = faction_succ_seniority
					in_faction = faction_succ_gavelkind
					in_faction = faction_separatist
				}
				has_character_flag = will_join_civil_war
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				religion_group = muslim
				religion_group = indian_group
				religion = celtic_pagan
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 1
		modifier = {
			factor = 0.5
			always = yes
		}
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { lower_tier_than = DUKE }
		}
		modifier = {
			factor = 0
			holder_scope = { lower_tier_than = KING }
		}
		modifier = {
			factor = 0
			holder_scope = { is_married = FROM }
		}
		modifier = {
			factor = 2
			has_title_flag = former_feudal_elective
		}
		modifier = {
			factor = 0
			NOR = {
				has_title_flag = former_feudal_elective
				FROM = {
					among_most_powerful_vassals = 5
					trait = ambitious
					OR = {
						culture_group = north_germanic
						culture_group = central_germanic
						culture_group = west_germanic
						culture = frankish
						culture = norman
						culture = roman
						culture = nubian
						culture = somali
					}
				}
				FROM = {
					among_most_powerful_vassals = 5
					trait = ambitious
					diplomacy = 12
				}
			}
		}
		#the liege title is either de jure to my titles or is titular and primary title
		modifier = {
			factor = 0
			NOR = {
				AND = {
					is_titular = no
					FROM = {
						any_demesne_title = {
							OR = {
								higher_tier_than = COUNT
								ROOT = { lower_tier_than = KING }
							}
							de_jure_liege_or_above = ROOT
						}
					}
				}
				is_primary_holder_title = yes
			}
		}
		# Not for the current heir
		modifier = {
			factor = 0
			current_heir = { character = FROM }
		}
		modifier = {
			factor = 0
			FROM = { primary_title = { is_primary_type_title = yes } }
		}
		# Not for spouse of current heir
		modifier = {
			factor = 0
			current_heir = {
				any_spouse = { character = FROM }
			}
		}
		# Not for close dynasty relatives of the present holder
		modifier = {
			factor = 0
			holder_scope = {
				FROM = {
					is_close_relative = PREV
					dynasty = PREV
				}
			}
		}
		# Not for dynasty members under some laws
		modifier = {
			factor = 0
			OR = {
				has_law = succ_seniority
				has_law = succ_tanistry
				has_law = succ_elective_gavelkind
			}
			holder_scope = { dynasty = FROM }
		}
		# If next in line under seniority, choose that plot insetead
		modifier = {
			factor = 0
			would_be_heir_under_law = { who = FROM law = seniority }
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			holder_scope = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					FROM = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
					}
				}
			}
		}		
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		modifier = {
			factor = 0.1
			FROM = { 
				opinion = { who = LIEGE value = 0 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
			}
		}		
		modifier = {
			factor = 0
			FROM = { 
				opinion = { who = LIEGE value = 20 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
			}
		}		
		modifier = {
			factor = 0.1
			FROM = {
				opinion = { who = LIEGE value = 20 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
			}
		}		
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = 40 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
			}
		}
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = 0 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		modifier = {
			factor = 4.0
			FROM = { is_pretender = yes }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.25
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.25
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
		modifier = {
			factor = 0.75
			calc_true_if = {
				amount = 2
				has_law = law_voting_power_1
				has_law = banish_voting_power_1
				has_law = execution_voting_power_1
				has_law = revoke_title_voting_power_1
				has_law = grant_title_voting_power_1
				has_law = imprison_voting_power_1
				has_law = war_voting_power_1
			}
		}
		modifier = {
			factor = 0.75
			calc_true_if = {
				amount = 4
				has_law = law_voting_power_1
				has_law = banish_voting_power_1
				has_law = execution_voting_power_1
				has_law = revoke_title_voting_power_1
				has_law = grant_title_voting_power_1
				has_law = imprison_voting_power_1
				has_law = war_voting_power_1
			}
		}
		modifier = {
			factor = 0.75
			calc_true_if = {
				amount = 6
				has_law = law_voting_power_1
				has_law = banish_voting_power_1
				has_law = execution_voting_power_1
				has_law = revoke_title_voting_power_1
				has_law = grant_title_voting_power_1
				has_law = imprison_voting_power_1
				has_law = war_voting_power_1
			}
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1
		modifier = {
			factor = 1000
			has_character_flag = will_join_civil_war
			FROM = {
				has_character_flag = demands_feudal_elective
				has_character_flag = civil_war_faction_leader
			}
		}
		modifier = {
			factor = 0.5
			always = yes
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}
		modifier = {
			factor = 0
			preparing_invasion = yes
		}
		modifier = {
			factor = 2
			FROMFROM = { has_title_flag = former_feudal_elective }
		}
		#the liege title is either de jure to my titles or is titular and primary title
		modifier = {
			factor = 0
			NOR = {
				AND = {
					FROMFROM = { is_titular = no }
					any_demesne_title = { de_jure_liege_or_above = FROMFROM }
				}
				FROMFROM = { is_primary_holder_title = yes }
			}
		}
		# Not for the current heir
		modifier = {
			factor = 0
			FROMFROM = { current_heir = { character = ROOT } }
		}
		# Not for spouse of current heir
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					any_spouse = { character = ROOT }
				}
			}
		}
		# Not for close dynasty relatives of the present holder
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				holder_scope = {
					ROOT = {
						is_close_relative = PREV
						dynasty = PREV
					}
				}
			}
		}
		# Not for dynasty members under some laws
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				OR = {
					has_law = succ_seniority
					has_law = succ_tanistry
					has_law = succ_elective_gavelkind
				}
				holder_scope = { dynasty = ROOT }
			}
		}
		# If next in line under seniority, choose that plot insetead
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				would_be_heir_under_law = { who = ROOT law = seniority }
			}
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			OR = {
				AND = {
					NOT = { in_faction = faction_succ_feudal_elective }
					opinion_diff = {
						first = LIEGE
						second = FROM
						value = 10 # I like my liege rather a lot more than the faction leader
						as_if_liege = yes
					}
				}
				AND = {
					in_faction = faction_succ_feudal_elective
					opinion_diff = {
						first = LIEGE
						second = FROM
						value = 25
						as_if_liege = yes
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			opinion = { who = LIEGE value = 0 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 20 } 
			NOT = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 0.1
			opinion = { who = LIEGE value = 20 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 40 } 
			OR = {
				trait = deceitful
				trait = ambitious
				trait = envious
			}
		}
		modifier = {
			factor = 2.0
			opinion = { who = FROM value = 0 }
			opinion_diff = {
				first = FROM
				second = LIEGE
				value = 25
				as_if_liege = yes
			}
		}
		modifier = {
			factor = 0.01
			trait = content
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.01
			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.01
			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.01
			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.25
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.25
			trait = humble
		}
		modifier = {
			factor = 0.5
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
		modifier = {
			factor = 0.75
			calc_true_if = {
				amount = 2
				has_law = law_voting_power_1
				has_law = banish_voting_power_1
				has_law = execution_voting_power_1
				has_law = revoke_title_voting_power_1
				has_law = grant_title_voting_power_1
				has_law = imprison_voting_power_1
				has_law = war_voting_power_1
			}
		}
		modifier = {
			factor = 0.75
			calc_true_if = {
				amount = 4
				has_law = law_voting_power_1
				has_law = banish_voting_power_1
				has_law = execution_voting_power_1
				has_law = revoke_title_voting_power_1
				has_law = grant_title_voting_power_1
				has_law = imprison_voting_power_1
				has_law = war_voting_power_1
			}
		}
		modifier = {
			factor = 0.75
			calc_true_if = {
				amount = 6
				has_law = law_voting_power_1
				has_law = banish_voting_power_1
				has_law = execution_voting_power_1
				has_law = revoke_title_voting_power_1
				has_law = grant_title_voting_power_1
				has_law = imprison_voting_power_1
				has_law = war_voting_power_1
			}
		}
	}

	success = {
		has_law = succ_feudal_elective
	}
	abort = {
		always = no		# Factions will abort if the Potential or Allow triggers are no longer valid
	}
	abort_effect = {
	}
	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_succ_feudal_elective
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Separatist faction, forms purely for the purpose of waging an independence war
faction_separatist = {
	type = character
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.

	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		is_patrician = no
		mercenary = no
		is_adult = yes
		primary_title = { holy_order = no }
		higher_tier_than = BARON
		NOR = {
			in_revolt = yes
			trait = incapable
			has_landed_title = k_orthodox
			has_character_modifier = faction_independence_ultimatum_timer 
		}
		OR = {
			ai = no
			is_feudal = yes
			is_tribal = yes
			is_nomadic = yes
			higher_tier_than = COUNT
		}
		faction_council_trigger = yes
		liege = {
			independent = yes
			NOR = {
				in_revolt = yes
				has_character_flag = faction_separatist_war
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				reverse_has_truce = ROOT
				any_demesne_title = { temporary = yes }
			}
			# Mongols and Aztecs do not have independence revolt problems before 1350
			OR = {
				year = 1350
				primary_title = { is_tribal = no }
				NOT = { culture = ROOT }
				NOT = { religion = ROOT }
				has_horde_culture = no
			}
			# Not allowed to start factions like this if our capital borders the liege's capital
			NOT = {
				capital_scope = {
					any_neighbor_province = {
						ROOT = {
							capital_scope = { province = PREVPREV }
						}
					}
				}
			}
		}
		
		OR = {
			is_nomadic = no
			NOT = { has_dlc = "Horse Lords" }
			liege = {
				NOT = { has_blood_oath_with = PREV }
			}
		}
		
		# No independence factions in merchant republics
		NOT = {
			AND = {
				is_merchant_republic = yes
				liege = {
					is_merchant_republic = yes
				}
			}
		}
	}
	
	# Target scope
	allow = {
		prisoner = no
		
		NOR = {
			has_opinion_modifier = {
				who = LIEGE
				modifier = opinion_coerced_into_leaving_faction
			}
			AND = {
				is_nomadic = yes
				clan_opinion = { who = LIEGE value = 0 }
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			is_patrician = no
			mercenary = no
			is_adult = yes
			prisoner = no
			faction_council_trigger = yes
			NOR = {
				in_revolt = yes
				liege = { reverse_has_truce = ROOT }
				trait = incapable
				is_inaccessible_trigger = yes
				has_landed_title = k_orthodox
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
				has_character_modifier = faction_independence_ultimatum_timer
			}
			OR = {
				is_nomadic = no
				NOT = {
					clan_opinion = { who = LIEGE value = 0 }
				}
			}
			
			# No independence factions in merchant republics
			NOT = {
				AND = {
					is_merchant_republic = yes
					liege = {
						is_merchant_republic = yes
					}
				}
			}
			
			# Can't join factions when in blood oath with liege
			OR = {
				is_nomadic = no
				NOT = { has_dlc = "Horse Lords" }
				liege = {
					NOT = { has_blood_oath_with = PREV }
				}
			}
		}
	}

	# AI creation weight (ROOT = faction creator, FROM = target)
	chance = {
		factor = 8
		modifier = {
			factor = 0
			war = yes
		}
		modifier = {
			factor = 0.1
			liege = { has_imperial_government_trigger = yes }
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}		
		modifier = {
			factor = 0
			preparing_invasion = yes
		}		
		modifier = {
			factor = 0
			is_patrician = yes
			is_merchant_republic = no
		}
		modifier = {
			factor = 0
			leads_faction = faction_religious
		}
		modifier = {
			factor = 0
			liege = {
				current_heir = { character = ROOT }
			}
		}
		modifier = {
			factor = 3.0
			religion_group = muslim
			capital_scope = { region = world_europe_west_iberia }
			liege = { has_law = taifa_law_0 }
		}
		modifier = {
			factor = 2.0
			religion_group = muslim
			capital_scope = { region = world_europe_west_iberia }
			liege = { has_law = taifa_law_1 }
		}
		modifier = {
			factor = 2.0
			is_pagan_religion = yes
			is_reformed_pagan_religion = no
		}
		modifier = {
			factor = 1.5
			primary_title = { is_vice_royalty = yes }
		}
		modifier = {
			factor = 2.0
			higher_real_tier_than = DUKE
		}
		modifier = {
			factor = 0.1
			NOT = { trait = deceitful }
			liege = {
				reverse_has_opinion_modifier = { who = ROOT modifier = sworn_to_support_heir }
			}
		}
		modifier = {
			factor = 0.75
			opinion = { who = LIEGE value = 0 }
		}
		modifier = {
			factor = 0.5
			opinion = { who = LIEGE value = 20 }
		}
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 40 }
		}
		modifier = {
			factor = 1.5
			NOT = { opinion = { who = LIEGE value = -20 } } 
		}
		modifier = {
			factor = 2.0
			NOT = { opinion = { who = LIEGE value = -50 } } 
		}
		modifier = {
			factor = 4.0
			NOT = { opinion = { who = LIEGE value = -75 } } 
		}
		# Lower if liege is a close relative or is allied
		modifier = {
			factor = 0.1
			liege = {
				OR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}
		# Lower if liege is the same dynasty but not close relative or allied
		modifier = {
			factor = 0.3
			liege = {
				dynasty = ROOT
				NOR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}
		# Not at all if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
		modifier = {
			factor = 0
			lower_tier_than = KING
			OR = {
				is_pagan_religion = no
				is_reformed_pagan_religion = yes
			}
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				de_jure_vassal_or_below = ROOT
				NOT = { over_vassal_limit = 1 }
				NOT = { has_law = taifa_law_0 }
				NOT = { has_law = taifa_law_1 }
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if king & if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
		modifier = {
			factor = 0.25
			tier = KING
			OR = {
				is_pagan_religion = no
				is_reformed_pagan_religion = yes
			}
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				de_jure_vassal_or_below = ROOT
				NOT = { over_vassal_limit = 1 }
				NOT = { has_law = taifa_law_0 }
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		modifier = {
			factor = 0.5
			lower_tier_than = KING
			liege = {
				de_jure_vassal_or_below = ROOT
				OR = {
					NOT = { religion = ROOT }
					NOT = { compare_cultures_ROOT_trigger = yes }
					over_vassal_limit = 1
				}
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if king & if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		modifier = {
			factor = 0.75
			tier = KING
			liege = {
				de_jure_vassal_or_below = ROOT
				OR = {
					NOT = { religion = ROOT }
					NOT = { compare_cultures_ROOT_trigger = yes }
					over_vassal_limit = 1
				}
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if liege is same religion & same culture & not over vassal limit -- but either not de jure or not connected to the capital
		modifier = {
			factor = 0.75
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				NOT = { over_vassal_limit = 1 }
			}
			OR = {
				liege = { NOT = { de_jure_vassal_or_below = ROOT } }
				capital_scope = { NOT = { has_province_flag = contingent_territory } }
			}
			OR = {
				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}
		# Higher if liege is both not de jure vassal and not connected
		modifier = {
			factor = 1.5
			liege = { NOT = { de_jure_vassal_or_below = ROOT } }
			capital_scope = { NOT = { has_province_flag = contingent_territory } }
		}
		# Higher if liege is not same religion and culture
		modifier = {
			factor = 2.0
			liege = {
				NOT = { religion = ROOT }
				NOT = { compare_cultures_ROOT_trigger = yes }
			}
		}
		# Higher if liege is not same religion group
		modifier = {
			factor = 2.0
			liege = {
				NOT = { religion_group = ROOT }
			}
		}
		# Higher if liege is not same culture group
		modifier = {
			factor = 2.0
			liege = {
				NOT = { compare_cultures_ROOT_trigger = yes }
			}
		}
		# Higher if liege is very over vassal limit
		modifier = {
			factor = 1.5
			liege = { over_vassal_limit = 5 }
		}
		modifier = {
			factor = 1.5
			liege = { over_vassal_limit = 10 }
		}
		# very reduced chance of joining if close to liege's capital (except for unreformed pagans)
		modifier = {
			factor = 0.1
			OR = {
				is_pagan_religion = no
				is_reformed_pagan_religion = yes
			}
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							NOT = {
								distance = { 
									where = PREVPREV
									value = 200
								}
							}
						}
					}
				}
			}
		}
		# chance of joining increases the further the liege's capital is away from the ruler's
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 300
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 400
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 500
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 600
							}
						}
					}
				}
			}
		}
		# Avoid joining faction if independence would put me beside a stronger neighbor eligible for holy war
		modifier = {
			factor = 0
			any_realm_province = {
				any_neighbor_province = {
					owner = {
						top_liege = {
							NOT = { same_realm = ROOT }
							higher_tier_than = ROOT
							OR = {
								NOT = { religion_group = ROOT }
								is_heresy_of = ROOT
								is_parent_religion = ROOT
								AND = {
									religion_group = muslim
									NOT = { religion = ROOT }
								}
							}
						}
					}
				}
			}
		}
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			lower_tier_than = KING
			liege = {
				OR = {
					NOT = { culture = ROOT }
					NOT = { religion = ROOT }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					ROOT = {
						primary_title = { de_jure_liege_or_above = PREVPREV }
					}
					any_claimant = {
						compare_cultures_ROOT_trigger = yes
						religion = ROOT
						dynasty = ROOT
					}
				}
			}
		}
		# Personality considerations
		modifier = {
			factor = 0.025
			trait = content
		}
		modifier = {
			factor = 0.025
			trait = imbecile
		}
		modifier = {
			factor = 0.025
			trait = craven
		}
		modifier = {
			factor = 0.1
			trait = inbred
		}
		modifier = {
			factor = 0.1
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
		#Make HRE a bit more stable
		modifier = {
			factor = 0.1
			liege = {
				has_landed_title = e_hre
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
					has_law = law_voting_power_1
				}
			}
		}
		modifier = { # More likely to want to go independent from the WP if China is unstable
			factor = 10.0
			liege = {
				government = confucian_bureaucracy
			}
			offmap_china = {
				NOR = {
					has_status = china_stable
					has_status = china_golden_age
				}
			}
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 10
		modifier = {
			factor = 0
			war = yes
		}
		modifier = {
			factor = 0.1
			liege = { has_imperial_government_trigger = yes }
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}		
		modifier = {
			factor = 0
			preparing_invasion = yes
		}		
		modifier = {
			factor = 0
			is_patrician = yes
			is_merchant_republic = no
		}
		# Clans are very unlikely to join Independence factions led by non-nomads
		modifier = {
			factor = 0.01
			is_nomadic = yes
			FROM = { is_nomadic = no }
		}
		modifier = {
			factor = 0
			OR = {
				in_faction = faction_religious
				leads_faction = faction_religious
			}
		}
		modifier = {
			factor = 0
			liege = {
				current_heir = { character = ROOT }
			}
		}
		modifier = {
			factor = 3.0
			religion_group = muslim
			capital_scope = { region = world_europe_west_iberia }
			liege = { has_law = taifa_law_0 }
		}
		modifier = {
			factor = 2.0
			religion_group = muslim
			capital_scope = { region = world_europe_west_iberia }
			liege = { has_law = taifa_law_1 }
		}
		modifier = {
			factor = 2.0
			is_pagan_religion = yes
			is_reformed_pagan_religion = no
		}
		modifier = {
			factor = 1.5
			primary_title = { is_vice_royalty = yes }
		}
		modifier = {
			factor = 2.0
			higher_real_tier_than = DUKE
		}
		modifier = {
			factor = 0.1
			NOT = { trait = deceitful }
			liege = {
				reverse_has_opinion_modifier = { who = ROOT modifier = sworn_to_support_heir }
			}
		}
		modifier = {
			factor = 0.75
			opinion = { who = LIEGE value = 0 }
		}
		modifier = {
			factor = 0.5
			opinion = { who = LIEGE value = 20 }
		}
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 40 }
		}
		modifier = {
			factor = 1.5
			NOT = { opinion = { who = LIEGE value = -20 } } 
		}
		modifier = {
			factor = 2.0
			NOT = { opinion = { who = LIEGE value = -50 } } 
		}
		modifier = {
			factor = 4.0
			NOT = { opinion = { who = LIEGE value = -75 } } 
		}
		# Lower if liege is a close relative or is allied
		modifier = {
			factor = 0.1
			liege = {
				OR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}
		# Lower if liege is the same dynasty but not close relative or allied
		modifier = {
			factor = 0.3
			liege = {
				dynasty = ROOT
				NOR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}
		# Not at all if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
		modifier = {
			factor = 0
			lower_tier_than = KING
			OR = {
				is_pagan_religion = no
				is_reformed_pagan_religion = yes
			}
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				de_jure_vassal_or_below = ROOT
				NOT = { over_vassal_limit = 1 }
				NOT = { has_law = taifa_law_0 }
				NOT = { has_law = taifa_law_1 }
			}
			capital_scope = { has_province_flag = contingent_territory }
			NAND = {
				religion_group = muslim
				capital_scope = { region = world_europe_west_iberia }
				NOT = { crownlaw_title = { has_law = crown_authority_3 } }
				NOT = { crownlaw_title = { has_law = crown_authority_4 } }
			}
		}
		# Lower if king & if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
		modifier = {
			factor = 0.25
			tier = KING
			OR = {
				is_pagan_religion = no
				is_reformed_pagan_religion = yes
			}
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				de_jure_vassal_or_below = ROOT
				NOT = { over_vassal_limit = 1 }
				NOT = { has_law = taifa_law_0 }
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		modifier = {
			factor = 0.25
			lower_tier_than = KING
			liege = {
				de_jure_vassal_or_below = ROOT
				OR = {
					NOT = { religion = ROOT }
					NOT = { compare_cultures_ROOT_trigger = yes }
					over_vassal_limit = 1
				}
				NOT = { has_law = taifa_law_0 }
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if king & if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		modifier = {
			factor = 0.5
			tier = KING
			liege = {
				de_jure_vassal_or_below = ROOT
				OR = {
					NOT = { religion = ROOT }
					NOT = { compare_cultures_ROOT_trigger = yes }
					over_vassal_limit = 1
				}
			}
			capital_scope = { has_province_flag = contingent_territory }
		}
		# Lower if liege is same religion & same culture & not over vassal limit -- but either not de jure or not connected to the capital
		modifier = {
			factor = 0.5
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				NOT = { over_vassal_limit = 1 }
			}
			OR = {
				liege = { NOT = { de_jure_vassal_or_below = ROOT } }
				capital_scope = { NOT = { has_province_flag = contingent_territory } }
			}
			OR = {
				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}
		# Lower if liege is same religion & same culture but over vassal limit -- but either not de jure or not connected to the capital
		modifier = {
			factor = 0.75
			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes	
				over_vassal_limit = 1
			}
			OR = {
				liege = { NOT = { de_jure_vassal_or_below = ROOT } }
				capital_scope = { NOT = { has_province_flag = contingent_territory } }
			}
			OR = {
				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}
		# Lower if liege is either different religion/culture (but not both) and not over vassal limit -- but either not de jure or not connected to the capital
		modifier = {
			factor = 0.75
			liege = {
				OR = {
					religion = ROOT
					compare_cultures_ROOT_trigger = yes
				}
				OR = {
					NOT = { religion = ROOT }
					NOT = { compare_cultures_ROOT_trigger = yes }
				}
				NOT = { over_vassal_limit = 1 }
			}
			OR = {
				liege = { NOT = { de_jure_vassal_or_below = ROOT } }
				capital_scope = { NOT = { has_province_flag = contingent_territory } }
			}
			OR = {
				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}
		# Higher if liege is both not de jure vassal and not connected
		modifier = {
			factor = 1.5
			liege = { NOT = { de_jure_vassal_or_below = ROOT } }
			capital_scope = { NOT = { has_province_flag = contingent_territory } }
		}
		# Higher if liege is both not same religion and culture
		modifier = {
			factor = 1.5
			liege = {
				NOT = { religion = ROOT }
				NOT = { compare_cultures_ROOT_trigger = yes }
			}
		}
		# Higher if liege is not same religion group
		modifier = {
			factor = 2.0
			liege = {
				NOT = { religion_group = ROOT }
			}
		}
		# Higher if liege is not same culture group
		modifier = {
			factor = 1.5
			liege = {
				NOT = { culture_group = ROOT }
			}
		}
		# Higher if liege is very over vassal limit
		modifier = {
			factor = 1.5
			liege = { over_vassal_limit = 5 }
		}
		modifier = {
			factor = 1.5
			liege = { over_vassal_limit = 10 }
		}
		# very reduced chance of joining if close to liege's capital (except for unreformed pagans)
		modifier = {
			factor = 0.1
			OR = {
				is_pagan_religion = no
				is_reformed_pagan_religion = yes
			}
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							NOT = {
								distance = { 
									where = PREVPREV
									value = 200
								}
							}
						}
					}
				}
			}
		}
		# chance of joining increases the further the liege's capital is away from the ruler's
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 300
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 400
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = { 
								where = PREVPREV
								value = 500
							}
						}
					}
				}
			}
		}
		# Avoid joining faction if independence would put me beside a stronger neighbor eligible for holy war
		modifier = {
			factor = 0
			any_realm_province = {
				any_neighbor_province = {
					owner = {
						top_liege = {
							NOT = { same_realm = ROOT }
							higher_tier_than = ROOT
							OR = {
								NOT = { religion_group = ROOT }
								is_heresy_of = ROOT
								is_parent_religion = ROOT
								AND = {
									religion_group = muslim
									NOT = { religion = ROOT }
								}
							}
						}
					}
				}
			}
		}

		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			lower_tier_than = KING
			liege = {
				OR = {
					NOT = { culture = ROOT }
					NOT = { religion = ROOT }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					ROOT = {
						primary_title = { de_jure_liege_or_above = PREVPREV }
					}
					any_claimant = {
						compare_cultures_ROOT_trigger = yes
						religion = ROOT
						dynasty = ROOT
					}
				}
			}
		}
		# Won't join this type of faction if our capital borders the liege's capital
		modifier = {
			factor = 0
			liege = {
				capital_scope = {
					any_neighbor_province = {
						ROOT = {
							capital_scope = {
								province = PREVPREV
							}
						}
					}
				}
			}
		}
		# Won't join this type of faction if Aztec/Mongol before 1350
		modifier = {
			factor = 0
			has_horde_culture = yes
			liege = { 
				NOT = { year = 1350 }
				primary_title = { is_tribal = yes }
				culture = ROOT
				religion = ROOT
			}
		}
		modifier = {
			factor = 0
			has_landed_title = k_orthodox
		}
		# Personality considerations
		modifier = {
			factor = 0.025
			trait = content
		}
		modifier = {
			factor = 0.025
			trait = imbecile
		}
		modifier = {
			factor = 0.025
			trait = craven
		}
		modifier = {
			factor = 0.1
			trait = inbred
		}
		modifier = {
			factor = 0.1
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
		#Make HRE a bit more stable
		modifier = {
			factor = 0.1
			liege = {
				has_landed_title = e_hre
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
					has_law = law_voting_power_1
				}
			}
		}
		modifier = { # More likely to want to go independent from the WP if China is unstable
			factor = 10.0
			liege = {
				government = confucian_bureaucracy
			}
			offmap_china = {
				NOR = {
					has_status = china_stable
					has_status = china_golden_age
				}
			}
		}
	}

	success = {
		independent = yes
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_separatist
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Faction supports claimant to the throne
faction_pretender = {
	type = liege_titles_w_claimant # 'new_character' is a Claimant, or, if the title is Elective, anyone eligible for election
	exclusive = yes # Can only lead or be in one faction of this type
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.

	# Plotter scope
	potential = {
		prisoner = no
		is_playable = yes
		is_landed = yes
		independent = no
		is_adult = yes
		primary_title = { holy_order = no }
		NOT = { trait = incapable }
		in_revolt = no
		higher_tier_than = BARON
		faction_council_trigger = yes
		liege = {
			is_vice_royalty = no
			OR = {
				is_feudal = yes
				is_tribal = yes
				is_nomadic = yes
			}
			OR = {
				# Hordes should have less problems with this type of faction until ca 1350
				year = 1350
				has_horde_culture = no
				NOT = { culture = ROOT }
				NOT = { religion = ROOT }
			}
			NOR = {
				in_revolt = yes
				reverse_has_truce = ROOT
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		OR = {
			# Is not affected by a Crown Law title
			NOT = { crownlaw_title = { always = yes } }
			# The Crown Law title holder is my liege
			crownlaw_title = { holder_scope = { is_liege_of = ROOT } }
			# king's peace has not been enforced
			AND = {
				will_liege_enforce_peace = no
				has_liege_enforced_peace = no
			}
		}
		OR = {
			liege = { is_nomadic = no }
			AND = {
				liege = {
					is_nomadic = yes
					NOT = { has_blood_oath_with = PREV }
				}
				is_nomadic = yes
				new_character = {
					character = PREV
				}
				has_dlc = "Horse Lords"
			}
		}
	}

	# Target scope
	allow = {
		# primary or king titles
		OR = {
			is_primary_holder_title = yes
			higher_tier_than = DUKE
		}
		# is either the primary title or my de jure liege
		OR = {
			is_primary_holder_title = yes
			de_jure_vassal_or_below = FROM
		}
		# claimant must be the same religion for religious head titles
		OR = {
			controls_religion = no
			new_character = { ROOT = { holder_scope = { religion = PREVPREV } } }
		}
		# no claimant factions to return duke/king titles to emperor within imperial realm
		OR = {
			holder_scope = { has_imperial_government_trigger = no }
			new_character = { lower_real_tier_than = EMPEROR }
			new_character = {
				ROOT = {
					holder_scope = {
						NOT = { same_realm = PREVPREV }
					}
				}
			}
			NOR = {
				tier = DUKE
				tier = KING
			}
		}
		new_character = {
			is_alive = yes
			prisoner = no
			NOR = {
				trait = incapable
				has_landed_title = PREV
				has_character_flag = refused_pretender_faction
			}
			#claimant is either landless or is feudal/tribal/nomadic
			OR = {
				is_ruler = no
				is_feudal = yes
				is_tribal = yes
				is_nomadic = yes
			}
			#claimant is male or not muslim
			OR = {
				is_female = no
				NOT = { religion_group = muslim }
			}
			#holder is not currently defending against that claimant for that title
			ROOT = {
				holder_scope = {
					NOR = {
						defending_against_claimant = {
							character = PREVPREV
							title = ROOT
						}
						reverse_has_truce = PREVPREV
					}
				}
			}
			#either holder is independent or claimant is in the same realm/not a ruler
			OR = {
				ROOT = { holder_scope = { independent = yes } }
				ROOT = { holder_scope = { same_realm = PREVPREV } }
				is_ruler = no
			}
			#has not failed as a pretender against the holder previously
			ROOT = {
				holder_scope = {
					NOT = { has_opinion_modifier = { who = PREVPREV modifier = failed_to_claim_my_title } }
				}
			}
		}
		#is either not elective or the claimant is a non-ruler/de jure vassal of the title
		OR = {
			NOT = { has_law = succ_feudal_elective }
			new_character = { is_ruler = no }
			new_character = {
				primary_title = {
					de_jure_liege_or_above = PREVPREV
				}
			}
		}
		NOT = {
			holder_scope = {
				reverse_has_opinion_modifier = { who = FROM modifier = opinion_coerced_into_leaving_faction }
			}
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			is_adult = yes
			prisoner = no
			faction_council_trigger = yes
			OR = {
				NOT = { is_inaccessible_trigger = yes }
				has_character_flag = will_join_civil_war
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
				liege = { reverse_has_truce = ROOT }
			}
			# Can't join factions when in blood oath with liege
			OR = {
				is_nomadic = no
				NOT = { has_dlc = "Horse Lords" }
				liege = {
					NOT = { has_blood_oath_with = PREV }
				}
			}
		}
	}

	# AI creation weight
	chance = {
		factor = 4
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}
		modifier = {
			factor = 0.8
			owner = {
				liege = {
					OR = {
						trait = crowned
						trait = weak_basileus
					}
				}
			}
		}
		modifier = {
			factor = 0.5
			owner = {
				liege = {
					trait = crowned_by_pope
				}
			}
		}
		modifier = {
			factor = 0.2
			owner = {
				liege = {
					trait = strong_basileus
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					controls_religion = yes
					rightful_religious_head_scope = { character = PREV }
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				NOT = { trait = cynical }
				rightful_religious_head_scope = {
					ai = yes
					has_landed_title = ROOT
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			holder_scope = {
				independent = no
				NOT = { same_realm = FROM }
			}
		}
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		modifier = {
			factor = 0.5
			NOT = { is_primary_holder_title = yes }
		}
		modifier = {
			factor = 3.0
			holder_scope = {
				OR = {
					prisoner = yes
					is_adult = no
					trait = incapable
					trait = uncrowned
				}
			}
		}
		modifier = {
			factor = 3
			new_character = { has_character_flag = justified_claimant }
		}
		modifier = {
			factor = 10
			new_character = { character = FROM }
		}
		modifier = {
			factor = 1.5
			new_character = {
				NOT = { character = FROM }
				dynasty = FROM
			}
		}
		modifier = {
			factor = 0
			new_character = { trait = decadent }
			FROM = { NOT = { trait = decadent } }
		}
		modifier = {
			factor = 1.5
			new_character = { is_close_relative = FROM }
		}
		modifier = {
			factor = 0.25
			new_character = { NOT = { culture = FROM } }
		}
		modifier = {
			factor = 0.25
			new_character = { NOT = { culture_group = FROM } }
		}
		modifier = {
			factor = 0
			new_character = { NOT = { religion = FROM } }
		}
		modifier = {
			factor = 0.1
			FROM = { NOT = { trait = deceitful } }
			holder_scope = {
				reverse_has_opinion_modifier = { who = FROM modifier = sworn_to_support_heir }
			}
		}
		# Will not support a claimant against someone you installed in the position
		modifier = {
			factor = 0
			holder_scope = {
				reverse_has_opinion_modifier = { who = FROM modifier = opinion_fought_for_claimant }
			}
		}
		# Will support a claimant of the same religion & culture against a liege who is either not of the same religion group or the same culture group
		modifier = {
			factor = 3.0
			holder_scope = {
				is_liege_of = FROM
				OR = {
					NOT = { culture_group = FROM }
					NOT = { religion_group = FROM }
				}
			}
			new_character = {
				culture = FROM
				religion = FROM
			}
		}
		# Less likely to support young children
		modifier = {
			factor = 0.5
			new_character = { NOT = { age = 13 } }
		}
		modifier = {
			factor = 0.5
			new_character = { NOT = { age = 10 } }
		}
		modifier = {
			factor = 0.5
			new_character = { NOT = { age = 5 } }
		}
		# More likely to support a male claimant against a female holding an agnatic title
		modifier = {
			factor = 3.0
			has_law = agnatic_succession
			holder_scope = { is_female = yes }
			new_character = { is_female = no }
			FROM = { is_feminist_trigger = no }
		}
		# More likely to support a female claimant against a male holding an enatic title
		modifier = {
			factor = 3.0
			has_law = enatic_succession
			holder_scope = { is_female = no }
			new_character = { is_female = yes }
		}
		# Will not support women for an agnatic title unless they have a son or are formidable
		modifier = {
			factor = 0
			has_law = agnatic_succession
			new_character = {
				is_female = yes
				NOR = {
					character = FROM
					any_child = {
						is_female = no
						OR = {
							dynasty = PREV
							dynasty = FROM
						}
						NOT = { trait = bastard }
					}
					calc_true_if = {
						amount = 2
						diplomacy = 12
						diplomacy = 20
						intrigue = 12
						prestige = 1000
						is_ruler = yes
					}
				}
			}
			FROM = { is_feminist_trigger = no }
		}
		# Unlikely to support women for an cognatic title unless they have a son or are formidable
		modifier = {
			factor = 0.5
			has_law = cognatic_succession
			new_character = {
				is_female = yes
				NOR = {
					character = FROM
					any_child = {
						is_female = no
						OR = {
							dynasty = PREV
							dynasty = FROM
						}
						NOT = { trait = bastard }
					}
					calc_true_if = {
						amount = 2
						diplomacy = 12
						diplomacy = 20
						intrigue = 12
						prestige = 1000
						is_ruler = yes
					}
				}
			}
			FROM = { is_feminist_trigger = no }
		}
		# Unlikely to support a woman in any case unless you are a woman
		modifier = {
			factor = 0.5
			NOR = {
				has_law = true_cognatic_succession
				has_law = enatic_cognatic_succession
				has_law = enatic_succession
			}
			new_character = { is_female = yes }
			FROM = {
				is_female = no
				is_feminist_trigger = no
			}
		}
		# Will not support a woman at all if zealous or in tradition faction
		modifier = {
			factor = 0
			NOR = {
				has_law = true_cognatic_succession
				has_law = enatic_cognatic_succession
				has_law = enatic_succession
			}
			new_character = { is_female = yes }
			FROM = {
				OR = {
					trait = zealous
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
				is_feminist_trigger = no
			}
		}
		# Will not support men for an enatic title unless they have a daughter or are formidable
		modifier = {
			factor = 0
			has_law = enatic_succession
			new_character = {
				is_female = no
				NOR = {
					character = FROM
					any_child = {
						is_female = yes
						OR = {
							dynasty = PREV
							dynasty = FROM
						}
						NOT = { trait = bastard }
					}
					calc_true_if = {
						amount = 2
						diplomacy = 12
						diplomacy = 20
						intrigue = 12
						prestige = 1000
						is_ruler = yes
					}
				}
			}
		}
		# Unlikely to support men for an enatic-cognatic title unless they have a daughter or are formidable
		modifier = {
			factor = 0.5
			has_law = enatic_cognatic_succession
			new_character = {
				is_female = no
				NOR = {
					character = FROM
					any_child = {
						is_female = yes
						OR = {
							dynasty = PREV
							dynasty = FROM
						}
						NOT = { trait = bastard }
					}
					calc_true_if = {
						amount = 2
						diplomacy = 12
						diplomacy = 20
						intrigue = 12
						prestige = 1000
						is_ruler = yes
					}
				}
			}
		}
		# Unlikely to support a man in any case unless you are a man
		modifier = {
			factor = 0.5
			NOR = {
				has_law = true_cognatic_succession
				has_law = cognatic_succession
				has_law = agnatic_succession
			}
			new_character = { is_female = no }
			FROM = { is_female = yes }
		}
		# Will not support claimants against their own spouse
		modifier = {
			factor = 0
			holder_scope = {
				any_spouse = { character = FROM }
			}
		}
		# Limits on who the AI will install in the title
		modifier = {
			factor = 0
			new_character = {
				OR = {
					is_rival = FROM
					trait = blinded
					trait = eunuch
					trait = imbecile
					trait = inbred
					trait = monk
					trait = nun
					trait = abdicated
					trait = druid
					trait = bad_druid
					trait = retired_vestalis
					trait = vestalis
					# Not over 65 or celibate unless they have a legitimate son
					AND = {
						OR = {
							age = 65
							trait = celibate
						}
						NOT = {
							any_child = {
								is_female = no
								NOT = { trait = bastard }
							}
						}
					}
					# Not old women, period
					AND = {
						is_female = yes
						age = 40
					}
				}
			}
		}
		# Will not install a parent of the current ruler
		modifier = {
			factor = 0
			new_character = {
				ROOT = {
					holder_scope = {
						is_child_of = PREVPREV
					}
				}
			}
		}
		# Will not install the current heir & will not install anyone if the heir, unless elective
		modifier = {
			factor = 0
			NOT = { has_law = succ_feudal_elective }
			current_heir = {
				OR = {
					character = FROM
					ROOT = { new_character = { character = PREVPREV } }
				}
			}
		}
		# Less likely to support a weak claimant when a strong claimant of the same religion, culture and dynasty exists in the realm
		modifier = {
			factor = 0.25
			new_character = { has_weak_claim = ROOT }
			FROM = {
				liege = {
					any_vassal = {
						leads_faction = faction_pretender
						supported_claimant = {
							religion = FROM
							culture = FROM
							dynasty = FROM
							has_strong_claim = ROOT
						}
					}
				}
			}
		}
		# There's already another claimant that I like
		modifier = {
			factor = 0.75
			new_character = { NOT = { character = FROM } }
			holder_scope = {
				any_vassal = {
					leads_faction = faction_pretender
					supported_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
						dynasty = FROM
						reverse_opinion = { who = FROM value = 20 }
						ROOT = {
							new_character = {
								NOT = { character = PREVPREV }
							}
						}
					}
				}
			}
		}
		# Will not support a claimant when they are a claimant of another pretender faction
		modifier = {
			factor = 0.25
			new_character = { NOT = { character = FROM } }
			FROM = {
				liege = {
					any_vassal = {
						leads_faction = faction_pretender
						supported_claimant = { character = FROM }
						supported_claimant_title = { title = ROOT }
					}
				}
			}
		}
		# Will not support a claimant to a title they also have a claim to
		modifier = {
			factor = 0
			new_character = { NOT = { character = FROM } }
			FROM = { has_claim = ROOT }
		}
		# Will not support a claimant of a different dynasty if holder is same dynasty, religion and culture
		modifier = {
			factor = 0
			holder_scope = {
				dynasty = FROM
				religion = FROM
				culture = FROM
			}
			new_character = {
				NOT = { dynasty = FROM }
			}
		}
		# Will not put himself forward for an elective title unless ambitious, proud, or a justified/strong claimant
		modifier = {
			factor = 0
			has_law = succ_feudal_elective
			new_character = {
				character = FROM
				NOR = {
					trait = ambitious
					trait = proud
					has_strong_claim = PREV
					has_character_flag = justified_claimant
				}
			}
		}
		# Will not support a claimant for a title that is currently contested by someone of a different religion/culture group
		modifier = {
			factor = 0
			NOT = { has_law = succ_feudal_elective }
			holder_scope = {
				culture_group = FROM
				religion = FROM
				any_war = {
					war_title = ROOT
					defender = { character = THIS } 
					attacker = {
						OR = {
							NOT = { culture_group = FROM }
							NOT = { religion = FROM }
						}
					}
				}
			}
		}
		# Will not support a claim for the primary title if there is an equal-tier title they are de jure vassal of
		modifier = {
			factor = 0
			NOT = { de_jure_vassal_or_below = FROM }
			holder_scope = {
				any_demesne_title = {
					is_primary_holder_title_tier = yes
					de_jure_vassal_or_below = FROM
					NOT = { title = ROOT }
				}
			}
		}
		# Will not support a claim for the title if the claimant already has a faction for a higher tier one
		modifier = {
			factor = 0
			FROM = {
				liege = {
					any_vassal = {
						leads_faction = faction_pretender
						supported_claimant = {
							ROOT = { new_character = { character = PREVPREV } }
						}
						supported_claimant_title = { higher_tier_than = ROOT }
					}
				}
			}
		}
		# If recently conquered, will not support a claimant of a different culture
		modifier = {
			factor = 0
			is_conquered = yes
			NOT = { new_character = { culture = FROM } }
		}
		# If recently conquered, more likely to support a claimant of the same culture
		modifier = {
			factor = 4.0
			is_conquered = yes
			NOT = { conquest_culture = FROM }
			new_character = { culture = FROM }
		}
		# If we are conquered, tend to unite behind one single claimant
		modifier = {
			factor = 0.1
			is_conquered = yes
			NOT = { conquest_culture = FROM }
			holder_scope = {
				any_vassal = {
					NOT = { character = FROM }
					in_faction = faction_pretender
					supported_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
						reverse_opinion = { who = FROM value = 25 }
						ROOT = {
							new_character = {
								NOT = { character = PREVPREV }
							}
						}
					}
				}
			}
		}
		# If there is an antiking faction, prioritize that
		modifier = {
			factor = 0
			holder_scope = { is_liege_of = FROM }
			FROM = {
				has_character_flag = opposes_the_antipope
				OR = {
					religion = catholic
					religion = fraticelli
				}
				liege = {
					religion = FROM
					rightful_religious_head_scope = {
						vassal_of = PREV
						OR = {
							has_claim = k_papal_state
							has_claim = d_fraticelli
						}
					}
					any_vassal = { leads_faction = faction_antiking }
				}
			}
		}
		# More likely to support claimants from less powerful dynasties
		modifier = {
			factor = 2.0
			holder_scope = { dynasty_realm_power = 0.25 }
			new_character = {
				ROOT = {
					holder_scope = { NOT = { dynasty = PREVPREV } }
				}
			}
		}
		modifier = {
			factor = 2.0
			holder_scope = { dynasty_realm_power = 0.4 }
			new_character = {
				ROOT = {
					holder_scope = { NOT = { dynasty = PREVPREV } }
				}
			}
		}
		# Less likely to support a claimant not born in the purple against a holder who is
		modifier = {
			factor = 0.5
			OR = {
				title = e_byzantium
				title = e_roman_empire
			}
			FROM = {
				OR = {
					culture_group = byzantine
					culture = roman
				}
			}
			holder_scope = { trait = born_in_the_purple }
			new_character = { NOT = { trait = born_in_the_purple } }
		}
		# More likely to support a claimant born in the purple against a holder who isn't
		modifier = {
			factor = 2.0
			OR = {
				title = e_byzantium
				title = e_roman_empire
			}
			FROM = {
				OR = {
					culture_group = byzantine
					culture = roman
				}
			}
			holder_scope = { NOT = { trait = born_in_the_purple } }
			new_character = { trait = born_in_the_purple }
		}
		# More likely to support sayyid against a holder who isn't
		modifier = {
			factor = 2.0
			FROM = { religion_group = muslim }
			new_character = { trait = sayyid }
			holder_scope = { NOT = { trait = sayyid } }
		}
		# More likely to support mirza against a holder who is neither sayyid nor mirza
		modifier = {
			factor = 1.5
			FROM = { religion_group = muslim }
			new_character = { trait = mirza }
			holder_scope = {
				NOR = {
					trait = sayyid
					trait = mirza
				}
			}
		}
		# Members of the tradition faction are less likely to support claimants unless the holder is excommunicated
		modifier = {
			factor = 2
			holder_scope = { trait = excommunicated }
			FROM = {
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
		}
		modifier = {
			factor = 0.25
			holder_scope = { NOT = { trait = excommunicated } }
			FROM = {
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
		}
		# Members of the court faction are more likely to support claimants
		modifier = {
			factor = 2.0
			FROM = {
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				liege = {
					OR = {
						has_character_flag = faction_court_angry
						has_character_flag = faction_court_unhappy
					}
				}
			}
		}
		# Opinions
		modifier = {
			factor = 0
			holder_scope = {
				culture = FROM
				religion = FROM
				FROM = {
					opinion = { who = PREV value = 0 }
					NOR = {
						trait = deceitful
						trait = ambitious
						trait = envious
						trait = proud
						trait = brave
					}
				}
			}
		}
		modifier = {
			factor = 0
			holder_scope = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
				FROM = {
					opinion = { who = PREV value = 25 }
					NOR = {
						trait = deceitful
						trait = ambitious
						trait = envious
						trait = proud
						trait = brave
					}
				}
			}
		}
		modifier = {
			factor = 0
			holder_scope = {
				culture = FROM
				religion = FROM
				FROM = {
					opinion = { who = PREV value = 25 }
					OR = {
						trait = deceitful
						trait = ambitious
						trait = envious
						trait = proud
						trait = brave
					}
				}
			}
		}
		modifier = {
			factor = 0
			holder_scope = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
				FROM = {
					opinion = { who = PREV value = 50 }
					OR = {
						trait = deceitful
						trait = ambitious
						trait = envious
						trait = proud
						trait = brave
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			holder_scope = {
				NOT = { reverse_opinion = { who = FROM value = -25 } }
			}
		}
		modifier = {
			factor = 2.0
			holder_scope = {
				NOT = { reverse_opinion = { who = FROM value = -50 } }
			}
		}
		modifier = {
			factor = 4.0
			holder_scope = {
				NOT = { reverse_opinion = { who = FROM value = -75 } }
			}
		}
		modifier = {
			factor = 0.5
			new_character = {
				NOT = { reverse_opinion = { who = FROM value = 20 } }
			}
		}
		modifier = {
			factor = 0
			new_character = {
				NOT = { reverse_opinion = { who = FROM value = 0 } }
			}
		}
		modifier = {
			# I must like the Claimant more than the current ruler
			factor = 0
			new_character = { NOT = { character = FROM } }
			NOT = {
				new_character = {
					FROM = {
						opinion_diff = {
							first = PREV
							second = LIEGE
							value = 10
							as_if_liege = yes
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			new_character = {
				NOT = { character = FROM }
				FROM = {
					opinion_diff = {
						first = PREV
						second = LIEGE
						value = 25
						as_if_liege = yes
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			new_character = {
				NOT = { character = FROM }
				FROM = {
					opinion_diff = {
						first = PREV
						second = LIEGE
						value = 50
						as_if_liege = yes
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			new_character = {
				NOT = { character = FROM }
				FROM = {
					opinion_diff = {
						first = PREV
						second = LIEGE
						value = 75
						as_if_liege = yes
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			new_character = {
				NOT = { character = FROM }
				FROM = {
					opinion_diff = {
						first = PREV
						second = LIEGE
						value = 100
						as_if_liege = yes
					}
				}
			}
		}
		modifier = {
			# The new claimant cannot like the holder
			factor = 0
			NOT = { new_character = { character = FROM } }
			holder_scope = {
				ROOT = {
					new_character = {
						opinion = { who = PREVPREV value = 25 }
						NOR = {
							trait = deceitful
							trait = ambitious
							trait = envious
							trait = proud
							trait = greedy
						}
					}
				}
			}
		}
		# Personal traits of the claimant
		modifier = {
			factor = 0
			new_character = {
				OR = {
					trait = lunatic
					trait = possessed
				}
			}
			FROM = {
				NOR = {
					trait = lunatic
					trait = possessed
				}
			}
			holder_scope = {
				NOR = {
					trait = lunatic
					trait = possessed
				}
			}
		}
		modifier = {
			factor = 1.5
			new_character = {
				is_smart_trigger = yes
			}
			holder_scope = {
				is_smart_trigger = no
			}
		}
		modifier = {
			factor = 0.5
			new_character = {
				OR = {
					trait = slow
					trait = dull
					trait = infirm
					trait = content
					NOT = { health = 4 }
				}
			}
		}
		modifier = {
			factor = 1.5
			new_character = { trait = zealous }
			FROM = { trait = zealous }
			holder_scope = { NOT = { trait = zealous } }
		}
		modifier = {
			factor = 0.5
			new_character = { trait = cynical }
			FROM = { trait = zealous }
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 2
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 4
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 6
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 8
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 10
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 2
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 4
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 6
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 8
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 10
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = stewardship
							value = 5
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = stewardship
							value = 5
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			holder_scope = {
				ROOT = {
					new_character = {
						attribute_diff = {
							character = PREVPREV
							attribute = intrigue
							value = 5
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			new_character = {
				ROOT = {
					holder_scope = {
						attribute_diff = {
							character = PREVPREV
							attribute = intrigue
							value = 5
						}
					}
				}
			}
		}
		# Personal traits
		modifier = {
			factor = 0.01
			FROM = { trait = content }
			OR = {
				is_conquered = no
				conquest_culture = FROM
			}
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			new_character = { character = FROM }
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.1
			new_character = { character = FROM }
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = slothful }
		}
		modifier = {
			factor = 0.5
			new_character = { NOT = { character = FROM } }
			FROM = { trait = humble }
		}
		modifier = {
			factor = 1.5
			new_character = { character = FROM }
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			new_character = { character = FROM }
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			new_character = { character = FROM }
			FROM = {
				OR = {
					trait = envious
					trait = greedy
					trait = deceitful
				}
			}
		}
		modifier = {
			factor = 2.0
			is_conquered = yes
			NOT = { conquest_culture = FROM }
			new_character = { culture = FROM }
			FROM = {
				OR = {
					trait = diligent
					trait = just
					trait = wroth
				}
			}
		}
		modifier = {
			factor = 3.0
			FROM = { trait = lunatic }
		}
		modifier = {
			factor = 4.0
			new_character = {
				OR = {
					character = FROM
					is_child_of = FROM
					is_married = FROM
				}
			}
			FROM = { trait = ambitious }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 4
		modifier = {
			factor = 100
			has_character_flag = will_join_civil_war
			FROM = {
				has_character_flag = preparing_claimant_faction_war
				has_character_flag = civil_war_faction_leader
			}
		}
		modifier = {
			factor = 0.2
			pacifist = yes
		}
		modifier = {
			factor = 0.8
			liege = {
				OR = {
					trait = crowned
					trait = weak_basileus
				}
			}
		}
		modifier = {
			factor = 0.5
			liege = {
				trait = crowned_by_pope
			}
		}
		modifier = {
			factor = 0.2
			liege = {
				trait = strong_basileus
			}
		}
		modifier = {
			factor = 0
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
		modifier = {
			factor = 0
			NOT = { trait = cynical }
			rightful_religious_head_scope = {
				ai = yes
				has_landed_title = FROMFROM
			}
		}
		modifier = {
			factor = 0
			preparing_invasion = yes
		}
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					independent = no
					NOT = { same_realm = ROOT }
				}
			}
		}
		modifier = {
			factor = 3.0
			FROMFROM = {
				holder_scope = {
					OR = {
						prisoner = yes
						is_adult = no
						trait = incapable
						trait = uncrowned
					}
				}
			}
		}
		modifier = {
			factor = 3.0
			FROM = {
				supported_claimant = { has_character_flag = justified_claimant }
			}
		}
		modifier = {
			factor = 10.0
			FROM = {
				supported_claimant = { character = ROOT }
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					dynasty = ROOT
				}
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = { is_close_relative = ROOT }
			}
		}
		modifier = {
			factor = 0.25
			FROM = {
				supported_claimant = { NOT = { culture = ROOT } }
			}
		}
		modifier = {
			factor = 0.25
			FROM = {
				supported_claimant = { NOT = { culture_group = ROOT } }
			}
		}
		modifier = {
			factor = 0
			FROM = {
				supported_claimant = { NOT = { religion = ROOT } }
			}
		}
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			NOT = { trait = decadent }
			FROM = {
				supported_claimant = { trait = decadent }
			}
		}
		modifier = {
			factor = 0.1
			NOT = { trait = deceitful }
			FROMFROM = {
				holder_scope = {
					reverse_has_opinion_modifier = { who = ROOT modifier = sworn_to_support_heir }
				}
			}
		}
		# Will not support a claimant against someone you installed in the position
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					reverse_has_opinion_modifier = { who = ROOT modifier = opinion_fought_for_claimant }
				}
			}
		}
		# Should not be supporting a different claimant unless it's yourself
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			OR = {
				leads_faction = faction_pretender
				in_faction = faction_pretender
			}
			supported_claimant = {
				FROM = {
					supported_claimant = {
						NOT = { character = ROOT }
						NOT = { character = PREVPREV }
					}
				}
			}
		}
		# Will support a claimant of the same religion & culture against a liege who is either not of the same religion group or the same culture group
		modifier = {
			factor = 10.0
			FROMFROM = {
				holder_scope = {
					is_liege_of = ROOT
					OR = {
						NOT = { culture_group = ROOT }
						NOT = { religion_group = ROOT }
					}
				}
			}
			FROM = {
				supported_claimant = {
					culture = ROOT
					religion = ROOT
				}
			}
		}
		# Less likely to support young children
		modifier = {
			factor = 0.5
			FROM = {
				supported_claimant = { NOT = { age = 13 } }
			}
		}
		modifier = {
			factor = 0.5
			FROM = {
				supported_claimant = { NOT = { age = 10 } }
			}
		}
		modifier = {
			factor = 0.5
			FROM = {
				supported_claimant = { NOT = { age = 5 } }
			}
		}
		# More likely to support a male claimant against a female holding an agnatic title
		modifier = {
			factor = 3.0
			FROMFROM = {
				has_law = agnatic_succession
				holder_scope = { is_female = yes }
			}
			FROM = {
				supported_claimant = { is_female = no }
			}
			is_feminist_trigger = no
		}
		# More likely to support a female claimant against a male holding an enatic title
		modifier = {
			factor = 3.0
			FROMFROM = {
				has_law = enatic_succession
				holder_scope = { is_female = no }
			}
			FROM = {
				supported_claimant = { is_female = yes }
			}
		}
		# Will not support women for an agnatic title unless they have a son or are formidable
		modifier = {
			factor = 0
			FROMFROM = {
				has_law = agnatic_succession
			}
			FROM = {
				supported_claimant = {
					is_female = yes
					NOR = {
						character = ROOT
						any_child = {
							is_female = no
							OR = {
								dynasty = PREV
								dynasty = ROOT
							}
							NOT = { trait = bastard }
						}
						calc_true_if = {
							amount = 2
							diplomacy = 12
							diplomacy = 20
							intrigue = 12
							prestige = 1000
						}
					}
				}
			}
			is_feminist_trigger = no
		}
		# Unlikely to support women for an cognatic title unless they have a son or are formidable
		modifier = {
			factor = 0.5
			FROMFROM = {
				has_law = cognatic_succession
			}
			FROM = {
				supported_claimant = {
					is_female = yes
					NOR = {
						character = ROOT
						any_child = {
							is_female = no
							OR = {
								dynasty = PREV
								dynasty = ROOT
							}
							NOT = { trait = bastard }
						}
						calc_true_if = {
							amount = 2
							diplomacy = 12
							diplomacy = 20
							intrigue = 12
							prestige = 1000
						}
					}
				}
			}
			is_feminist_trigger = no
		}
		# Unlikely to support a woman in any case unless you are a woman
		modifier = {
			factor = 0.5
			FROMFROM = {
				NOR = {
					has_law = true_cognatic_succession
					has_law = enatic_cognatic_succession
					has_law = enatic_succession
				}
			}
			FROM = {
				supported_claimant = { is_female = yes }
			}
			is_female = no
			is_feminist_trigger = no
		}
		# Will not support a woman at all if zealous or in tradition faction
		modifier = {
			factor = 0
			FROMFROM = {
				NOR = {
					has_law = true_cognatic_succession
					has_law = enatic_cognatic_succession
					has_law = enatic_succession
				}
			}
			FROM = {
				supported_claimant = { is_female = yes }
			}
			OR = {
				trait = zealous
				leads_faction = faction_tradition
				in_faction = faction_tradition
			}
			is_feminist_trigger = no
		}
		# Will not support men for an enatic title unless they have a daughter or are formidable
		modifier = {
			factor = 0
			FROMFROM = {
				has_law = enatic_succession
			}
			FROM = {
				supported_claimant = {
					is_female = no
					NOR = {
						character = ROOT
						any_child = {
							is_female = yes
							OR = {
								dynasty = PREV
								dynasty = ROOT
							}
							NOT = { trait = bastard }
						}
						calc_true_if = {
							amount = 2
							diplomacy = 12
							diplomacy = 20
							intrigue = 12
							prestige = 1000
						}
					}
				}
			}
		}
		# Unlikely to support men for an enatic-cognatic title unless they have a daughter or are formidable
		modifier = {
			factor = 0.5
			FROMFROM = {
				has_law = enatic_cognatic_succession
			}
			FROM = {
				supported_claimant = {
					is_female = no
					NOR = {
						character = ROOT
						any_child = {
							is_female = yes
							OR = {
								dynasty = PREV
								dynasty = ROOT
							}
							NOT = { trait = bastard }
						}
						calc_true_if = {
							amount = 2
							diplomacy = 12
							diplomacy = 20
							intrigue = 12
							prestige = 1000
						}
					}
				}
			}
		}
		# Unlikely to support a man in any case unless you are a man
		modifier = {
			factor = 0.5
			FROMFROM = {
				NOR = {
					has_law = true_cognatic_succession
					has_law = cognatic_succession
					has_law = agnatic_succession
				}
			}
			FROM = {
				supported_claimant = { is_female = no }
			}
			is_female = yes
		}
		# Will not support claimants against their own spouse
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					any_spouse = { character = ROOT }
				}
			}
		}
		# Limits on who the AI will install in the title
		modifier = {
			factor = 0
			FROM = {
				supported_claimant = {
					OR = {
						is_rival = ROOT
						trait = blinded
						trait = eunuch
						trait = imbecile
						trait = inbred
						trait = monk
						trait = nun
						trait = abdicated
						trait = druid
						trait = bad_druid
						trait = retired_vestalis
						trait = vestalis
						# Not over 65 or celibate unless they have a legitimate son
						AND = {
							OR = {
								age = 65
								trait = celibate
							}
							NOT = {
								any_child = {
									is_female = no
									NOT = { trait = bastard }
								}
							}
						}
						# Not old women, period
						AND = {
							is_female = yes
							age = 40
						}
					}
				}
			}
		}
		# Will not install anyone else if the current heir
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = { character = ROOT }
			}
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
				}
			}
		}
		# Less likely to support a weak claimant when a strong claimant of the same religion, culture and dynasty exists in the realm
		modifier = {
			factor = 0.25
			FROM = {
				supported_claimant = { has_weak_claim = FROMFROM }
			}
			liege = {
				any_vassal = {
					leads_faction = faction_pretender
					supported_claimant = {
						religion = ROOT
						culture = ROOT
						dynasty = ROOT
						has_strong_claim = FROMFROM
					}
				}
			}
		}
		# There's already another claimant that I like
		modifier = {
			factor = 0.75
			FROM = {
				supported_claimant = { NOT = { character = ROOT } }
			}
			FROMFROM = {
				holder_scope = {
					any_vassal = {
						leads_faction = faction_pretender
						supported_claimant = {
							culture = ROOT
							religion = ROOT
							dynasty = ROOT
							reverse_opinion = { who = FROM value = 20 }
							FROM = {
								supported_claimant = {
									NOT = { character = PREVPREV }
								}
							}
						}
					}
				}
			}
		}
		# Will not support a claimant when they are a claimant of another pretender faction
		modifier = {
			factor = 0
			FROM = {
				supported_claimant = { NOT = { character = ROOT } }
			}
			liege = {
				any_vassal = {
					leads_faction = faction_pretender
					supported_claimant = { character = ROOT }
					supported_claimant_title = { title = FROMFROM }
				}
			}
		}
		# Less likely to support a weak claimant for a title they also have a weak claim to unless it has good backing
		modifier = {
			factor = 0.1
			FROMFROM = {
				NOT = { has_law = succ_feudal_elective }
			}
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					has_weak_claim = FROMFROM
				}
				NOR = {
					faction_power = {
						faction = faction_pretender
						power = 0.3
					}
					any_faction_backer = {
						in_faction = faction_pretender
						count = 3
					}
				}
			}
			has_weak_claim = FROMFROM
		}
		# Still reluctant to support a weak claimant for a title they also have a weak claim to even when it has good backing
		modifier = {
			factor = 0.5
			FROMFROM = {
				NOT = { has_law = succ_feudal_elective }
			}
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					has_weak_claim = FROMFROM
				}
				OR = {
					faction_power = {
						faction = faction_pretender
						power = 0.3
					}
					any_faction_backer = {
						in_faction = faction_pretender
						count = 3
					}
				}
			}
			has_weak_claim = FROMFROM
		}
		# Will not support a claimant for a title they also have a strong claim to
		modifier = {
			factor = 0
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
				}
			}
			has_strong_claim = FROMFROM
		}
		# Less likely to support a strong claimant for a title they have a weak claim to unless it has good backing
		modifier = {
			factor = 0.25
			FROMFROM = {
				NOT = { has_law = succ_feudal_elective }
			}
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					has_strong_claim = FROMFROM
				}
				NOR = {
					faction_power = {
						faction = faction_pretender
						power = 0.3
					}
					any_faction_backer = {
						in_faction = faction_pretender
						count = 3
					}
				}
			}
			has_weak_claim = FROMFROM
		}
		# Still less likely to support a strong claimant for a title they have a weak claim even when it has good backing
		modifier = {
			factor = 0.75
			FROMFROM = {
				NOT = { has_law = succ_feudal_elective }
			}
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					has_strong_claim = FROMFROM
				}
				OR = {
					faction_power = {
						faction = faction_pretender
						power = 0.3
					}
					any_faction_backer = {
						in_faction = faction_pretender
						count = 3
					}
				}
			}
			has_weak_claim = FROMFROM
		}
		# Will not support a claimant of a different dynasty if holder is same dynasty, religion and culture
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					dynasty = ROOT
					religion = ROOT
					culture = ROOT
				}
			}
			FROM = {
				supported_claimant = {
					NOT = { dynasty = ROOT }
				}
			}
		}
		# Will not put himself forward for an elective title unless ambitious, proud, or a justified/strong claimant
		modifier = {
			factor = 0
			FROMFROM = {
				has_law = succ_feudal_elective
			}
			FROM = {
				supported_claimant = {
					character = ROOT
					NOR = {
						trait = ambitious
						trait = proud
						has_strong_claim = FROMFROM
						has_character_flag = justified_claimant
					}
				}
			}
		}
		# Will not support a claimant for a title that is currently contested by someone of a different religion/culture group
		modifier = {
			factor = 0
			FROMFROM = {
				NOT = { has_law = succ_feudal_elective }
				holder_scope = {
					culture_group = ROOT
					religion = ROOT
					any_war = {
						war_title = PREVPREV
						defender = { character = THIS } 
						attacker = {
							OR = {
								NOT = { culture_group = ROOT }
								NOT = { religion = ROOT }
							}
						}
					}
				}
			}
		}
		# Will not support a claim for the primary title if there is an equal-tier title they are de jure vassal of
		modifier = {
			factor = 0
			FROMFROM = {
				NOT = { de_jure_vassal_or_below = ROOT }
				holder_scope = {
					any_demesne_title = {
						is_primary_holder_title_tier = yes
						de_jure_vassal_or_below = ROOT
						NOT = { title = PREVPREV }
					}
				}
			}
		}
		# If recently conquered, will not support a claimant of a different culture
		modifier = {
			factor = 0
			FROMFROM = {
				is_conquered = yes
			}
			FROM = {
				supported_claimant = { NOT = { culture = ROOT } }
			}
		}
		# If recently conquered, more likely to support a claimant of the same culture
		modifier = {
			factor = 4.0
			FROMFROM = {
				is_conquered = yes
				NOT = { conquest_culture = ROOT }
			}
			FROM = {
				supported_claimant = { culture = ROOT }
			}
		}
		# If there is an antiking faction, prioritize that
		modifier = {
			factor = 0
			NOT = { has_character_flag = will_join_civil_war }
			FROMFROM = {
				holder_scope = { is_liege_of = ROOT }
			}
			has_character_flag = opposes_the_antipope
			OR = {
				religion = catholic
				religion = fraticelli
			}
			liege = {
				religion = ROOT
				rightful_religious_head_scope = {
					vassal_of = PREV
					OR = {
						has_claim = k_papal_state
						has_claim = d_fraticelli
					}
				}
				any_vassal = { leads_faction = faction_antiking }
			}
		}
		# More likely to support claimants from less powerful dynasties
		modifier = {
			factor = 2.0
			FROMFROM = {
				holder_scope = { dynasty_realm_power = 0.25 }
			}
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = { NOT = { dynasty = PREVPREV } }
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			FROMFROM = {
				holder_scope = { dynasty_realm_power = 0.4 }
			}
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = { NOT = { dynasty = PREVPREV } }
					}
				}
			}
		}
		# Less likely to support a claimant not born in the purple against a holder who is
		modifier = {
			factor = 0.5
			FROMFROM = {
				OR = {
					title = e_byzantium
					title = e_roman_empire
				}
				holder_scope = { trait = born_in_the_purple }
			}
			FROM = {
				supported_claimant = { NOT = { trait = born_in_the_purple } }
			}
			OR = {
				culture_group = byzantine
				culture = roman
			}
		}
		# More likely to support a claimant born in the purple against a holder who isn't
		modifier = {
			factor = 2.0
			FROMFROM = {
				OR = {
					title = e_byzantium
					title = e_roman_empire
				}
				holder_scope = { NOT = { trait = born_in_the_purple } }
			}
			FROM = {
				supported_claimant = { trait = born_in_the_purple }
			}
			OR = {
				culture_group = byzantine
				culture = roman
			}
		}
		# More likely to support sayyid against a holder who isn't
		modifier = {
			factor = 2.0
			religion_group = muslim
			FROMFROM = {
				holder_scope = { NOT = { trait = sayyid } }
			}
			FROM = {
				supported_claimant = { trait = sayyid }
			}
		}
		# More likely to support mirza against a holder who is neither sayyid nor mirza
		modifier = {
			factor = 1.5
			religion_group = muslim
			FROMFROM = {
				holder_scope = {
					NOR = {
						trait = sayyid
						trait = mirza
					}
				}
			}
			FROM = {
				supported_claimant = { trait = mirza }
			}
		}
		# Members of the tradition faction are less likely to support claimants unless the holder is excommunicated
		modifier = {
			factor = 2
			FROMFROM = {
				holder_scope = { trait = excommunicated }
			}
			OR = {
				leads_faction = faction_tradition
				in_faction = faction_tradition
			}
		}
		modifier = {
			factor = 0.5
			FROMFROM = {
				holder_scope = { NOT = { trait = excommunicated } }
			}
			OR = {
				leads_faction = faction_tradition
				in_faction = faction_tradition
			}
		}
		# Members of the court faction are more likely to support claimants
		modifier = {
			factor = 2.0
			OR = {
				leads_faction = faction_court
				in_faction = faction_court
			}
			liege = {
				OR = {
					has_character_flag = faction_court_angry
					has_character_flag = faction_court_unhappy
				}
			}
		}
		# Faction leader is a member of the same faction, which is angry
		modifier = {
			factor = 5.0
			OR = {
				AND = {
					in_faction = faction_court
					FROM = {
						OR = {
							leads_faction = faction_court
							any_faction_backer = {
								in_faction = faction_pretender
								leads_faction = faction_court
							}
						}
						liege = { has_character_flag = faction_court_angry }
					}
				}
				AND = {
					in_faction = faction_prosperity
					FROM = {
						OR = {
							leads_faction = faction_prosperity
							any_faction_backer = {
								in_faction = faction_pretender
								leads_faction = faction_prosperity
							}
						}
						liege = { has_character_flag = faction_prosperity_angry }
					}
				}
				AND = {
					in_faction = faction_glory
					FROM = {
						OR = {
							leads_faction = faction_glory
							any_faction_backer = {
								in_faction = faction_pretender
								leads_faction = faction_glory
							}
						}
						liege = { has_character_flag = faction_glory_angry }
					}
				}
				AND = {
					in_faction = faction_tradition
					FROM = {
						OR = {
							leads_faction = faction_tradition
							any_faction_backer = {
								in_faction = faction_pretender
								leads_faction = faction_tradition
							}
						}
						liege = { has_character_flag = faction_tradition_angry }
					}
				}
			}
		}
		# Opinions
		modifier = {
			factor = 100.0
			FROM = {
				supported_claimant = {
					reverse_has_opinion_modifier = { who = ROOT modifier = opinion_support_claimant }
				}
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					culture = ROOT
					religion = ROOT
					ROOT = {
						opinion = { who = PREV value = 0 }
						NOR = {
							trait = deceitful
							trait = ambitious
							trait = envious
							trait = proud
							trait = brave
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					OR = {
						NOT = { compare_cultures_ROOT_trigger = yes }
						NOT = { religion = ROOT }
					}
					ROOT = {
						opinion = { who = PREV value = 25 }
						NOR = {
							trait = deceitful
							trait = ambitious
							trait = envious
							trait = proud
							trait = brave
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				holder_scope = {
					culture = ROOT
					religion = ROOT
					ROOT = {
						opinion = { who = PREV value = 25 }
						OR = {
							trait = deceitful
							trait = ambitious
							trait = envious
							trait = proud
							trait = brave
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			FROMFROM = {
				holder_scope = {
					NOT = { reverse_opinion = { who = ROOT value = -25 } }
				}
			}
		}
		modifier = {
			factor = 2.0
			FROMFROM = {
				holder_scope = {
					NOT = { reverse_opinion = { who = ROOT value = -50 } }
				}
			}
		}
		modifier = {
			factor = 4.0
			FROMFROM = {
				holder_scope = {
					NOT = { reverse_opinion = { who = ROOT value = -75 } }
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = {
				supported_claimant = {
					NOT = { reverse_opinion = { who = ROOT value = 20 } }
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				supported_claimant = {
					NOT = { reverse_opinion = { who = ROOT value = 0 } }
				}
			}
		}
		modifier = {
			# I must like the Claimant more than the current ruler
			factor = 0
			FROM = {
				supported_claimant = { NOT = { character = ROOT } }
			}
			NOT = {
				FROM = {
					supported_claimant = {
						ROOT = {
							opinion_diff = {
								first = PREV
								second = LIEGE
								value = 10
								as_if_liege = yes
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					ROOT = {
						opinion_diff = {
							first = PREV
							second = LIEGE
							value = 25
							as_if_liege = yes
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					ROOT = {
						opinion_diff = {
							first = PREV
							second = LIEGE
							value = 50
							as_if_liege = yes
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					ROOT = {
						opinion_diff = {
							first = PREV
							second = LIEGE
							value = 75
							as_if_liege = yes
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					ROOT = {
						opinion_diff = {
							first = PREV
							second = LIEGE
							value = 100
							as_if_liege = yes
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.1
			opinion = { who = FROM value = 25 }
		}
		modifier = {
			factor = 1.1
			opinion = { who = FROM value = 50 }
		}
		modifier = {
			factor = 1.1
			opinion = { who = FROM value = 75 }
		}
		modifier = {
			factor = 0.9
			NOT = { opinion = { who = FROM value = -25 } }
		}
		modifier = {
			factor = 0.9
			NOT = { opinion = { who = FROM value = -50 } }
		}
		modifier = {
			factor = 0.9
			NOT = { opinion = { who = FROM value = -75 } }
		}
		# Personal traits of the claimant
		modifier = {
			factor = 0
			FROM = {
				supported_claimant = {
					OR = {
						trait = lunatic
						trait = possessed
					}
				}
			}
			FROMFROM = {
				holder_scope = {
					NOR = {
						trait = lunatic
						trait = possessed
					}
				}
			}
			NOR = {
				trait = lunatic
				trait = possessed
			}
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = {
					is_smart_trigger = yes
				}
			}
			FROMFROM = {
				holder_scope = {
					is_smart_trigger = no
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = {
				supported_claimant = {
					OR = {
						trait = slow
						trait = dull
						trait = infirm
						trait = content
						NOT = { health = 4 }
					}
				}
			}
		}
		modifier = {
			factor = 1.5
			trait = zealous
			FROM = {
				supported_claimant = { trait = zealous }
			}
			FROMFROM = {
				holder_scope = { NOT = { trait = zealous } }
			}
		}
		modifier = {
			factor = 0.5
			trait = cynical
			FROM = {
				supported_claimant = { trait = cynical }
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 2
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 4
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 6
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 8
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value = 10
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value = 2
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value = 4
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value = 6
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value = 8
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value = 10
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = stewardship
							value = 5
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = stewardship
								value = 5
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 1.2
			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = intrigue
							value = 5
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.8
			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = intrigue
								value = 5
							}
						}
					}
				}
			}
		}
		# Personal traits
		modifier = {
			factor = 0.01
			NOT = { has_character_flag = will_join_civil_war }
			trait = content
			FROMFROM = {
				OR = {
					is_conquered = no
					conquest_culture = FROM
				}
			}
		}
		modifier = {
			factor = 0.01
			NOT = { has_character_flag = will_join_civil_war }
			trait = imbecile
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			FROM = {
				supported_claimant = { character = ROOT }
			}
			trait = humble
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			FROM = {
				supported_claimant = { character = ROOT }
			}
			trait = content
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			trait = inbred
		}
		modifier = {
			factor = 0.1
			NOT = { has_character_flag = will_join_civil_war }
			trait = craven
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = slothful
		}
		modifier = {
			factor = 0.5
			FROM = {
				supported_claimant = { NOT = { character = ROOT } }
			}
			trait = humble
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = { character = ROOT }
			}
			trait = brave
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = { character = ROOT }
			}
			trait = proud
		}
		modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = { character = ROOT }
			}
			OR = {
				trait = envious
				trait = greedy
				trait = deceitful
			}
		}
		modifier = {
			factor = 2.0
			FROMFROM = {
				is_conquered = yes
				NOT = { conquest_culture = ROOT }
			}
			FROM = {
				supported_claimant = { culture = ROOT }
			}
			OR = {
				trait = diligent
				trait = just
				trait = wroth
			}
		}
		modifier = {
			factor = 3.0
			trait = lunatic
		}
		modifier = {
			factor = 4.0
			FROM = {
				supported_claimant = {
					OR = {
						character = ROOT
						is_child_of = ROOT
						is_married = ROOT
					}
				}
			}
			trait = ambitious
		}
	}
	
	success = {
		always = no
	}
	
	abort = {
		always = no		# Factions will abort if the Potential or Allow triggers are no longer valid
	}
	
	abort_effect = {
	}
	
	effect = {
	}
}

# Antiking Faction
faction_antiking = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	rel_head_loyalist = yes # Members consider the "real" pope to be the rightful religious head
	cancel_on_leader_death = yes # The faction will not automatically continue under a new leader
	
	# Plotter scope
	potential = {
		piety = 100
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_adult = yes
		primary_title = { holy_order = no }
		NOT = { trait = incapable }
		in_revolt = no
		OR = {
			religion = catholic
			religion = fraticelli
		}
		higher_real_tier_than = COUNT
		faction_council_trigger = yes
		liege = {
			religion = ROOT
			NOT = { government = nomadic_government }
			rightful_religious_head_scope = {
				vassal_of = PREV
				OR = {
					has_claim = k_papal_state
					has_claim = d_fraticelli
				}
			}
			NOR = {
				in_revolt = yes
				reverse_has_truce = ROOT
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
			}
		}
		has_character_flag = took_sides_antipope
		NOT = { has_character_modifier = faction_antiking_ultimatum_timer }
	}
	
	# Target scope
	allow = {
		higher_tier_than = DUKE
		is_primary_holder_title = yes
		holder_scope = {
			independent = yes
			NOT = {
				any_war = {
					war_title = ROOT
					using_cb = cb_install_antiking
				}
			}			
			NOR = {
				reverse_has_opinion_modifier = { who = FROM modifier = opinion_coerced_into_leaving_faction }
				reverse_has_truce = FROM
			}
		}
	}
	
	# If false, shows the faction entry for players, but disabled
	player_allow = {
		FROM = {
			piety = 100
			is_playable = yes
			is_landed = yes
			independent = no
			prisoner = no
			is_adult = yes
			NOT = { trait = incapable }
			OR = {
				religion = catholic
				religion = fraticelli
			}
			higher_real_tier_than = COUNT
			liege = {
				religion = ROOT
				rightful_religious_head_scope = {
					vassal_of = PREV
					OR = {
						has_claim = k_papal_state
						has_claim = d_fraticelli
					}
				}
			}
			has_character_flag = took_sides_antipope
			NOT = { has_character_modifier = faction_antiking_ultimatum_timer }
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			has_regent = no
			has_character_flag = took_sides_antipope
			faction_council_trigger = yes
			NOR = {
				in_revolt = yes
				trait = incapable
				is_inaccessible_trigger = yes
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}
	
	# AI creation weight - target scope
	chance = {
		factor = 1
		modifier = {
			factor = 0
			FROM = { has_character_flag = supports_the_antipope }
		}
		modifier = {
			factor = 5
			FROM = { has_character_flag = opposes_the_antipope }
		}
		modifier = {
			factor = 0.5
			FROM = {
				NOT = { has_character_flag = supports_the_antipope }
				NOT = { has_character_flag = opposes_the_antipope }
			}
		}
		modifier = {
			factor = 2
			FROM = {
				has_character_flag = opposes_the_antipope
				OR = {
					is_priest = yes
					is_theocracy = yes
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0
			FROM = { has_regent = yes }
		}
		modifier = {
			factor = 0
			holder_scope = {
				any_spouse = { character = FROM }
			}
		}
		modifier = {
			factor = 0
			holder_scope = {
				current_heir = { character = FROM }
			}
		}
		modifier = {
			factor = 5
			FROM = { liege = { is_rival = PREV } }
		}
		modifier = {
			factor = 0
			FROM = { opinion = { who = LIEGE value = 50 } }
		}
		modifier = {
			factor = 0.2
			FROM = { opinion = { who = LIEGE value = 5 } }
		}
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = -10 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		modifier = {
			factor = 0.5
			NOT = { claimed_by = FROM }
		}
		modifier = {
			factor = 0.5
			FROM = { NOT = { trait = zealous } }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = cynical }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = zealous }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
		modifier = {
			factor = 0
			FROM = {
				has_opinion_modifier = {
					who = LIEGE
					modifier = opinion_coerced_into_leaving_faction
				}
			}
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title
	membership = {
		factor = 1	
		modifier = {
			factor = 0
			OR = {
				has_regent = yes
				is_landed = no
				preparing_invasion = yes
				NOT = { religion = FROM }
			}
		}
		modifier = {
			factor = 0
			has_character_flag = supports_the_antipope
		}
		modifier = {
			factor = 5
			has_character_flag = opposes_the_antipope
		}
		modifier = {
			factor = 0.5
			NOT = { has_character_flag = supports_the_antipope }
			NOT = { has_character_flag = opposes_the_antipope }
		}
		modifier = {
			factor = 2
			has_character_flag = opposes_the_antipope
			OR = {
				is_priest = yes
				is_theocracy = yes
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = { character = ROOT }
			}
		}
		modifier = {
			factor = 0
			has_character_modifier = faction_antiking_ultimatum_timer
		}
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 50 }
		}
		modifier = {
			factor = 5
			liege = { is_rival = ROOT }
		}
		modifier = {
			factor = 0
			NOT = { opinion = { who = FROM value = -50 } }
		}
		modifier = {
			factor = 0
			has_opinion_modifier = {
				who = LIEGE
				modifier = opinion_coerced_into_leaving_faction
			}
		}
		modifier = {
			factor = 0.2
			opinion = { who = LIEGE value = 5 }
		}
		modifier = {
			factor = 1.5
			NOT = { opinion = { who = LIEGE value = -10 } }
		}
		modifier = {
			factor = 2.0
			NOT = { opinion = { who = LIEGE value = -50 } }
		}
		modifier = {
			factor = 4.0
			NOT = { opinion = { who = LIEGE value = -75 } }
		}
		modifier = {
			factor = 0.5
			NOT = { opinion = { who = FROM value = 0 } }
		}
		modifier = {
			factor = 1.5
			opinion = { who = FROM value = 25 }
		}
		modifier = {
			factor = 1.5
			opinion = { who = FROM value = 50 }
		}
		modifier = {
			factor = 1.5
			opinion = { who = FROM value = 75 }
		}
		modifier = {
			factor = 0.5
			liege = { dynasty = ROOT }
			NOT = { dynasty = FROM }
		}
		modifier = {
			factor = 2
			NOT = { liege = { dynasty = ROOT } }
			dynasty = FROM
		}
		modifier = {
			factor = 0.5
			NOT = { trait = zealous }
		}
		modifier = {
			factor = 0.01
			trait = content
		}
		modifier = {
			factor = 0.01
			trait = imbecile
		}
		modifier = {
			factor = 0.1
			trait = inbred
		}
		modifier = {
			factor = 0.1
			trait = craven
		}
		modifier = {
			factor = 0.1
			trait = cynical
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.5
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = kind
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = zealous
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
	}
	
	success = {
		always = no
	}
	
	abort = {
		always = no
	}
	
	abort_effect = {
	}
	
	effect = {
	}
}

# Religious Faction
faction_religious = {
	type = character
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		independent = no
		prisoner = no
		is_adult = yes
		primary_title = { holy_order = no }
		NOT = { trait = incapable }
		in_revolt = no
		OR = {
			higher_tier_than = COUNT
			liege = { lower_tier_than = KING }
		}
		faction_council_trigger = yes
		liege = {
			independent = yes
			OR = {
				is_parent_religion = ROOT
				is_heresy_of = ROOT
			}
			NOR = {
				character = ROOT
				religion = ROOT
				reverse_has_truce = ROOT
				any_demesne_title = { temporary = yes }
				has_character_flag = faction_religious_war
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
			}
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			independent = no
			is_adult = yes
			prisoner = no
			faction_council_trigger = yes
			OR = {
				NOT = { is_inaccessible_trigger = yes }
				has_character_flag = will_join_civil_war
			}
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
			liege = {
				OR = {
					is_parent_religion = ROOT
					is_heresy_of = ROOT
				}
			}
		}
	}
	
	# AI creation weight (ROOT = faction creator)
	chance = {
		factor = 50
		modifier = {
			factor = 0
			leads_faction = faction_separatist
		}
		modifier = {
			factor = 0
			trait = cynical
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 10
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
		modifier = {
			factor = 5
			trait = zealous
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 0.5
			trait = arbitrary
		}
		modifier = {
			factor = 0.5
			trait = slothful
		}
		modifier = {
			factor = 0.1
			trait = humble
		}
		modifier = {
			factor = 0.1
			trait = content
		}
		modifier = {
			factor = 0.1
			trait = craven
		}
		modifier = {
			factor = 0.1
			trait = imbecile
		}
		modifier = {
			factor = 0.1
			trait = inbred
		}
		modifier = {
			factor = 0
			pacifist = yes
		}
		modifier = {
			factor = 0
			opinion = { who = liege value = 0 }
		}
		modifier = {
			factor = 0.5
			opinion = { who = liege value = -25 }
		}
		modifier = {
			factor = 0
			liege = {
				current_heir = { character = ROOT }
			}
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 10
		modifier = {
			factor = 100
			has_character_flag = will_join_civil_war
			FROM = {
				has_character_flag = preparing_religious_faction_war
				has_character_flag = civil_war_faction_leader
			}
		}
		modifier = {
			factor = 0
			leads_faction = faction_separatist
		}
		modifier = {
			factor = 0
			NOT = { religion = FROM }
		}
		modifier = {
			factor = 0
			trait = cynical
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 10
			OR = {
				controls_religion = yes
				rightful_religious_head = ROOT
			}
		}
		modifier = {
			factor = 5
			trait = zealous
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 0.5
			trait = arbitrary
		}
		modifier = {
			factor = 0.5
			trait = slothful
		}
		modifier = {
			factor = 0.1
			trait = humble
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = content
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0.1
			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}
		modifier = {
			factor = 0
			pacifist = yes
		}
		modifier = {
			factor = 0
			opinion = { who = liege value = 0 }
		}
		modifier = {
			factor = 0.5
			opinion = { who = liege value = -25 }
		}
		modifier = {
			factor = 0
			liege = {
				current_heir = { character = ROOT }
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}

# Overthrow a weak Khan faction
faction_overthrow = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	cancel_on_leader_death = yes # The faction will not automatically continue under a new leader
	
	# Plotter scope
	potential = {
		prisoner = no
		is_ruler = yes
		independent = no
		is_landed = yes
		is_adult = yes
		primary_title = { holy_order = no }
		is_nomadic = yes
		NOT = { trait = incapable }
		faction_council_trigger = yes
		liege = {
			is_nomadic = yes
			NOT = { has_blood_oath_with = PREV }
			NOT = { has_non_aggression_pact_with = ROOT }
		}
	}
	
	# Target scope
	allow = {
		is_nomadic = yes
		is_primary_holder_title = yes

		holder_scope = {
			independent = yes
			
			NOT = {
				OR = {
					reverse_has_opinion_modifier = {
						who = FROM
						modifier = opinion_coerced_into_leaving_faction
					}
					blood_brother = {
						holder_scope = {
							character = FROM
						}
					}
				}
			}
		}
	}
	
	# If false, shows the faction entry for players, but disabled
	player_allow = {
		is_nomadic = yes
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_ruler = yes
			independent = no
			is_landed = yes
			is_adult = yes
			is_nomadic = yes
			NOT = { trait = incapable }
			prisoner = no
			faction_council_trigger = yes
			#NOT = {
			#	blood_brother = {
			#		holder_scope = {
			#			character = FROM
			#		}
			#	}
			#}
			# Can't join factions when in blood oath with liege
			OR = {
				is_nomadic = no
				NOT = { has_dlc = "Horse Lords" }
				liege = {
					NOT = { has_blood_oath_with = PREV }
				}
			}
			NOT = {
				liege = { has_non_aggression_pact_with = ROOT }
			}
		}
	}	
	
	# AI creation weight
	chance = {
		factor = 1
		
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}		
		
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		
		modifier = {
			factor = 0
			holder_scope = {
				any_spouse = { character = FROM }
			}
		}
		
		modifier = {
			factor = 0
			current_heir = {
				character = FROM
			}
		}
		
		modifier = {
			factor = 0
			FROM = { 
				opinion = { who = LIEGE value = 50 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
				liege = {
					NOT = { is_weak_trigger = yes }
					health = 4
				}
			}
		}		
		
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = 75 } 
				OR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
				liege = {
					NOT = { is_weak_trigger = yes }
					health = 4
				}		
			}
		}
		
		modifier = {
			factor = 1.5
			NOT = { 
				holder_scope = { 
					clan_title = {
						FROM = { 
							clan_title = {
								clan_opinion = { who = PREVPREV value = -10 }
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			NOT = { 
				holder_scope = { 
					clan_title = {
						FROM = { 
							clan_title = {
								clan_opinion = { who = PREVPREV value = -50 }
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 4.0
			NOT = { 
				holder_scope = { 
					clan_title = {
						FROM = { 
							clan_title = {
								clan_opinion = { who = PREVPREV value = -75 }
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.25
			holder_scope = { 
				clan_title = {
					FROM = { 
						clan_title = {
							clan_opinion = { who = PREVPREV value = 10 }
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.05
			holder_scope = { 
				clan_title = {
					FROM = { 
						clan_title = {
							clan_opinion = { who = PREVPREV value = 50 }
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.01
			holder_scope = { 
				clan_title = {
					FROM = { 
						clan_title = {
							clan_opinion = { who = PREVPREV value = 75 }
						}
					}
				}
			}
		}

		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = -10 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}

		modifier = {
			factor = 0.25
			FROM = { opinion = { who = LIEGE value = 10 } }
		}
		modifier = {
			factor = 0.05
			FROM = { opinion = { who = LIEGE value = 50 } }
		}
		modifier = {
			factor = 0.01
			FROM = { opinion = { who = LIEGE value = 75 } }
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = content
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = imbecile
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = inbred
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					OR = {
						trait = slow
						trait = dull
					}
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = kind
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = humble
				}
			}
		}

		modifier = {
			factor = 2
			FROM = {
				liege = {
					trait = craven
				}
			}
		}

		modifier = {
			factor = 3
			FROM = {
				liege = {
					is_weak_trigger = yes
				}
			}
		}

		modifier = {
			factor = 0.01
			FROM = {
				liege = {
					is_strong_trigger = yes
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					NOT = { health = 5 }
				}
			}
		}

		modifier = {
			factor = 2
			FROM = {
				liege = {
					NOT = { health = 3 }
				}
			}
		}
		
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1
		
		modifier = {
			factor = 0.2
			pacifist = yes
		}	
		
		modifier = {
			factor = 0
			OR = {
				prisoner = yes
				trait = incapable
				is_adult = no
				is_landed = no
				preparing_invasion = yes
			}
		}
		
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					character = ROOT
				}
			}
		}
		
		modifier = {
			factor = 0
			NOT = { opinion = { who = FROM value = -40 } }
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0
			has_opinion_modifier = {
				who = LIEGE
				modifier = opinion_coerced_into_leaving_faction
			}
		}
		
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 50 }
			liege = {
				NOT = { is_weak_trigger = yes }
				health = 4
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0.2
			pacifist = yes
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = content
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = imbecile
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = inbred
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					OR = {
						trait = slow
						trait = dull
					}
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = kind
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					trait = humble
				}
			}
		}

		modifier = {
			factor = 2
			FROM = {
				liege = {
					trait = craven
				}
			}
		}

		modifier = {
			factor = 3
			FROM = {
				liege = {
					is_weak_trigger = yes
				}
			}
		}

		modifier = {
			factor = 0.01
			FROM = {
				liege = {
					is_strong_trigger = yes
				}
			}
		}

		modifier = {
			factor = 1.5
			FROM = {
				liege = {
					NOT = { health = 5 }
				}
			}
		}

		modifier = {
			factor = 2
			FROM = {
				liege = {
					NOT = { health = 3 }
				}
			}
		}

		modifier = {
			factor = 1.5
			NOT = { 
				liege = { 
					clan_title = {
						ROOT = { 
							clan_title = {
								clan_opinion = { who = PREVPREV value = -10 }
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 2.0
			NOT = { 
				liege = { 
					clan_title = {
						ROOT = { 
							clan_title = {
								clan_opinion = { who = PREVPREV value = -50 }
							}
						}
					}
				}
			}
		}
		modifier = {
			factor = 4.0
			NOT = { 
				liege = { 
					clan_title = {
						ROOT = { 
							clan_title = {
								clan_opinion = { who = PREVPREV value = -75 }
							}
						}
					}
				}
			}
		}

		modifier = {
			factor = 0.5
			liege = { 
				clan_title = {
					ROOT = { 
						clan_title = {
							clan_opinion = { who = PREVPREV value = 10 }
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.1
			liege = { 
				clan_title = {
					ROOT = { 
						clan_title = {
							clan_opinion = { who = PREVPREV value = 50 }
						}
					}
				}
			}
		}
		modifier = {
			factor = 0.05
			liege = { 
				clan_title = {
					ROOT = { 
						clan_title = {
							clan_opinion = { who = PREVPREV value = 75 }
						}
					}
				}
			}
		}
		
		modifier = {
			factor = 1000
			has_opinion_modifier = {
				who = FROM
				modifier = opinion_coerced_into_joining_faction
			}
		}
		
		modifier = {
			factor = 1.5
			NOT = { opinion = { who = LIEGE value = -10 } }
		}
		modifier = {
			factor = 2.0
			NOT = { opinion = { who = LIEGE value = -50 } }
		}
		modifier = {
			factor = 4.0
			NOT = { opinion = { who = LIEGE value = -75 } }
		}
		modifier = {
			factor = 0.25
			opinion = { who = LIEGE value = 10 }
		}
		modifier = {
			factor = 0.05
			opinion = { who = LIEGE value = 50 }
		}
		modifier = {
			factor = 0.01
			opinion = { who = LIEGE value = 75 }
		}
		
		modifier = {
			factor = 0.01
			trait = content
		}
		modifier = {
			factor = 0.01
			trait = imbecile
		}
		modifier = {
			factor = 0.1
			trait = inbred
		}
		modifier = {
			factor = 0.1
			trait = craven
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
	}
	
	success = {
		always = no
	}
	
	abort = {
		always = no
	}
	
	abort_effect = {
	}
	
	effect = {
	}
}

# Increase Council Power
faction_increase_council_power = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		has_dlc = "Zeus"
		prisoner = no
		is_ruler = yes
		independent = no
		is_landed = yes
		is_adult = yes
		primary_title = { holy_order = no }
		faction_council_trigger = yes
		NOT = { trait = incapable }
		liege = { 
			is_nomadic = no
			OR = {
				year = 1350
				primary_title = { is_tribal_type_title = no }
				NOT = { culture = ROOT }
				NOT = { religion = ROOT }
			}
			NOR = {
				in_revolt = yes
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				any_demesne_title = { temporary = yes }
			}
		}
		primary_title = { higher_tier_than = BARON }
		
		NOT = { has_character_modifier = faction_council_power_ultimatum_timer }
	}
	
	# Target scope
	allow = {
		higher_tier_than = COUNT
		is_primary_holder_title = yes
		holder_scope = {
			primary_title = {
				ROOT = {
					tier = PREV
				}
			}

			NOT = {
				any_vassal = {
					higher_tier_than = BARON
					NOT = {	character = FROM }
					num_of_faction_backers = {
						faction = faction_increase_council_power
						value = 0
					}
				}
			}
		}
		
		holder_scope = {
			primary_title = {
				OR = {
					has_law = law_voting_power_0
					has_law = banish_voting_power_0
					has_law = execution_voting_power_0
					has_law = revoke_title_voting_power_0
					has_law = grant_title_voting_power_0
					has_law = imprison_voting_power_0
					has_law = war_voting_power_0
				}
			}
			NOT = {
				any_war = {
					war_title = ROOT
					using_cb = increase_council_power_war
				}
			}
			
			NOT = {
				reverse_has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_leaving_faction
				}
			}
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_ruler = yes
			independent = no
			is_landed = yes
			is_adult = yes
			prisoner = no
			NOT = { has_character_modifier = faction_council_power_ultimatum_timer }
			faction_council_trigger = yes
			NOR = {
				in_revolt = yes
				trait = incapable
				liege = { has_non_aggression_pact_with = ROOT }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated } }
				liege = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel } }
			}
		}
	}		
	
	# AI creation weight
	chance = {
		factor = 1
		modifier = {
			factor = 0
			FROM = {
				NOR = {
					is_voter = yes
					liege = {
						any_voter = {
							OR = {
								is_friend = PREVPREV
								is_child_of = PREVPREV
								is_mother = PREVPREV
								is_father = PREVPREV
								sibling = PREVPREV
								is_married = PREVPREV
								is_lover = PREVPREV
							}
						}
					}
				}
			}
		}
		
		modifier = {
			factor = 0.8
			has_law = law_voting_power_1
		}
		modifier = {
			factor = 0.8
			has_law = war_voting_power_1
		}
		modifier = {
			factor = 0.8
			has_law = revoke_title_voting_power_1
		}
		modifier = {
			factor = 0.8
			has_law = imprison_voting_power_1
		}
		modifier = {
			factor = 0.8
			has_law = grant_title_voting_power_1
		}
		modifier = {
			factor = 0.8
			has_law = banish_voting_power_1
		}
		modifier = {
			factor = 0.8
			has_law = execution_voting_power_1
		}
		
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}		
		
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		
		modifier = {
			factor = 0
			holder_scope = {
				any_spouse = { character = FROM }
			}
		}
		
		modifier = {
			factor = 0
			current_heir = {
				character = FROM
			}
		}
		
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			holder_scope = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					FROM = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
					}
				}
			}
		}
		
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		
		modifier = {
			factor = 0.5
			FROM = { 
				opinion = { who = LIEGE value = 0 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
			}
		}
		
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = 25 } 			
			}
		}
		
		modifier = {
			factor = 0.5
			FROM = { is_voter = no }
		}

		modifier = {
			factor = 5
			FROM = {
				is_voter = yes
				has_position = malcontent
			}
		}

		modifier = {
			factor = 2
			FROM = {
				is_voter = yes
				NOR = {
					has_position = loyalist
					has_position = malcontent
				}
			}
		}
		
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = -25 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1			
		
		modifier = {
			factor = 0
			OR = {
				prisoner = yes
				trait = incapable
				is_adult = no
				is_landed = no
				preparing_invasion = yes
			}
		}
		
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					character = ROOT
				}
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0
			has_character_modifier = faction_council_power_ultimatum_timer
		}
		
		modifier = {
			factor = 0
			NOT = { opinion = { who = FROM value = -25 } }
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = law_voting_power_1 }
		}
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = war_voting_power_1 }
		}
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = revoke_title_voting_power_1 }
		}
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = imprison_voting_power_1 }
		}
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = grant_title_voting_power_1 }
		}
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = banish_voting_power_1 }
		}
		modifier = {
			factor = 0.8
			FROMFROM = { has_law = execution_voting_power_1 }
		}
		
		modifier = {
			factor = 0
			liege = { 
				NOT = { year = 1350 }
				primary_title = { is_tribal_type_title = yes }
				culture = ROOT
				religion = ROOT
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0
			has_opinion_modifier = {
				who = LIEGE
				modifier = opinion_coerced_into_leaving_faction
			}
		}
		
		modifier = {
			factor = 0.5
			opinion = { who = LIEGE value = 0 }
		}
		
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 25 }
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0.2
			pacifist = yes
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}

		modifier = {
			factor = 5
			FROM = {
				is_voter = yes
				has_position = malcontent
			}
		}

		modifier = {
			factor = 2
			FROM = {
				is_voter = yes
				NOT = { has_position = loyalist }
				NOT = { has_position = malcontent }
			}
		}
		
		modifier = {
			factor = 1000
			has_opinion_modifier = {
				who = FROM
				modifier = opinion_coerced_into_joining_faction
			}
		}
		
		modifier = {
			factor = 1.5
			NOT = { opinion = { who = LIEGE value = -25 } }
		}
		modifier = {
			factor = 2.0
			NOT = { opinion = { who = LIEGE value = -50 } }
		}
		modifier = {
			factor = 4.0
			NOT = { opinion = { who = LIEGE value = -75 } }
		}
		
		modifier = {
			factor = 0.01
			trait = content
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.01
			trait = imbecile
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.1
			trait = inbred
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.1
			trait = craven
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
	}
	
	success = {
		holder_scope = {
			FROM = {
				has_opinion_modifier = { who = PREV modifier = opinion_increased_council_power }
			}
		}
	}
	
	abort = {
	}
	
	abort_effect = {
	}
	
	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_increase_council_power
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Powerful vassals overthrow their liege
faction_powerful_vassal_takeover = {
	type = liege_titles
	
	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.
	
	# Plotter scope
	potential = {
		has_dlc = "Zeus"
		always = no
		prisoner = no
		is_ruler = yes
		independent = no
		is_landed = yes
		is_adult = yes
		primary_title = { holy_order = no }
		is_feudal = yes
		OR = {
			is_voter = no
			liege = { 
				NOT = { controls_religion = yes }
				OR = {
					is_council_content = no
					NOT = { primary_title = { has_law = war_voting_power_1 } }
					#has_council = no
				}
			}
		}
		NOT = { trait = incapable }
		liege = {
			is_feudal = yes
			NOR = {
				government = chinese_imperial_government
				controls_religion = yes
				any_demesne_title = {
					temporary = yes
				}
				has_non_aggression_pact_with = ROOT
			}
		}
		primary_title = { higher_tier_than = BARON }
		
		NOT = { has_character_modifier = faction_powerful_vassal_takeover_ultimatum_timer }
	}
	
	# Target scope
	allow = {
		always = no
		higher_tier_than = DUKE
		is_primary_holder_title = yes
		holder_scope = {
			primary_title = {
				ROOT = {
					tier = PREV
				}
			}

			NOT = {
				any_vassal = {
					higher_tier_than = COUNT
					NOT = {	character = FROM }
					num_of_faction_backers = {
						faction = faction_powerful_vassal_takeover
						value = 0
					}
				}
			}
		}
		
		holder_scope = {
			NOT = {
				any_war = {
					war_title = ROOT
					using_cb = powerful_vassal_takeover_war
				}
			}
			
			NOR = {
				reverse_has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_leaving_faction
				}
				reverse_has_opinion_modifier = {
					who = FROM
					modifier = opinion_replaced_bad_ruler
				}
			}
		}
	}
	
	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_ruler = yes
			independent = no
			is_landed = yes
			is_adult = yes
			NOT = { trait = incapable }
			prisoner = no
			NOT = { has_character_modifier = faction_powerful_vassal_takeover_ultimatum_timer }
			OR = {
				is_voter = no
				liege = { 
					OR = {
						is_council_content = no
						NOT = { primary_title = { has_law = war_voting_power_1 } }
						#has_council = no
					}
				}
			}
			NOT = {
				liege = { has_non_aggression_pact_with = ROOT }
			}
		}
	}		
	
	# AI creation weight
	chance = {
		factor = 1
		
		modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}		
		
		modifier = {
			factor = 0
			FROM = {
				OR = {
					prisoner = yes
					has_character_modifier = in_seclusion
				}
			}
		}
		modifier = {
			factor = 0.8
			owner = {
				liege = {
					OR = {
						trait = crowned
						trait = weak_basileus
					}
				}
			}
		}
		modifier = {
			factor = 0.5
			owner = {
				liege = {
					trait = crowned_by_pope
				}
			}
		}
		modifier = {
			factor = 0.2
			owner = {
				liege = {
					trait = strong_basileus
				}
			}
		}
		modifier = {
			factor = 0
			holder_scope = {
				any_spouse = { character = FROM }
			}
		}
		
		modifier = {
			factor = 0
			current_heir = {
				character = FROM
			}
		}
		
		# Try to exclude people who should rather support a claimant
		modifier = {
			factor = 0
			holder_scope = {
				OR = {
					NOT = { compare_cultures_FROM_trigger = yes }
					NOT = { religion = FROM }
				}
				any_demesne_title = {
					OR = {
						is_primary_holder_title = yes
						higher_tier_than = DUKE
					}
					FROM = {
						primary_title = {
							de_jure_liege_or_above = PREVPREV
						}
					}
					any_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
					}
				}
			}
		}
		
		modifier = {
			factor = 0
			FROM = { preparing_invasion = yes }
		}
		
		modifier = {
			factor = 0
			FROM = { 
				opinion = { who = LIEGE value = 0 } 
				NOR = {
					trait = deceitful
					trait = ambitious
					trait = envious
				}
				is_voter = no
			}
		}		
		
		modifier = {
			factor = 0
			FROM = {
				opinion = { who = LIEGE value = -15 } 			
			}
		}
		
		modifier = {
			factor = 1.5
			NOT = { FROM = { opinion = { who = LIEGE value = -25 } } }
		}
		modifier = {
			factor = 2.0
			NOT = { FROM = { opinion = { who = LIEGE value = -50 } } }
		}
		modifier = {
			factor = 4.0
			NOT = { FROM = { opinion = { who = LIEGE value = -75 } } }
		}
		modifier = {
			factor = 0.75
			FROM = {
				NOT = {
					liege = { is_tyrant_trigger = yes }
				}
			}
		}
		modifier = {
			factor = 0.01
			FROM = { trait = content }
		}
		modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}
		modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}
		modifier = {
			factor = 0.2
			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { trait = kind }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = charitable }
		}
		modifier = {
			factor = 0.5
			FROM = { trait = honest }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = humble }
		}
		modifier = {
			factor = 0.75
			FROM = { trait = just }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = proud }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = brave }
		}
		modifier = {
			factor = 1.5
			FROM = { trait = arbitrary }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = greedy }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = impaler }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = deceitful }
		}
		modifier = {
			factor = 4.0
			FROM = { trait = ambitious }
		}
	}
	
	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 1			
		
		modifier = {
			factor = 0
			OR = {
				prisoner = yes
				trait = incapable
				is_adult = no
				is_landed = no
				has_character_modifier = in_seclusion
				preparing_invasion = yes
			}
		}
		modifier = {
			factor = 0.8
			liege = {
				OR = {
					trait = crowned
					trait = weak_basileus
				}
			}
		}
		modifier = {
			factor = 0.5
			liege = {
				trait = crowned_by_pope
			}
		}
		modifier = {
			factor = 0.2
			liege = {
				trait = strong_basileus
			}
		}
		modifier = {
			factor = 0
			FROMFROM = {
				current_heir = {
					character = ROOT
				}
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0
			has_character_modifier = faction_powerful_vassal_takeover_ultimatum_timer
		}

		modifier = {
			factor = 0
			opinion = { who = FROMFROM value = 0 }
		}
		
		modifier = {
			factor = 0
			NOT = { opinion = { who = FROM value = -40 } }
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0
			liege = { 
				NOT = { year = 1350 }
				primary_title = { is_tribal_type_title = yes }
				culture = ROOT
				religion = ROOT
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0
			has_opinion_modifier = {
				who = LIEGE
				modifier = opinion_coerced_into_leaving_faction
			}
		}
		
		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 40 }
			is_voter = no
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}

		modifier = {
			factor = 0
			opinion = { who = LIEGE value = 80 }
			is_voter = yes
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		modifier = {
			factor = 0.2
			pacifist = yes
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		
		
		modifier = {
			factor = 1000
			has_opinion_modifier = {
				who = FROM
				modifier = opinion_coerced_into_joining_faction
			}
		}
		
		modifier = {
			factor = 1.5
			NOT = { opinion = { who = LIEGE value = -10 } }
		}
		modifier = {
			factor = 2.0
			NOT = { opinion = { who = LIEGE value = -50 } }
		}
		modifier = {
			factor = 4.0
			NOT = { opinion = { who = LIEGE value = -75 } }
		}
		
		modifier = {
			factor = 0.75
			NOT = {
				liege = { is_tyrant_trigger = yes }
			}
		}
		
		modifier = {
			factor = 0.01
			trait = content
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.01
			trait = imbecile
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.1
			trait = inbred
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.1
			trait = craven
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.2
			OR = {
				trait = slow
				trait = dull
			}
			NOT = {	
				has_opinion_modifier = {
					who = FROM
					modifier = opinion_coerced_into_joining_faction
				}
			}
		}
		modifier = {
			factor = 0.5
			trait = kind
		}
		modifier = {
			factor = 0.5
			trait = charitable
		}
		modifier = {
			factor = 0.5
			trait = honest
		}
		modifier = {
			factor = 0.75
			trait = humble
		}
		modifier = {
			factor = 0.75
			trait = just
		}
		modifier = {
			factor = 1.5
			trait = proud
		}
		modifier = {
			factor = 1.5
			trait = brave
		}
		modifier = {
			factor = 1.5
			trait = arbitrary
		}
		modifier = {
			factor = 2.0
			trait = envious
		}
		modifier = {
			factor = 2.0
			trait = greedy
		}
		modifier = {
			factor = 2.0
			trait = impaler
		}
		modifier = {
			factor = 2.0
			trait = deceitful
		}
		modifier = {
			factor = 4.0
			trait = ambitious
		}
	}
	
	success = {
		holder_scope = {
			FROM = {
				has_opinion_modifier = { who = PREV modifier = opinion_abdicated }
			}
		}
	}
	
	abort = {
	}
	
	abort_effect = {
	}
	
	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_powerful_vassal_takeover
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}