######################################################
# Islam events										 #
# Relates to Piety, Religious Schools, Scholars		 #
# and the Islamic world in the Early modern era		 #
#                         							 #
# Written by Henrik Lohmander						 #
######################################################

namespace = muslim_school_events
namespace = muslim_school_opinion_events

#Change opinion between schools

#Increasing to like
country_event = {
	id = muslim_school_opinion_events.1
	title = muslim_school_opinion_events.1.t
	desc = muslim_school_opinion_events.1.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture
	
	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		has_religious_school = yes
		total_development = 50
		num_of_cities = 5
		any_country = {
			has_religious_school = yes
			total_development = 50
			num_of_cities = 5
			NOT = { has_religious_school_of = ROOT }
			school_opinion = { #0 or more
				who = ROOT
				opinion = 0
			}
			NOT = {
				school_opinion = { #Below 1
					who = ROOT
					opinion = 1
				}
			}
			trust = {
				who = ROOT
				value = 70
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_country = {
				limit = {
					has_religious_school = yes
					total_development = 50
					num_of_cities = 5
					NOT = { has_religious_school_of = ROOT }
					school_opinion = { #0 or more
						who = ROOT
						opinion = 0
					}
					NOT = {
						school_opinion = { #Below 1
							who = ROOT
							opinion = 1
						}
					}
					trust = {
						who = ROOT
						value = 70
					}
				}
				save_event_target_as = school_opinion_increase_country
			}
		}
	}

	mean_time_to_happen = {
		months = 360
	}
	
	option = {
		name = muslim_school_opinion_events.1.a #
		event_target:school_opinion_increase_country = {
			set_school_opinion = {
				who = ROOT
				opinion = 1
			}
		}
	}
}

#Increasing to neutral
country_event = {
	id = muslim_school_opinion_events.2
	title = muslim_school_opinion_events.2.t
	desc = muslim_school_opinion_events.2.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture
	
	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		has_religious_school = yes
		total_development = 50
		num_of_cities = 5
		any_known_country = {
			has_religious_school = yes
			total_development = 50
			num_of_cities = 5
			NOT = { has_religious_school_of = ROOT }
			NOT = {
				school_opinion = {
					who = ROOT
					opinion = 0
				}
			}
			NOT = { war_with = ROOT }
			NOT = { truce_with = ROOT }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_known_country = {
				limit = {
					has_religious_school = yes
					total_development = 50
					num_of_cities = 5
					NOT = { has_religious_school_of = ROOT }
					NOT = {
						school_opinion = {
							who = ROOT
							opinion = 0
						}
					}
					NOT = { war_with = ROOT }
					NOT = { truce_with = ROOT }
				}
				save_event_target_as = school_opinion_increase_country
			}
		}
	}

	mean_time_to_happen = {
		months = 700
	}
	
	option = {
		name = muslim_school_opinion_events.2.a #
		event_target:school_opinion_increase_country = {
			set_school_opinion = {
				who = ROOT
				opinion = 0
			}
		}
	}
}

#Decreasing opinion
country_event = {
	id = muslim_school_opinion_events.3
	title = muslim_school_opinion_events.3.t
	desc = muslim_school_opinion_events.3.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture
	
	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		has_religious_school = yes
		total_development = 50
		num_of_cities = 5
		any_country = {
			has_religious_school = yes
			total_development = 50
			num_of_cities = 5
			war_with = ROOT
			NOT = { has_religious_school_of = ROOT }
			school_opinion = {
				who = ROOT
				opinion = 0
			}
			defensive_war_with = ROOT
			is_in_war = {
				defender_leader = THIS
				attacker_leader = ROOT
				duration = 1095
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_country = {
				limit = {
					has_religious_school = yes
					total_development = 50
					num_of_cities = 5
					war_with = ROOT
					NOT = { has_religious_school_of = ROOT }
					school_opinion = {
						who = ROOT
						opinion = 0
					}
					defensive_war_with = ROOT
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
						duration = 1095
					}
				}
				save_event_target_as = school_opinion_decrease_country
			}
		}
	}

	mean_time_to_happen = {
		months = 30
		modifier = {
			factor = 0.75
			any_country = {
				has_religious_school = yes
				total_development = 50
				num_of_cities = 5
				war_with = ROOT
				NOT = { has_religious_school_of = ROOT }
				school_opinion = {
					who = ROOT
					opinion = 0
				}
				defensive_war_with = ROOT
				is_in_war = {
					defender_leader = THIS
					attacker_leader = ROOT
					duration = 1825 #5 years
				}
			}
		}
	}
	
	option = {
		name = muslim_school_opinion_events.3.a #
		if = { # 0 is changed to -1
			limit = {
				event_target:school_opinion_decrease_country = {
					NOT = {
						school_opinion = {
							who = ROOT
							opinion = 1
						}
					}
				}
			}
			event_target:school_opinion_decrease_country = {
				set_school_opinion = {
					who = ROOT
					opinion = -1
				}
			}
		}
		else = { #1 is changed to 0

			event_target:school_opinion_decrease_country = {
				set_school_opinion = {
					who = ROOT
					opinion = 0
				}
			}
		}
	}
}

#A Talented Judge
country_event = {
	id = muslim_school_events.1
	title = muslim_school_events.1.t
	desc = muslim_school_events.1.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture
	goto = mufti_province
	trigger = {
		religion_group = muslim
		NOT = { religion = shiite }
		has_dlc = "Cradle of Civilization"
		has_religious_school = yes
		any_owned_province = {
			is_state = yes
			is_capital = no
			NOT = { area = CAPITAL }
			NOT = {
				any_province = {
					area = PREV
					owned_by = ROOT
					has_province_modifier = talented_qadi
				}
			}
		}
	}

	mean_time_to_happen = {
		months = 600
		modifier = {
			factor = 0.9
			stability = 2
		}
		modifier = {
			factor = 0.9
			stability = 3
		}
		modifier = {
			factor = 0.9
			has_religious_scholars_trigger = yes
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					NOT = { area = CAPITAL }
					NOT = {
						any_province = {
							area = PREV
							owned_by = ROOT
							has_province_modifier = talented_qadi
						}
					}
				}
				save_event_target_as = mufti_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					development = 10
					NOT = { area = CAPITAL }
					NOT = {
						any_province = {
							area = PREV
							owned_by = ROOT
							has_province_modifier = talented_qadi
						}
					}
				}
				save_event_target_as = mufti_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					development = 15
					NOT = { area = CAPITAL }
					NOT = {
						any_province = {
							area = PREV
							owned_by = ROOT
							has_province_modifier = talented_qadi
						}
					}
				}
				save_event_target_as = mufti_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					development = 20
					NOT = { area = CAPITAL }
					NOT = {
						any_province = {
							area = PREV
							owned_by = ROOT
							has_province_modifier = talented_qadi
						}
					}
				}
				save_event_target_as = mufti_province
			}
			random_owned_province = {
				limit = {
					development = 25
					is_state = yes
					is_capital = no
					NOT = { area = CAPITAL }
					NOT = {
						any_province = {
							area = PREV
							owned_by = ROOT
							has_province_modifier = talented_qadi
						}
					}
				}
				save_event_target_as = mufti_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					development = 30
					NOT = { area = CAPITAL }
					NOT = {
						any_province = {
							area = PREV
							owned_by = ROOT
							has_province_modifier = talented_qadi
						}
					}
				}
				save_event_target_as = mufti_province
			}
		}
	}
	
	option = {
		name = muslim_school_events.1.a #I hear [mufti_province.GetAreaName] is in need of a new Qadi.
		event_target:mufti_province = {
			area = {
				limit = { owned_by = ROOT }
				add_province_modifier = {
					name = "talented_qadi"
					duration = 5475
				}
			}
		}
	}
	option = {
		name = muslim_school_events.1.b #He will bring legal guidance to a generation as a Mufti in [Root.Capital.GetCapitalName]
		if = {
			limit = {
				NOT = { monthly_income = 30 }
			}
			if = {
				limit = {
					religious_school = {
						group = muslim
						school = hanafi_school
					}
				}
				define_advisor = {
					type = statesman
					skill = 2
					religion = sunni
					culture = event_target:mufti_province
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				define_advisor = {
					type = inquisitor
					skill = 2
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = maliki_school
					}
				}
				define_advisor = {
					type = theologian
					skill = 2
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = shafii_school
					}
				}
				define_advisor = {
					type = philosopher
					skill = 2
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = ismaili_school
					}
				}
				define_advisor = {
					type = artist
					skill = 2
					culture = event_target:mufti_province
					religion = shiite
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = jafari_school
					}
				}
				define_advisor = {
					type = diplomat
					skill = 2
					culture = event_target:mufti_province
					religion = shiite
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = zaidi_school
					}
				}
				define_advisor = {
					type = inquisitor
					religion = shiite
					culture = event_target:mufti_province
					skill = 2
					discount = yes
				}
			}
		}
		else_if = {
			limit = {
				monthly_income = 30
			}
			if = {
				limit = {
					religious_school = {
						group = muslim
						school = hanafi_school
					}
				}
				define_advisor = {
					type = statesman
					skill = 3
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				define_advisor = {
					type = inquisitor
					skill = 3
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = maliki_school
					}
				}
				define_advisor = {
					type = theologian
					skill = 3
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = shafii_school
					}
				}
				define_advisor = {
					type = philosopher
					skill = 3
					culture = event_target:mufti_province
					religion = sunni
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = ismaili_school
					}
				}
				define_advisor = {
					type = artist
					skill = 3
					culture = event_target:mufti_province
					religion = shiite
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = jafari_school
					}
				}
				define_advisor = {
					type = diplomat
					skill = 3
					culture = event_target:mufti_province
					religion = shiite
					discount = yes
				}
			}
			else_if = {
				limit = {
					religious_school = {
						group = muslim
						school = zaidi_school
					}
				}
				define_advisor = {
					type = inquisitor
					skill = 3
					culture = event_target:mufti_province
					religion = shiite
					discount = yes
				}
			}
		}
	}
}

# Election of a Sheik-ul-Islam
country_event = {
	id = muslim_school_events.2
	title = muslim_school_events.2.t
	desc = muslim_school_events.2.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture
	
	is_triggered_only = yes
	
	immediate = {
		hidden_effect = {
			clr_country_flag = had_sheikh_ul_islam_event
			#Loyal Mufti
			random_list = {
				42 = { set_country_flag = bad_loyal_mufti }
				43 = { set_country_flag = ok_loyal_mufti }
				15 = { set_country_flag = good_loyal_mufti }
			}
			#Pious Mufti
			random_list = {
				42 = { set_country_flag = bad_pious_mufti }
				43 = { set_country_flag = ok_pious_mufti }
				15 = { set_country_flag = good_pious_mufti }
			}
			#Sufi
			random_list = {
				42 = { set_country_flag = bad_sufi }
				43 = { set_country_flag = ok_sufi }
				15 = { set_country_flag = good_sufi }
			}
		}
	}
	
	option = {
		name = muslim_school_events.2.a #Let us elect a loyal Mufti to this position
		custom_tooltip = muslim_school_events.2.a.tt
		ai_chance = {
			factor = 33
		}
		trigger = {
			NOT = { has_global_flag = wahabism_founded }
			NOT = {
				religious_school = {
					group = muslim
					school = hanbali_school
				}
			}
		}
		trigger_switch = {
			on_trigger = has_country_flag
			bad_loyal_mufti = {
				add_ruler_modifier = {
					name = "bad_loyal_mufti_modifier"
				}
			}
			ok_loyal_mufti = {
				add_ruler_modifier = {
					name = "ok_loyal_mufti_modifier"
				}
			}
			good_loyal_mufti = {
				add_ruler_modifier = {
					name = "good_loyal_mufti_modifier"
				}
			}
		}
		clr_country_flag = bad_loyal_mufti
		clr_country_flag = ok_loyal_mufti
		clr_country_flag = good_loyal_mufti
		clr_country_flag = bad_pious_mufti
		clr_country_flag = ok_pious_mufti
		clr_country_flag = good_pious_mufti
		clr_country_flag = bad_sufi
		clr_country_flag = ok_sufi
		clr_country_flag = good_sufi
	}
	option = {
		name = muslim_school_events.2.b #We need a learned man who would not hesitate to speak his mind.
		ai_chance = {
			factor = 33
		}
		custom_tooltip = muslim_school_events.2.b.tt
		add_piety = 0.2
		trigger_switch = {
			on_trigger = has_country_flag
			bad_pious_mufti = {
				add_ruler_modifier = {
					name = "bad_pious_mufti_modifier"
				}
			}
			ok_pious_mufti = {
				add_ruler_modifier = {
					name = "ok_pious_mufti_modifier"
				}
			}
			good_pious_mufti = {
				add_ruler_modifier = {
					name = "good_pious_mufti_modifier"
				}
			}
		}
		clr_country_flag = bad_loyal_mufti
		clr_country_flag = ok_loyal_mufti
		clr_country_flag = good_loyal_mufti
		clr_country_flag = bad_pious_mufti
		clr_country_flag = ok_pious_mufti
		clr_country_flag = good_pious_mufti
		clr_country_flag = bad_sufi
		clr_country_flag = ok_sufi
		clr_country_flag = good_sufi
	}
	option = {
		name = muslim_school_events.2.c #Let us invite a man schooled in the esoteric secrets of Sufism.
		ai_chance = {
			factor = 33
			modifier = {
				factor = 3
				NOT = { legitimacy = 65 }
			}
		}
		trigger = {
			NOT = { has_global_flag = wahabism_founded }
			NOT = {
				religious_school = {
					group = muslim
					school = hanbali_school
				}
			}
		}
		custom_tooltip = muslim_school_events.2.c.tt
		add_piety = -0.2
		trigger_switch = {
			on_trigger = has_country_flag
			bad_sufi = {
				add_ruler_modifier = {
					name = "bad_sufi_modifier"
				}
			}
			ok_sufi = {
				add_ruler_modifier = {
					name = "ok_sufi_modifier"
				}
			}
			good_sufi = {
				add_ruler_modifier = {
					name = "good_sufi_modifier"
				}
			}
		}
		clr_country_flag = bad_loyal_mufti
		clr_country_flag = ok_loyal_mufti
		clr_country_flag = good_loyal_mufti
		clr_country_flag = bad_pious_mufti
		clr_country_flag = ok_pious_mufti
		clr_country_flag = good_pious_mufti
		clr_country_flag = bad_sufi
		clr_country_flag = ok_sufi
		clr_country_flag = good_sufi
	}
}

#New Madrasah
country_event = {
	id = muslim_school_events.3
	title = muslim_school_events.3.t
	desc = muslim_school_events.3.d
	picture = BIG_ARABIAN_CITY_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		any_owned_province = {
			is_capital = no
			has_building = temple
			NOT = { has_province_modifier = new_madrassah }
			NOT = { has_province_flag = new_madrassah_flag }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_capital = no
					has_building = temple
					NOT = { has_province_modifier = new_madrassah }
					NOT = { has_province_flag = new_madrassah_flag }
				}
				save_event_target_as = madrassah_province
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
		
		#Support of Religious Establishment for Righteous Rule:
		modifier = {
			factor = 0.9
			piety = 0.7
			NOT = { has_global_flag = neo_sufism } #After this you have to be more pious for bonus.
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 0.8
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 1.0
			has_pious_sheikh_ul_islam_trigger = yes
		}
		#Support of Religious Establishment under loyal Sheik-ul-Islam:
		modifier = {
			factor = 0.8
			has_loyal_sheikh_ul_islam_trigger = yes
			NOT = { has_global_flag = neo_sufism } #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 0.9
			has_loyal_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism #After this smaller bonus from loyal sheik ul islams.
		}
		#Support of Religious Establishment under Sufi leader:
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			NOT = { piety = 0.1 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			has_religious_scholars_trigger = yes
		}
	}
		

	option = {
		name = muslim_school_events.3.a
		event_target:madrassah_province = {
			add_province_modifier = {
				name = "new_madrassah"
				duration = 3650
			}
			set_province_flag = new_madrassah_flag
		}
	}
}

#Ghazis
country_event = {
	id = muslim_school_events.4
	title = muslim_school_events.4.t
	desc = muslim_school_events.4.d
	picture = QIZILBASH_CAVALRY_CHARGING_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		at_war_with_religious_enemy = yes
		has_border_with_religious_enemy = yes
		any_country = {
			NOT = { religion_group = muslim }
			war_with = ROOT
			num_of_cities = ROOT
		}
	}
	
	immediate = {
		hidden_effect = {
			random_country = {
				limit = { 
					NOT = { religion_group = muslim }
					war_with = ROOT
					num_of_cities = ROOT
				}
				save_event_target_as = infidel
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
		
		#Support of Religious Establishment for Righteous Rule:
		modifier = {
			factor = 0.9
			piety = 0.7
			NOT = { has_global_flag = neo_sufism } #After this you have to be more pious for bonus.
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 0.8
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 1.0
			has_pious_sheikh_ul_islam_trigger = yes
		}
		#Support of Religious Establishment under Sufi leader:
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			NOT = { piety = 0.1 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
	}
		

	option = {
		name = muslim_school_events.4.a
		add_yearly_manpower = 1
		add_country_modifier = {
			name = "ghazis_from_abroad"
			duration = 1825
		}
	}
}

#Custodianship of [holy_city.GetCapitalName]
#Size of bonus is randomized (25% largest 50% medium 25% smallest )
#Type and size of bonus is also dependent on the type of holy site.
country_event = {
	id = muslim_school_events.5
	title = muslim_school_events.5.t
	desc = muslim_school_events.5.d
	picture = {
		trigger = {
			OR = {
				owns_core_province = 384 #Medina
				owns_core_province = 385 #Mecca
			}
		}
		picture = MECCA_eventPicture
	}
	picture = {
		trigger = {
			NOT = { owns_core_province = 384 } #Medina
			NOT = {	owns_core_province = 385 } #Mecca
		}
		picture = PRAYER_IN_MOSQUE_eventPicture
	}

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		OR = {
			owns_core_province = 379 #Jerusalem
			owns_core_province = 384 #Medina
			owns_core_province = 385 #Mecca
			AND = {
				religion = shiite
				owns_core_province = 2311 #Najaf
			}
			AND = {
				religion = shiite
				owns_core_province = 409 #Karbala
			}
			AND = {
				religion = shiite
				owns_core_province = 2211 #Mashhad
			}
			AND = {
				NOT = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				any_owned_province = {
					is_core = ROOT
					has_province_modifier = sufi_shrine
				}
			}
		}
		any_country = {
			religion = ROOT
			NOT = { tag = ROOT }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_list = { #What type of reward?
				25 = {
					set_country_flag = trade_advisor_reward
				}
				25 = {
					set_country_flag = mp_reward
				}
				25 = {
					set_country_flag = money_reward
				}
				25 = {
					set_country_flag = scholar_advisor_reward
				}
			}
			random_list = { #How big a reward?
				25 = { set_country_flag = big_influx }
				50 = { set_country_flag = medium_influx }
				25 = { set_country_flag = low_influx }
			}
			random_owned_province = { #What type of holy site?
				limit = {
					OR = {
						province_id = 379 #Jerusalem
						province_id = 384 #Medina
						province_id = 385 #Mecca
						AND = {
							owner = { religion = shiite }
							province_id = 2311 #Najaf
						}
						AND = {
							owner = { religion = shiite }
							province_id = 409 #Karbala
						}
						AND = {
							owner = { religion = shiite }
							province_id = 2211 #Mashhad
						}
						AND = {
							owner = {
								NOT = {
									religious_school = {
										group = muslim
										school = hanbali_school
									}
								}
							}
							is_core = ROOT
							has_province_modifier = sufi_shrine
						}
					}
				}
				save_event_target_as = holy_city
			}
			random_owned_province = {
				limit = {
					OR = {
						province_id = 379 #Jerusalem
						province_id = 384 #Medina
						province_id = 385 #Mecca
						AND = {
							owner = { religion = shiite }
							province_id = 2311 #Najaf
						}
						AND = {
							owner = { religion = shiite }
							province_id = 409 #Karbala
						}
						AND = {
							owner = { religion = shiite }
							province_id = 2211 #Mashhad
						}
					}
				}
				save_event_target_as = holy_city
			}
			random_owned_province = {
				limit = {
					OR = {
						province_id = 379 #Jerusalem
						province_id = 384 #Medina
						province_id = 385 #Mecca
						AND = {
							owner = { religion = shiite }
							province_id = 2311 #Najaf
						}
						AND = {
							owner = { religion = shiite }
							province_id = 409 #Karbala
						}
						AND = {
							owner = { religion = shiite }
							province_id = 2211 #Mashhad
						}
					}
				}
				save_event_target_as = holy_city
			}
			random_owned_province = {
				limit = { 
					OR = {
						province_id = 384 #Medina
						province_id = 385 #Mecca
						province_id = 2311 #Najaf
					}
				}
				save_event_target_as = holy_city
			}
			random_country = { #From where do the advisors come?
				limit = {
					religion = ROOT
					NOT = { tag = ROOT }
				}
				save_event_target_as = origin_of_advisor
			}
			set_saved_name = {
				key = advisor_from_afar
				type = advisor
				scope = event_target:origin_of_advisor
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
		
		modifier = {
			factor = 1.2
			NOT = {
				owns_core_province = 384 #Medina
			}
			NOT = {
				owns_core_province = 385 #Mecca
			}
			NOT = { religion = shiite }
			NOT = {
				owns_core_province = 2311 #Najaf
			}
		}
		#Support of Religious Establishment for Righteous Rule:
		modifier = {
			factor = 0.9
			piety = 0.7
			NOT = { has_global_flag = neo_sufism } #After this you have to be more pious for bonus.
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 0.8
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 1.0
			has_pious_sheikh_ul_islam_trigger = yes
		}
		#Support of Religious Establishment under Sufi leader:
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			NOT = { piety = 0.1 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
	}

	option = {
		name = muslim_school_events.5.a #God is Good.
		if = {
			limit = {
				event_target:holy_city = {
					OR = {
						province_id = 384 #Medina
						province_id = 385 #Mecca
						province_id = 2311 #Najaf
					}
				}
			}
			trigger_switch = {
				on_trigger = has_country_flag
				money_reward = {
					clr_country_flag = money_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							add_years_of_income = 1
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							add_years_of_income = 0.5
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							add_years_of_income = 0.25
						}
					}
				}
				mp_reward = {
					clr_country_flag = mp_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							add_dip_power = 35
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							add_dip_power = 25
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							add_dip_power = 15
						}
					}
				}
				trade_advisor_reward = {
					clr_country_flag = trade_advisor_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							define_advisor = {
								type = trader
								skill = 3
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							define_advisor = {
								type = trader
								skill = 2
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							define_advisor = {
								type = trader
								skill = 2
								name = advisor_from_afar
								discount = yes
								culture = event_target:origin_of_advisor
							}
						}
					}
				}
				scholar_advisor_reward = {
					clr_country_flag = scholar_advisor_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							define_advisor = {
								type = natural_scientist
								skill = 3
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							define_advisor = {
								type = natural_scientist
								name = advisor_from_afar
								skill = 2
								discount = yes
								culture = event_target:origin_of_advisor
							}
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							define_advisor = {
								type = natural_scientist
								name = advisor_from_afar
								skill = 2
								discount = yes
								culture = event_target:origin_of_advisor
							}
						}
					}
				}
			}
		}
		else_if = { #Sufi Shrines
			limit = {
				event_target:holy_city = {
					has_province_modifier = sufi_shrine
				}
			}
			trigger_switch = {
				on_trigger = has_country_flag
				money_reward = {
					clr_country_flag = money_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							add_years_of_income = 0.5
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							add_years_of_income = 0.25
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							add_years_of_income = 0.1
						}
					}
				}
				mp_reward = {
					clr_country_flag = mp_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							add_dip_power = 25
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							add_dip_power = 15
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							add_dip_power = 15
						}
					}
				}
				trade_advisor_reward = {
					clr_country_flag = trade_advisor_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							define_advisor = { #Won't attract lvl 3 traders
								type = trader
								skill = 2
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							define_advisor = {
								type = trader
								skill = 2
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							define_advisor = {
								type = trader
								skill = 2
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
						}
					}
				}
				scholar_advisor_reward = {
					clr_country_flag = scholar_advisor_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							define_advisor = {
								type = philosopher
								skill = 3
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							define_advisor = {
								type = philosopher
								skill = 2
								discount = yes
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
							}
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							define_advisor = {
								type = philosopher
								name = advisor_from_afar
								culture = event_target:origin_of_advisor
								skill = 2
								discount = yes
							}
						}
					}
				}
			}
		}
		else = { #Holy cities that aren't Mecca, Medina or Najaf
			trigger_switch = {
				on_trigger = has_country_flag
				money_reward = {
					clr_country_flag = money_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							add_years_of_income = 0.75
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							add_years_of_income = 0.40
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							add_years_of_income = 0.25
						}
					}
				}
				mp_reward = {
					clr_country_flag = mp_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							add_dip_power = 30
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							add_dip_power = 20
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							add_dip_power = 15
						}
					}
				}
				trade_advisor_reward = {
					clr_country_flag = trade_advisor_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							define_advisor = {
								type = treasurer
								name = advisor_from_afar
								skill = 3
								discount = yes
								culture = event_target:origin_of_advisor
							}
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							define_advisor = {
								type = treasurer
								name = advisor_from_afar
								skill = 2
								discount = yes
								culture = event_target:origin_of_advisor
							}
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							define_advisor = {
								type = treasurer
								name = advisor_from_afar
								skill = 2
								discount = yes
								culture = event_target:origin_of_advisor
							}
						}
					}
				}
				scholar_advisor_reward = {
					clr_country_flag = scholar_advisor_reward
					trigger_switch = {
						on_trigger = has_country_flag
						big_influx = { 
							clr_country_flag = big_influx
							define_advisor = {
								type = theologian
								name = advisor_from_afar
								skill = 3
								discount = yes
								culture = event_target:origin_of_advisor
							}
							add_prestige = 10
						}
						medium_influx = { 
							clr_country_flag = medium_influx
							define_advisor = {
								type = theologian
								name = advisor_from_afar
								skill = 2
								discount = yes
								culture = event_target:origin_of_advisor
							}
							add_prestige = 5
						}
						low_influx = {
							clr_country_flag = low_influx
							define_advisor = {
								type = theologian
								name = advisor_from_afar
								skill = 2
								discount = yes
								culture = event_target:origin_of_advisor
							}
						}
					}
				}
			}
		}
	}
	after = {
		clear_saved_name = advisor_from_afar
	}
}

#Shiite Migration
country_event = {
	id = muslim_school_events.6
	title = muslim_school_events.6.t
	desc = muslim_school_events.6.d
	picture = PRAYER_IN_MOSQUE_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion = shiite
		is_free_or_tributary_trigger = yes
		piety = 0.75
		OR = {
			any_owned_province = {
				is_state = yes
				NOT = { has_province_modifier = foreign_shiite_urbanites }
			}
			any_owned_province = {
				is_state = no
				NOT = { has_province_modifier = foreign_shiite_settlers }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
		
		#Support of Religious Establishment for Righteous Rule:
		modifier = {
			factor = 0.9
			piety = 0.7
			NOT = { has_global_flag = neo_sufism } #After this you have to be more pious for bonus.
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 0.8
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 1.0
			has_pious_sheikh_ul_islam_trigger = yes
		}
		#Support of Religious Establishment under Sufi leader:
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			NOT = { piety = 0.1 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = { is_state = yes }
				save_event_target_as = urban_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					development = 10
				}
				save_event_target_as = urban_province
			}
			random_owned_province = {
				limit = { is_state = no }
				save_event_target_as = frontier_province
			}
			random_owned_province = {
				limit = {
					is_state = no
					OR = {
						any_neighbor_province = {
							NOT = { owned_by = ROOT }
						}
						has_owner_religion = no
					}
				}
				save_event_target_as = frontier_province
			}
		}
	}

	option = {
		name = muslim_school_events.6.a
		event_target:urban_province = {
			add_base_production = 1
			add_province_modifier = {
				name = "foreign_shiite_urbanites"
				duration = 3650
			}
		}
	}
	option = {
		name = muslim_school_events.6.b
		trigger = {
			any_owned_province = {
				is_state = no
			}
		}
		event_target:frontier_province = {
			add_base_manpower = 1
			add_province_modifier = {
				name = "foreign_shiite_settlers"
				duration = 3650
			}
		}
	}
}


#Sufi Syncretism
country_event = {
	id = muslim_school_events.7
	title = muslim_school_events.7.t
	desc = muslim_school_events.7.d
	picture = MYSTIC_IN_PRAYER_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		NOT = { has_global_flag = neo_sufism }
		any_owned_province = {
			NOT = { religion_group = muslim }
			NOT = { has_province_modifier = local_sufi }
			NOT = { has_province_modifier = local_sufi_chased_away }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					NOT = { religion_group = muslim }
					NOT = { has_province_modifier = local_sufi }
					NOT = { has_province_modifier = local_sufi_chased_away }
				}
				save_event_target_as = sufi_province
			}
			random_owned_province = {
				limit = {
					NOT = { religion_group = muslim }
					NOT = { has_province_modifier = local_sufi }
					NOT = { has_province_modifier = local_sufi_chased_away }
					NOT = { continent = europe }
					same_continent = ROOT
				}
				save_event_target_as = sufi_province
			}
		}
	}
	
	mean_time_to_happen = {
		months = 700
		
		modifier = {
			factor = 0.7
			NOT = { dominant_religion = ROOT }
		}
		#Support of Religious Establishment for Righteous Rule:
		modifier = {
			factor = 1.1
			piety = 0.7
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 1.1
			piety = 0.8
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 1.1
			OR = {
				piety = 1.0
				has_pious_sheikh_ul_islam_trigger = yes
			}
		}
		#Support of Religious Establishment under Sufi leader:
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			OR = {
				NOT = { piety = 0.1 }
				has_sufi_sheikh_ul_islam_trigger = yes
			}
		}
	}

	option = {
		name = muslim_school_events.7.a #He is doing God's work.
		add_piety = -0.15
		reduce_estate_church_loyalty_effect = yes
		event_target:sufi_province = {
			area = {
				limit = {
					owned_by = ROOT
					NOT = { religion_group = ROOT }
				}
				add_province_modifier = {
					name = "local_sufi"
					duration = 3650
				}
			}
		}
	}
	option = {
		name = muslim_school_events.7.b #He will have to do his preaching elsewhere.
		add_piety = 0.1
		add_estate_church_loyalty_effect = yes
		event_target:sufi_province = {
			area = {
				limit = {
					owned_by = ROOT
					NOT = { religion_group = ROOT }
				}
				add_province_modifier = {
					name = "local_sufi_chased_away"
					duration = 3650
				}
			}
		}
	}
}

#Foreign Scholars influence local theology
country_event = {
	id = muslim_school_events.8
	title = muslim_school_events.8.t
	desc = muslim_school_events.8.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture

	trigger = {
		religion_group = muslim
		has_religious_scholars_trigger = yes
		any_known_country = {
			OR = {
				our_scholar_matches_their_school_trigger = { school=hanafi }
				our_scholar_matches_their_school_trigger = { school=hanbali }
				our_scholar_matches_their_school_trigger = { school=shafii }
				our_scholar_matches_their_school_trigger = { school=maliki }
				our_scholar_matches_their_school_trigger = { school=zaidi }
				our_scholar_matches_their_school_trigger = { school=ismaili }
				our_scholar_matches_their_school_trigger = { school=jafari }
			}
			has_opinion = { who = ROOT value = 150 }
			OR = {
				alliance_with = ROOT
				is_subject_of = ROOT
				overlord_of = ROOT
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_known_country = {
				limit = {
					OR = {
						our_scholar_matches_their_school_trigger = { school=hanafi }
						our_scholar_matches_their_school_trigger = { school=hanbali }
						our_scholar_matches_their_school_trigger = { school=shafii }
						our_scholar_matches_their_school_trigger = { school=maliki }
						our_scholar_matches_their_school_trigger = { school=zaidi }
						our_scholar_matches_their_school_trigger = { school=ismaili }
						our_scholar_matches_their_school_trigger = { school=jafari }
					}
					has_opinion = { who = ROOT value = 150 }
					OR = {
						alliance_with = ROOT
						is_subject_of = ROOT
						overlord_of = ROOT
					}
				}
				save_event_target_as = scholar_country
			}
			set_saved_name = {
				key = foreign_theologian
				type = advisor
				scope = event_target:scholar_country
			}
		}
	}
	
	mean_time_to_happen = {
		months = 460

	}

	option = {
		name = muslim_school_events.8.a #
		if = {
			limit = {
				religion = sunni
				OR = {
					has_country_modifier = hanafi_scholar_modifier
					has_country_modifier = hanbali_scholar_modifier
					has_country_modifier = maliki_scholar_modifier
					has_country_modifier = shafii_scholar_modifier
				}
			}
			add_piety = 0.15
		}
		else_if = {
			limit = {
				religion = shiite
				OR = {
					has_country_modifier = ismaili_scholar_modifier
					has_country_modifier = jafari_scholar_modifier
					has_country_modifier = zaidi_scholar_modifier
				}
			}
			add_piety = 0.15
		}
		else_if = {
			limit = {
				religion = ibadi
			}
			add_piety = 0.15
		}
		else = { #We have invited scholars from another religion.
			add_piety = -0.15
		}
		define_advisor = {
			type = theologian
			name = foreign_theologian
			culture = event_target:scholar_country
			religion = event_target:scholar_country
			skill = 2
			discount = yes
		}
	}
	option = {
		name = muslim_school_events.8.b #
		if = {
			limit = {
				religion = sunni
				OR = {
					has_country_modifier = hanafi_scholar_modifier
					has_country_modifier = hanbali_scholar_modifier
					has_country_modifier = maliki_scholar_modifier
					has_country_modifier = shafii_scholar_modifier
				}
			}
			add_piety = 0.15
		}
		else_if = {
			limit = {
				religion = shiite
				OR = {
					has_country_modifier = ismaili_scholar_modifier
					has_country_modifier = jafari_scholar_modifier
					has_country_modifier = zaidi_scholar_modifier
				}
			}
			add_piety = 0.15
		}
		else_if = {
			limit = {
				religion = ibadi
			}
			add_piety = 0.15
		}
		else = { #We have invited scholars from another religion.
			add_piety = -0.15
		}
		add_adm_power = 25
	}
	after = {
		clear_saved_name = foreign_theologian
	}
}

#[scholar_country.GetReligiousSchool] Theologians
country_event = {
	id = muslim_school_events.9
	title = muslim_school_events.9.t
	desc = muslim_school_events.9.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		has_religious_scholars_trigger = yes
		any_known_country = {
			OR = {
				our_scholar_matches_their_school_trigger = { school=hanafi }
				our_scholar_matches_their_school_trigger = { school=hanbali }
				our_scholar_matches_their_school_trigger = { school=shafii }
				our_scholar_matches_their_school_trigger = { school=maliki }
				our_scholar_matches_their_school_trigger = { school=zaidi }
				our_scholar_matches_their_school_trigger = { school=ismaili }
				our_scholar_matches_their_school_trigger = { school=jafari }
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_known_country = {
				limit = {
					OR = {
						our_scholar_matches_their_school_trigger = { school=hanafi }
						our_scholar_matches_their_school_trigger = { school=hanbali }
						our_scholar_matches_their_school_trigger = { school=shafii }
						our_scholar_matches_their_school_trigger = { school=maliki }
						our_scholar_matches_their_school_trigger = { school=zaidi }
						our_scholar_matches_their_school_trigger = { school=ismaili }
						our_scholar_matches_their_school_trigger = { school=jafari }
					}
				}
				save_event_target_as = scholar_country
			}
		}
	}
	
	mean_time_to_happen = {
		months = 460

	}

	option = {
		name = muslim_school_events.9.a #He is doing God's work.
		if = {
			limit = {
				religion = sunni
				OR = {
					has_country_modifier = hanafi_scholar_modifier
					has_country_modifier = hanbali_scholar_modifier
					has_country_modifier = maliki_scholar_modifier
					has_country_modifier = shafii_scholar_modifier
				}
			}
			add_piety = 0.15
		}
		else_if = {
			limit = {
				religion = shiite
				OR = {
					has_country_modifier = ismaili_scholar_modifier
					has_country_modifier = jafari_scholar_modifier
					has_country_modifier = zaidi_scholar_modifier
				}
			}
			add_piety = 0.15
		}
		else_if = {
			limit = {
				religion = ibadi
			}
			add_piety = 0.15
		}
		else = { #We have invited scholars from another religion.
			add_piety = -0.15
		}
		event_target:scholar_country = {
			add_opinion = {
				who = ROOT
				modifier = academic_respect
			}
		}
	}
}

#"Religious Scholars Disagree"
country_event = {
	id = muslim_school_events.10
	title = muslim_school_events.10.t
	desc = muslim_school_events.10.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		has_religious_scholars_trigger = yes
	}
	

	mean_time_to_happen = {
		months = 460
		
		#Support of Religious Establishment under loyal Sheik-ul-Islam:
		modifier = {
			factor = 1.1
			has_loyal_sheikh_ul_islam_trigger = yes
			NOT = { has_global_flag = neo_sufism } #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 1.05
			has_loyal_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 0.9
			religion = sunni
			OR = {
				has_country_modifier = ismaili_scholar_modifier
				has_country_modifier = jafari_scholar_modifier
				has_country_modifier = zaidi_scholar_modifier
			}
		}
		modifier = {
			factor = 0.9
			religion = shiite
			OR = {
				has_country_modifier = hanafi_scholar_modifier
				has_country_modifier = hanbali_scholar_modifier
				has_country_modifier = maliki_scholar_modifier
				has_country_modifier = shafii_scholar_modifier
			}
		}
		modifier = {
			factor = 0.9
			OR = {
				has_pious_sheikh_ul_islam_trigger = yes
				has_global_flag = neo_sufism
			}
			piety = 0.5
		}
		modifier = {
			factor = 0.9
			OR = {
				has_pious_sheikh_ul_islam_trigger = yes
				has_global_flag = neo_sufism
			}
			piety = 0.8
		}
	}

	option = {
		name = muslim_school_events.10.a #Let us just ensure that this man is dealt with.
		add_adm_power = -25
		add_prestige = -10
	}
}

#Playing the courts
country_event = {
	id = muslim_school_events.11
	title = muslim_school_events.11.t
	desc = muslim_school_events.11.d
	picture = TRADE_GOODS_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		NOT = { religion = shiite }
		any_owned_province = {
			is_state = yes
			is_capital = no
			has_owner_religion = yes
			NOT = { has_province_modifier = courtly_disorder }
			NOT = { has_province_modifier = ruler_overriding_ulema }
			NOT = {
				any_province = {
					owned_by = ROOT
					area = PREV
					is_capital = yes
				}
			}
		}
		NOT = { has_country_modifier = muslim_playing_court_event_timer }
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = courtly_disorder }
					NOT = { has_province_modifier = ruler_overriding_ulema }
				}
				save_event_target_as = shiites_here
			}
			add_country_modifier = {
				name = muslim_playing_court_event_timer
				duration = 4880
				hidden = yes
			}
		}
	}
	
	mean_time_to_happen = {
		months = 520
		
		#Support of Religious Establishment under loyal Sheik-ul-Islam:
		modifier = {
			factor = 1.2
			has_loyal_sheikh_ul_islam_trigger = yes
			NOT = { has_global_flag = neo_sufism } #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 1.1
			has_loyal_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism #After this smaller bonus from loyal sheik ul islams.
		}
	}

	option = {
		name = muslim_school_events.11.a #Let us just ensure that this man is dealt with.
		add_piety = 0.25
		add_estate_church_loyalty_effect = yes
		event_target:shiites_here = {
			area = {
				add_province_modifier = {
					name = "courtly_disorder"
					duration = 3650
				}
			}
		}
	}
	option = {
		name = muslim_school_events.11.b #Pragmatism must come before theology.
		add_piety = -0.25
		reduce_estate_church_loyalty_effect = yes
		event_target:shiites_here = {
			area = {
				add_province_modifier = {
					name = "ruler_overriding_ulema"
					duration = 3650
				}
			}
		}
	}
}

#Taqiyya
country_event = {
	id = muslim_school_events.12
	title = muslim_school_events.12.t
	desc = muslim_school_events.12.d
	picture = MYSTICS_DANCING_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		NOT = { religion = shiite }
		any_owned_province = {
			is_state = yes
			is_capital = no
			has_owner_religion = yes
			NOT = { has_province_modifier = upset_lodges }
		}
		NOT = { has_country_modifier = taqiyya_event_timer }
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = upset_lodges }
				}
				save_event_target_as = shiites_here
			}
			add_country_modifier = {
				name = taqiyya_event_timer
				duration = 4880
				hidden = yes
			}
		}
	}
	
	mean_time_to_happen = {
		months = 520
		
		#Support of Religious Establishment under loyal Sheik-ul-Islam:
		modifier = {
			factor = 1.2
			has_loyal_sheikh_ul_islam_trigger = yes
			NOT = { has_global_flag = neo_sufism } #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 1.1
			has_loyal_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism #After this smaller bonus from loyal sheik ul islams.
		}

		modifier = {
			factor = 0.9
			has_sufi_sheikh_ul_islam_trigger = yes
		}
	}

	option = {
		name = muslim_school_events.12.a #We cannot tolerate heretics!
		ai_chance = {
			factor = 75
		}
		add_piety = 0.15
		add_prestige = -10
		add_estate_church_loyalty_effect = yes
		event_target:shiites_here = {
			area = {
				limit = { owned_by = ROOT }
				add_province_modifier = {
					name = "upset_lodges"
					duration = 3650
				}
			}
		}
	}
	option = {
		name = muslim_school_events.12.b #We must respect the Sufi lodges.
		ai_chance = {
			factor = 25
		}
		add_piety = -0.1
		reduce_estate_church_loyalty_effect = yes
		event_target:shiites_here = {
			every_province = {
				limit = {
					area = PREV
					owned_by = ROOT
					is_capital = no
				}
			}
			random = {
				chance = 40
				change_religion = shiite
			}
		}
	}
}

#Protests in [protest_province.GetName]
country_event = {
	id = muslim_school_events.13
	title = muslim_school_events.13.t
	desc = muslim_school_events.13.d
	picture = REVOLT_eventPicture
	
	goto = protest_province


	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		any_owned_province = {
			is_state = yes
			is_capital = no
			has_owner_religion = yes
			NOT = { has_province_modifier = agreed_with_mufti }
			NOT = { has_province_modifier = disagreed_with_mufti }
		}
		NOT = { has_country_modifier = mufti_event_timer }
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = agreed_with_mufti }
					NOT = { has_province_modifier = disagreed_with_mufti }
				}
				save_event_target_as = protest_province
			}
			add_country_modifier = {
				name = mufti_event_timer
				duration = 4880
				hidden = yes
			}
		}
	}
	
	mean_time_to_happen = {
		months = 520
		
		#Support of Religious Establishment under loyal Sheik-ul-Islam:
		modifier = {
			factor = 1.2
			has_loyal_sheikh_ul_islam_trigger = yes
			NOT = { has_global_flag = neo_sufism } #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 1.1
			has_loyal_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism #After this smaller bonus from loyal sheik ul islams.
		}
		
		
		modifier = {
			factor = 0.9
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			has_religious_scholars_trigger = yes
		}
		
	}

	option = {
		name = muslim_school_events.13.a #Let us compensate the people of [protest_province.GetName].
		ai_chance = {
			factor = 75
		}
		add_piety = 0.15
		add_prestige = -10
		add_estate_church_loyalty_effect = yes
		event_target:protest_province = {
			area = {
				add_province_modifier = {
					name = "agreed_with_mufti"
					duration = 3650
				}
			}
		}
	}
	option = {
		name = muslim_school_events.13.b #Mufti or not, there is nothing we can do.
		ai_chance = {
			factor = 25
		}
		add_piety = -0.1
		reduce_estate_church_loyalty_effect = yes
		event_target:protest_province = {
			area = {
				add_province_modifier = {
					name = "disagreed_with_mufti"
					duration = 3650
				}
			}
		}
	}
}


#The poor of [urbanization_province.GetCapitalName]
country_event = {
	id = muslim_school_events.14
	title = muslim_school_events.14.t
	desc = muslim_school_events.14.d
	picture = SOUP_KITCHEN_eventPicture
	
	goto = urbanization_province


	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		any_owned_province = {
			is_state = yes
			is_capital = no
			development = 10
			has_owner_religion = yes
			NOT = { has_province_modifier = waqfs_donated }
			NOT = { has_province_modifier = urban_decay }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = waqfs_donated }
					NOT = { has_province_modifier = urban_decay }
					development = 10
				}
				save_event_target_as = urbanization_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = waqfs_donated }
					NOT = { has_province_modifier = urban_decay }
					development = 15
				}
				save_event_target_as = urbanization_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = waqfs_donated }
					NOT = { has_province_modifier = urban_decay }
					development = 20
				}
				save_event_target_as = urbanization_province
			}
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = waqfs_donated }
					NOT = { has_province_modifier = urban_decay }
					development = 30
				}
				save_event_target_as = urbanization_province
			}
		}
	}
	
	mean_time_to_happen = {
		months = 520
		
		#Support of Religious Establishment under loyal Sheik-ul-Islam:
		modifier = {
			factor = 1.2
			has_loyal_sheikh_ul_islam_trigger = yes
			NOT = { has_global_flag = neo_sufism } #After this smaller bonus from loyal sheik ul islams.
		}
		modifier = {
			factor = 1.1
			has_loyal_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism #After this smaller bonus from loyal sheik ul islams.
		}
	}

	option = {
		name = muslim_school_events.14.a #We will naturally support such a cause.
		ai_chance = {
			factor = 25
		}
		add_prestige = 10
		event_target:urbanization_province = {
			add_province_modifier = {
				name = "waqfs_donated"
				duration = 5475
			}
		}
	}
	option = {
		name = muslim_school_events.14.b #Surely local notables can afford to do so out of their own pockets?
		ai_chance = {
			factor = 75
		}
		event_target:urbanization_province = {
			add_province_modifier = {
				name = "urban_decay"
				duration = 5475
			}
		}
	}
}

#Custodianship of [holy_city.GetCapitalName]
#These places also come with costs
country_event = {
	id = muslim_school_events.15
	title = muslim_school_events.15.t
	desc = muslim_school_events.15.d
	picture = {
		trigger = {
			OR = {
				owns_core_province = 384 #Medina
				owns_core_province = 385 #Mecca
			}
		}
		picture = MECCA_eventPicture
	}
	picture = {
		trigger = {
			NOT = { owns_core_province = 384 } #Medina
			NOT = {	owns_core_province = 385 } #Mecca
		}
		picture = PRAYER_IN_MOSQUE_eventPicture
	}

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		NOT = { has_country_modifier = "upkeep_of_holy_cities" }
		OR = {
			owns_core_province = 379 #Jerusalem
			owns_core_province = 384 #Medina
			owns_core_province = 385 #Mecca
			AND = {
				religion = shiite
				owns_core_province = 2311 #Najaf
			}
			AND = {
				religion = shiite
				owns_core_province = 409 #Karbala
			}
			AND = {
				religion = shiite
				owns_core_province = 2211 #Mashhad
			}
			AND = {
				NOT = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				any_owned_province = {
					is_core = ROOT
					has_province_modifier = sufi_shrine
				}
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = { #What holy site?
				limit = {
					OR = {
						province_id = 379 #Jerusalem
						province_id = 384 #Medina
						province_id = 385 #Mecca
						AND = {
							owner = { religion = shiite }
							province_id = 2311 #Najaf
						}
						AND = {
							owner = { religion = shiite }
							province_id = 409 #Karbala
						}
						AND = {
							owner = { religion = shiite }
							province_id = 2211 #Mashhad
						}
						AND = {
							owner = {
								NOT = {
									religious_school = {
										group = muslim
										school = hanbali_school
									}
								}
							}
							is_core = ROOT
							has_province_modifier = sufi_shrine
						}
					}
				}
				save_event_target_as = holy_city
			}
			random_owned_province = {
				limit = {
					OR = {
						province_id = 379 #Jerusalem
						province_id = 384 #Medina
						province_id = 385 #Mecca
						AND = {
							owner = { religion = shiite }
							province_id = 2311 #Najaf
						}
						AND = {
							owner = { religion = shiite }
							province_id = 409 #Karbala
						}
						AND = {
							owner = { religion = shiite }
							province_id = 2211 #Mashhad
						}
					}
				}
				save_event_target_as = holy_city
			}
			random_owned_province = {
				limit = {
					OR = {
						province_id = 379 #Jerusalem
						province_id = 384 #Medina
						province_id = 385 #Mecca
						AND = {
							owner = { religion = shiite }
							province_id = 2311 #Najaf
						}
						AND = {
							owner = { religion = shiite }
							province_id = 409 #Karbala
						}
						AND = {
							owner = { religion = shiite }
							province_id = 2211 #Mashhad
						}
					}
				}
				save_event_target_as = holy_city
			}
			random_owned_province = {
				limit = { 
					OR = {
						province_id = 384 #Medina
						province_id = 385 #Mecca
						province_id = 2311 #Najaf
					}
				}
				save_event_target_as = holy_city
			}
		}
	}
	
	mean_time_to_happen = {
		months = 560
		
		modifier = {
			factor = 1.1
			NOT = {
				owns_core_province = 384 #Medina
			}
			NOT = {
				owns_core_province = 385 #Mecca
			}
			NOT = { religion = shiite }
			NOT = {
				owns_core_province = 2311 #Najaf
			}
		}
		#Support of Religious Establishment for Righteous Rule:
		modifier = {
			factor = 0.9
			piety = 0.7
			NOT = { has_global_flag = neo_sufism } #After this you have to be more pious for bonus.
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 0.8
			has_pious_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			piety = 1.0
			has_pious_sheikh_ul_islam_trigger = yes
		}
		#Support of Religious Establishment under Sufi leader:
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		
		modifier = {
			factor = 0.9
			NOT = { piety = 0.1 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.95
			has_religious_scholars_trigger = yes
		}
	}

	option = {
		name = muslim_school_events.15.a #Let us set aside more land for their upkeep.
		add_country_modifier = {
			name = "upkeep_of_holy_cities"
			duration = 5475
		}
	}
	option = {
		name = muslim_school_events.15.b #Sadly we have no more resources to spare right now.
		reduce_estate_church_loyalty_effect = yes
		add_stability = -1
	}
}


# Expansion of the [madrasa_province.GetCapitalName] 
country_event = {
	id = muslim_school_events.16
	title = muslim_school_events.16.t
	desc = muslim_school_events.16.d
	picture = PRAYER_IN_MOSQUE_eventPicture
	goto = madrasa_province
	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		has_religious_scholars_trigger = yes
		any_owned_province = {
			is_state = yes
			is_capital = no
			has_owner_religion = yes
			NOT = { has_province_modifier = expanded_madrasah }
			NOT = { has_province_modifier = hampered_expansion_of_madrasah }
		}	
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = { #
				limit = { 
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = expanded_madrasah }
					NOT = { has_province_modifier = hampered_expansion_of_madrasah }
				}
				save_event_target_as = madrasa_province
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
	}

	option = {
		name = muslim_school_events.16.a #We must contribute to this endeavour.
		ai_chance = {
			factor = 75
			modifier = {
				factor = 0.05
				NOT = { num_of_cities = 20 }
			}
		}
		add_prestige = 10 #You get Prestige regardless for the famous scholarship.
		event_target:madrasa_province = {
			add_base_tax = 1
			add_base_production = 1
			area = {
				limit = {
					owned_by = ROOT
				}
				add_province_modifier = {
					name = "expanded_madrasah"
					duration = 7300
				}
			}
		}
	}
	option = {
		name = muslim_school_events.16.b #The locals can feed and pay for them.
		ai_chance = {
			factor = 25
		}
		add_prestige = 10 #You get Prestige regardless for the famous scholarship.
		event_target:madrasa_province = {
			area = {
				limit = {
					owned_by = ROOT
				}
				add_province_modifier = {
					name = "hampered_expansion_of_madrasah"
					duration = 3650
				}
			}
		}
	}
}

# Dargah
country_event = {
	id = muslim_school_events.17
	title = muslim_school_events.17.t
	desc = muslim_school_events.17.d
	picture = MYSTIC_IN_PRAYER_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		NOT = { has_ruler_modifier = sought_sufi_sheikh }
		NOT = { has_country_modifier = ruler_not_favoring_sufis }
		any_owned_province = {
			is_state = yes
			is_capital = no
			has_owner_religion = yes
			NOT = { has_province_modifier = sufi_shrine }
		}	
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = { #
				limit = { 
					is_state = yes
					is_capital = no
					has_owner_religion = yes
					NOT = { has_province_modifier = sufi_shrine }
				}
				save_event_target_as = dargah_province
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
		modifier = {
			factor = 0.9
			NOT = { piety = 0.5 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
		modifier = {
			factor = 0.9
			NOT = { piety = 0.3 }
			has_sufi_sheikh_ul_islam_trigger = yes
		}
	}

	option = {
		name = muslim_school_events.17.a #Let us seek guidance at this holy place.
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.5
				NOT = { has_global_flag = neo_sufism }
				capital_scope = {
					continent = asia
				}
			}
			modifier = {
				factor = 0.25
				has_global_flag = neo_sufism
			}
		}
		add_piety = -0.15
		add_ruler_modifier = {
			name = "sought_sufi_sheikh"
			duration = 9125
		}
		event_target:dargah_province = {
			add_permanent_province_modifier = {
				name = "sufi_shrine"
				duration = -1
			}
		}
	}
	option = {
		name = muslim_school_events.17.b #We must not feed into local superstition.
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.5
				has_global_flag = neo_sufism
			}
		}
		add_piety = 0.15
		add_country_modifier = {
			name = "ruler_not_favoring_sufis"
			duration = 9125
		}
		event_target:dargah_province = {
			add_province_modifier = {
				name = "sufi_shrine"
				duration = 3650
			}
		}
	}
}


# Alevis of X
country_event = {
	id = muslim_school_events.18
	title = muslim_school_events.18.t
	desc = muslim_school_events.18.d
	picture = PRAYER_IN_MOSQUE_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion = shiite
		any_owned_province = {
			is_capital = no
			nationalism = 1
			has_owner_religion = no
			NOT = { has_province_modifier = alevi_modifier }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = { #
				limit = { 
					is_capital = no
					nationalism = 1
					has_owner_religion = no
					NOT = { has_province_modifier = alevi_modifier }
				}
				save_event_target_as = alevi_province
			}
		}
	}
	
	mean_time_to_happen = {
		months = 540
	}

	option = {
		name = muslim_school_events.18.a #Let us empower our brothers of faith in the area.
		ai_chance = {
			factor = 25
		}
		event_target:alevi_province = {
			area = {
				limit = { owned_by = ROOT }
				add_province_modifier = {
					name = "alevi_modifier"
					duration = 7300
				}
			}
		}
	}
	option = {
		name = muslim_school_events.18.b #While we welcome them administration will remain in the hands of local authorities.
		ai_chance = {
			factor = 75
		}
		add_prestige = 5
	}
}

#The Worldly Ulema
#Corrupt Sadrs
country_event = {
	id = muslim_school_events.19
	title = muslim_school_events.19.t
	desc = muslim_school_events.19.d
	picture = MUSLIM_SCHOLAR_WRITING_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		NOT = { stability = 3 }
	}

	mean_time_to_happen = {
		months = 560
		modifier = {
			factor = 0.9
			corruption = 0.01
		}
		modifier = {
			factor = 1.3
			OR = {
				has_ruler_modifier = good_loyal_mufti_modifier
				has_ruler_modifier = good_pious_mufti_modifier
				has_ruler_modifier = good_sufi_modifier
			}
		}
	}

	option = {
		name = muslim_school_events.19.a #
		ai_chance = {
			factor = 25
		}
		add_estate_church_loyalty_effect = yes
		add_corruption = 2
		add_country_modifier = {
			name = "corrupt_sadrs"
			duration = 3650
		}
	}
	option = {
		name = muslim_school_events.19.b #
		ai_chance = {
			factor = 75
		}
		reduce_estate_church_loyalty_effect = yes
		add_corruption = -2
		add_country_modifier = {
			name = "ulema_displeased"
			duration = 3650
		}
	}
}

#Choosing Madhhab - New Country
country_event = {
	id = muslim_school_events.20
	title = muslim_school_events.20.t
	desc = muslim_school_events.20.d
	picture = MYSTIC_IN_PRAYER_eventPicture
	
	trigger = {
		has_dlc = "Cradle of Civilization"
		OR = {
			religion = sunni
			religion = shiite
			religion = ibadi
		}
		OR = {
			has_religious_school = no
			AND = {
				religion = sunni
				has_shia_school_trigger = yes
			}
			AND = {
				religion = shiite
				has_sunni_school_trigger = yes
			}
		}
	}

	is_triggered_only = yes
	
	option = {
		name = muslim_school_events.20.a #Gives areas historical school of region
		trigger = {
			ai = yes
		}
		if = { #Shafii in East Africa and East Indies
			limit = {
				religion = sunni
				capital_scope = {
					OR = {
						region = egypt_region
						region = mashriq_region
						region = horn_of_africa_region
						region = east_africa_region
						superregion = east_indies_superregion
					}
				}
			}
			set_religious_school = {
				group = muslim
				school = shafii_school
			}
		}
		else_if = { #Hanbali in Arabia
			limit = {
				religion = sunni
				capital_scope = {
					region = arabia_region
				}
			}
			set_religious_school = {
				group = muslim
				school = hanbali_school
			}
		}
		else_if = { #Maliki in Africa and Western Europe
			limit = {
				religion = sunni
				capital_scope = {
					OR = {
						continent = africa
						superregion = europe_superregion
					}
				}
			}
			set_religious_school = {
				group = muslim
				school = maliki_school
			}
		}
		else_if = { #Hanafi in Asia and Eastern Europe
			limit = {
				religion = sunni
				capital_scope = {
					OR = {
						continent = asia
						superregion = eastern_europe_superregion
					}
				}
			}
			set_religious_school = {
				group = muslim
				school = hanafi_school
			}
		}
		else_if = { #Jafari in Iran
			limit = {
				religion = shiite
				capital_scope = {
					superregion = persia_superregion
				}
			}
			set_religious_school = {
				group = muslim
				school = jafari_school
			}
		}
		else_if = { #Zaidi in Yemen/East Africa
			limit = {
				religion = shiite
				capital_scope = {
					OR = {
						area = upper_yemen_area
						area = tihama_al_yemen_area
						area = yemen_area
						area = hadramut_area
						area = mahra_area
						area = dhofar_area
						region = horn_of_africa_region
						region = east_africa_region
					}
				}
			}
			set_religious_school = {
				group = muslim
				school = zaidi_school
			}
		}
		else_if = { #Final fallbacks
			limit = { religion = sunni }
			set_religious_school = {
				group = muslim
				school = shafii_school
			}
		}
		else_if = { #Remaining Shiites get this:
			limit = { religion = shiite }
			set_religious_school = {
				group = muslim
				school = ismaili_school
			}
		}
		else_if = { #Remaining Shiites get this:
			limit = { 
				religion = ibadi
				capital_scope = {
					region = sufri_school
				}
			}
			set_religious_school = {
				group = muslim
				school = ismaili_school
			}
		}
		else = {
			set_religious_school = {
				group = muslim
				school = ibadi_school
			}
		}
	}
	option = {
		name = muslim_school_events.20.b #Hanafi
		trigger = {
			religion = sunni
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = hanafi_school
		}
	}
	option = {
		name = muslim_school_events.20.c #Hanbali
		trigger = {
			religion = sunni
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = hanbali_school
		}
	}
	option = {
		name = muslim_school_events.20.dd #Maliki
		trigger = {
			religion = sunni
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = maliki_school
		}
	}
	option = {
		name = muslim_school_events.20.e #Shafi'i
		trigger = {
			religion = sunni
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = shafii_school
		}
	}
	option = {
		name = muslim_school_events.20.f #Jafari
		trigger = {
			religion = shiite
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = jafari_school
		}
	}
	option = {
		name = muslim_school_events.20.g #Ismaili
		trigger = {
			religion = shiite
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = ismaili_school
		}
	}
	option = {
		name = muslim_school_events.20.h #Zaidi
		trigger = {
			religion = shiite
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = zaidi_school
		}
	}
	option = {
		name = muslim_school_events.20.i #Ibadi
		trigger = {
			religion = ibadi
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = ibadi_school
		}
	}
	option = {
		name = muslim_school_events.20.j #Sufri
		trigger = {
			religion = ibadi
			ai = no
		}
		set_religious_school = {
			group = muslim
			school = sufri_school
		}
	}
}

#Neo Sufism (Most likely going to trigger in India)
country_event = {
	id = muslim_school_events.21
	title = muslim_school_events.21.t
	desc = muslim_school_events.21.d
	picture = PRAYER_IN_MOSQUE_eventPicture
	
	major = yes

	trigger = {
		has_dlc = "Cradle of Civilization"
		is_year = 1600
		NOT = { has_global_flag = neo_sufism }
		uses_piety = yes
		NOT = { piety = 0.3 }
		NOT = { dominant_religion = ROOT }
		any_owned_province = {
			NOT = { religion_group = muslim }
			tolerance_to_this = 3
		}
	}
	
	immediate = {
		hidden_effect = {
			set_global_flag = neo_sufism
		}
	}
	
	mean_time_to_happen = {
		months = 600
	}
	
	option = {
		name = muslim_school_events.21.a #They are sadly misguided.
		custom_tooltip = muslim_school_events.21.a.tt #From now on the religious establishment will react more strongly to impious conduct of the [Root.Monarch.GetTitle].
		if = {
			limit = {
				has_estate = "estate_church"
			}
			tooltip = {
				add_estate_influence_modifier = {
					estate = estate_church
					desc = EST_VAL_NEO_SUFISM
					influence = 10
					duration = -1
				}
			}
		}
	}
}


#Birth of Wahabism
country_event = {
	id = muslim_school_events.22
	title = muslim_school_events.22.t
	desc = muslim_school_events.22.d
	picture = PRAYER_IN_MOSQUE_eventPicture
	
	major = yes

	trigger = {
		has_dlc = "Cradle of Civilization"
		is_year = 1700
		OR = {
			has_global_flag = neo_sufism
			is_year = 1780
		}
		uses_piety = yes
		religious_school = {
			group = muslim
			school = hanbali_school
		}
		piety = 0.65
	}
	
	immediate = {
		hidden_effect = {
			set_global_flag = wahabism_founded
		}
	}
	
	mean_time_to_happen = {
		months = 600
	}
	
	option = {
		name = muslim_school_events.22.a #Interesting
		custom_tooltip = muslim_school_events.22.a.tt #Sunni Tribal Federations will now be able to change to the Hanbali School
	}
}

#Sufi Shrines and the Religious Establishment
country_event = {
	id = muslim_school_events.23
	title = muslim_school_events.23.t
	desc = muslim_school_events.23.d
	picture = MYSTIC_IN_PRAYER_eventPicture

	trigger = {
		has_dlc = "Cradle of Civilization"
		religion_group = muslim
		OR = {
			has_pious_sheikh_ul_islam_trigger = yes
			has_global_flag = neo_sufism
		}
		any_owned_province = {
			has_province_modifier = sufi_shrine
		}
	}

	mean_time_to_happen = {
		months = 560
		modifier = {
			factor = 1.1
			NOT = { piety = 0.1 }
		}
		modifier = {
			factor = 1.1
			NOT = { piety = 0.3 }
		}
		modifier = {
			factor = 1.1
			NOT = { piety = 0.5 }
		}
		modifier = {
			factor = 0.9
			piety = 0.6
		}
		modifier = {
			factor = 0.9
			piety = 0.7
		}
		modifier = {
			factor = 0.9
			piety = 0.9
		}
	}

	option = {
		name = muslim_school_events.23.a #
		ai_chance = {
			factor = 50
			modifier = {	
				factor = 0.5
				NOT = { piety = 0.5 }
			}
		}
		add_piety = 0.1
		random_owned_province = {
			limit = { has_province_modifier = sufi_shrine }
			remove_province_modifier = sufi_shrine
		}
		add_country_modifier = {
			name = "ruler_not_favoring_sufis"
			duration = 3650
		}
	}
	option = {
		name = muslim_school_events.23.b #
		ai_chance = {
			factor = 50
			modifier = {	
				factor = 0.5
				piety = 0.5
			}
		}
		add_piety = -0.1
		add_legitimacy = 10
	}
}

#Invite a Permanent Scholar
country_event = {
	id = muslim_school_events.24
	title = muslim_school_events.24.t
	desc = muslim_school_events.24.d
	picture = MYSTIC_IN_PRAYER_eventPicture
	
	is_triggered_only = yes

	immediate = {
		disallow_baseline_invite_scholar = yes
	}

	option = {
		name = muslim_school_events.24.a
		trigger = {
			NOT = { has_country_flag = can_always_invite_hanafi_school }
			NOT = { has_country_flag = privilege_can_always_invite_hanafi_school }
			NOT = {
				religious_school = {
					group = muslim
					school = hanafi_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = hanafi_school
		}
	}

	option = {
		name = muslim_school_events.24.b
		trigger = {
			NOT = { has_country_flag = can_always_invite_hanbali_school }
			NOT = { has_country_flag = privilege_can_always_invite_hanbali_school }
			NOT = {
				religious_school = {
					group = muslim
					school = hanbali_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = hanbali_school
		}
	}

	option = {
		name = muslim_school_events.24.c
		trigger = {
			NOT = { has_country_flag = can_always_invite_maliki_school }
			NOT = { has_country_flag = privilege_can_always_invite_maliki_school }
			NOT = {
				religious_school = {
					group = muslim
					school = maliki_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = maliki_school
		}
	}

	option = {
		name = muslim_school_events.24.e
		trigger = {
			NOT = { has_country_flag = can_always_invite_shafii_school }
			NOT = { has_country_flag = privilege_can_always_invite_shafii_school }
			NOT = {
				religious_school = {
					group = muslim
					school = shafii_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = shafii_school
		}
	}

	option = {
		name = muslim_school_events.24.f
		trigger = {
			NOT = { has_country_flag = can_always_invite_ismaili_school }
			NOT = { has_country_flag = privilege_can_always_invite_ismaili_school }
			NOT = {
				religious_school = {
					group = muslim
					school = ismaili_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = ismaili_school
		}
	}

	option = {
		name = muslim_school_events.24.g
		trigger = {
			NOT = { has_country_flag = can_always_invite_jafari_school }
			NOT = { has_country_flag = privilege_can_always_invite_jafari_school }
			NOT = {
				religious_school = {
					group = muslim
					school = jafari_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = jafari_school
		}
	}

	option = {
		name = muslim_school_events.24.h
		trigger = {
			NOT = { has_country_flag = can_always_invite_zaidi_school }
			NOT = { has_country_flag = privilege_can_always_invite_zaidi_school }
			NOT = {
				religious_school = {
					group = muslim
					school = zaidi_school
				}
			}
		}
		allow_baseline_invite_scholar_privilege = {
			religious_school = zaidi_school
		}
	}

	after = {
		clr_country_flag = swaps_scholar_flag
	}
}