﻿on_bastard_birth = {
	events =
	{
		
	}		
}

in_naval_battle = {
	random_events = {
		1098 = 0
		4 = warfare.8 #Battle Wound
		4 = warfare.9 #Fallen in Battle
	}
}

in_land_battle = {
	random_events = {
		1098 = 0
		4 = warfare.6 #Battle Wound
		4 = warfare.7 #Fallen in Battle
	}
}

on_battle_won = {

}

on_state_secession = { #Fired for States that revolt only, for now. Civil wars require refactor.
	effect = {
		if = {
			limit = {
				has_variable = num_state_mods
			}
			while = {
				limit = {
					has_variable = num_state_mods
					var:num_state_mods > 0
				}
				owner = {
					add_1_free_province_investments = yes
				}
				if = {
					limit = {
						var:num_state_mods > 1
					}
					change_variable = {
						name = num_state_mods
						add = -1
					}
				}
				else = {
					remove_variable = num_state_mods
				}
			}
		}
		if = {
			limit = {
				owner = { is_ai = no }
			}
			every_state_province = { #This is a bit convoluted but gives the old owner a culture modifier for any culture dominant in at least 3 territories in the revolting state - unless it is an integrated or primary culture.
				save_scope_as = revolting_territory
				owner = {
					random_country_culture = {
						limit = { is_culture = scope:revolting_territory.culture }
						if = {
							limit = {
								root = {
									any_state_province = {
										count >= 3
										dominant_province_culture = scope:revolting_territory.culture
									}
								}
							}
							save_scope_as = revolt_culture
						}
					}
					if = {
						limit = { exists = scope:revolt_culture }
						scope:revolt_culture = {
							if = {
								limit = {
									NOT = { has_country_culture_modifier = revolting_culture }
									is_integrated = no
									NOT = { is_culture = root.owner.culture }
								}
								add_country_culture_modifier = {
									name = "revolting_culture"
									duration = 730 #2 years
								}
							}
						}
					}
				}
			}
		}
	}
}

on_rebellion_in_country = { #root scope parent country
	effect = {
		if = {
			limit = {
				is_ai = yes #There are numerous tools to offset rebellions, all of which are situational - the AI will never be able to manage these with the same ability as a human player, so we reduce the frequency of revolts to balance.
			}
			every_country_state = {
				capital_scope = {
					add_state_loyalty = 30
				}
			}
		}
	}
}

on_battle_lost = {
	random_events = {
		1000 = 0	
		50	= after_battle.2 #lose Victorious, if you have it
		50 = after_battle.4	#gaining brave or coward
		50 = after_battle.27 # Pompey Victorious lost
		50 = after_battle.29 # Pompey Daring lost
		50 = after_battle.30 # Pompey Tough lost
		50 = after_battle.41 # Pompey Wounded 
	}
}

on_siege_won = { #Only triggers if sieging army has a commander (which is also ROOT in this on_action)
	effect = {
		if = {
			limit = {
				is_mercenary = yes
				has_variable = adventuring_from
				var:adventuring_from = {
					has_land = yes
				}
			}
			set_variable = {
				name = adventuring_mercenary_siege
				value = location
			}
		}
	}
	
	events = {
		warfare.1
		warfare.10
		warfare.17
	}
	random_events = {
		1000 = 0
		25 = distinction.30
	}

}

#scope:former_ruler, root = country,
#same as on_ruler_change, but called before switching
on_reign_ending = { 
	on_actions = {
		on_republic_reign_ending
	}
}

on_reign_ending_successor = { #scope:former_ruler = the successor, because onactions..., root = country,
	effect = { 
		scope:former_ruler = {
			if = {
				limit = {
					has_character_modifier = foreign_citizen
				}
				remove_character_modifier = foreign_citizen
			}
		}
		if = {
			limit = {
				NOT = { has_law = elective_succession_law }
				tag = EGY
				exists = fam:Lagid
				scope:former_ruler = {
					NOT = { THIS = char:43 } # Ptolemaios Keraunos
					NOT = { THIS = char:45 } # Ptolemaios Philadelphos
					is_minor_character = no
					family = root.fam:Lagid
					NOT = { has_variable = took_on_regnal_name }
				}
			}
			scope:former_ruler = {
				switch = {
					trigger = is_male
					yes = {
						set_firstname = Ptolemaios
						save_scope_as = ptolemaios_scope
						char:42 = { save_scope_as = ptolemaios_soter }
						employer = { trigger_event = { id = heir_events.2 } }
					}
					no = {
						set_firstname = Kleopatra
						save_scope_as = kleo_scope
						employer = { trigger_event = { id = heir_events.3 } }
					}
				}
			}
		}
		else_if = {
			limit = {
				NOT = { has_law = elective_succession_law }
				tag = SEL
				exists = fam:Seleukid
				scope:former_ruler = {
					NOT = { THIS = char:26 } # Antiochos I
					is_minor_character = no
					family = root.fam:Seleukid
					NOT = { has_variable = took_on_regnal_name }
				}
			}
			scope:former_ruler = {
				if = {
					limit = { is_male = yes }
					if = {
						limit = {
							employer = { has_variable = had_antiochos }
						}
						set_firstname = Seleukos
						save_scope_as = seleukos_scope
						employer = { remove_variable = had_antiochos }
					}
					else = {
						set_firstname = Antiochos
						save_scope_as = antiochos_scope
						employer = { set_variable = had_antiochos }
					}
					employer = { trigger_event = { id = heir_events.1 } }
				}
			}
		}
		else_if = {
			limit = {
				NOT = { has_law = elective_succession_law }
				has_variable = mithridatic_pontus_flag
				exists = fam:Mithridatid
				scope:former_ruler = {
					NOT = { THIS = char:97 } # Mithridates III Ktistes
					NOT = { THIS = char:393 } # Ariobarzanes, son of above
					is_male = yes
					is_minor_character = no
					family = root.fam:Mithridatid
					NOT = { has_variable = took_on_regnal_name }
				}
			}
			scope:former_ruler = {
				if = {
					limit = { is_male = yes }
					set_firstname = Mithridates
					save_scope_as = mithridates_scope
					char:97 = { save_scope_as = mithridates_i }
					employer = { trigger_event = { id = heir_events.12 } }
				}
			}
		}
		else_if = {
			limit = {
				NOT = { has_law = elective_succession_law }
				tag = BIT
				exists = fam:Zipoeteid
				scope:former_ruler = {
					NOT = { THIS = char:307 } # Bas
					NOT = { THIS = char:90 } # Boteiras
					NOT = { THIS = char:306 } # Zipoetes II
					is_male = yes
					is_minor_character = no
					family = root.fam:Zipoeteid
					NOT = { has_variable = took_on_regnal_name }
				}
			}
			scope:former_ruler = {
				if = {
					limit = { is_male = yes }
					if = {
						limit = {
							employer = { has_variable = had_nikomedes }
						}
						set_firstname = Prusias
						save_scope_as = prusias_scope
						employer = { remove_variable = had_nikomedes }
					}
					else = {
						set_firstname = Nikomedes
						save_scope_as = nikomedes_scope
						employer = { set_variable = had_nikomedes }
					}
					employer = { trigger_event = { id = heir_events.13 } }
				}
			}
		}
		else_if = {
			limit = {
				NOT = { has_law = elective_succession_law }
				heritage = attalid_heritage
				exists = fam:Attalid
				scope:former_ruler = {
					NOT = { THIS = char:67 } # Attalos, father of Philetairos, Eumenes, and Attalos
					NOT = { THIS = char:386 } # Eumenes, father of Eumenes I
					NOT = { THIS = char:389 } # Eumenes I
					NOT = { THIS = char:390 } # Attalos, brother of Philetairos and Eumenes
					is_male = yes
					is_minor_character = no
					family = root.fam:Attalid
					NOT = { has_variable = took_on_regnal_name }
				}
			}
			scope:former_ruler = {
				if = {
					limit = {
						employer = { has_variable = had_attalos }
					}
					set_firstname = Eumenes
					save_scope_as = eumenes_scope
					employer = { remove_variable = had_attalos }
				}
				else = {
					set_firstname = Attalos
					save_scope_as = attalos_scope
					employer = { set_variable = had_attalos }
				}
				employer = { trigger_event = heir_events.14 }
			}
		}
	}
}

#scope:former_ruler, root = country
on_ruler_change = {
	effect = {
		if = {
			limit = {
				tag = MRY
				current_ruler = {
					NOR = {
						this = char:66
						this = char:65
						this = char:22
					}
				}
				NOT = { has_variable = had_mauryan_decline }
			}
			set_variable = had_mauryan_decline
			trigger_event = {
				id = dhe_buddhism.6
			}
		}
		if = {
			limit = {
				is_subject = yes
				is_subject_type = subject_mercenary_city_state
			}
			current_ruler = {
				add_martial = 2
			}
		}
		if = { #remove disloyal family mod if exists
			limit = {
				exists = root.current_ruler
				root.current_ruler = {
					has_character_modifier = disloyal_family_head_cmod
				}
			}
			root.current_ruler = {
				remove_triggered_character_modifier = disloyal_family_head_cmod
			}
		}
		if = {
			limit = {
				root.current_ruler = {
					has_variable = disloyal_family_head_var
				}
			}
			root.current_ruler = {
				remove_variable = disloyal_family_head_var
			}
		}
		if = {
			limit = {
				scope:former_ruler = {
					num_of_rivals >= 1
					any_rival = {
						is_ruler = yes
						NOT = {
							employer = root
						}
					}
					employer = {
						has_land = yes
					}
				}
			}
			scope:former_ruler = {
				every_rival = {
					limit = {
						is_ruler = yes
						NOT = {
							employer = root
						}
					}
					remove_rival = scope:former_ruler
				}
			}
		}
		if = {
			limit = {
				current_ruler = {
					has_variable = prominent_actor
					var:prominent_actor = 1
				}
				has_land = yes
			}
			current_ruler = {
				change_variable = {
					name = prominent_actor
					add = -1
				}
			}
		}
		if = {
			limit = {
				scope:former_ruler = {
					is_alive = yes
					has_variable = prominent_actor
					var:prominent_actor = 0
					employer = {
						has_land = yes
					}
				}
			}
			scope:former_ruler = {
				change_variable = {
					name = prominent_actor
					add = 1
				}
			}
		}
		if = {
			limit = {
				has_country_modifier = almost_divine_basileus
			}
			remove_country_modifier = almost_divine_basileus
		}
		if = {
			limit = {
				has_country_modifier = egypt_divine_basileus
			}
			remove_country_modifier = egypt_divine_basileus
		}
		clear_party_agenda_cooldown_var_effect = yes
		clear_befriending_var_effect = yes
		if = {
			limit = { has_country_modifier = dictatorial_extension }
			remove_country_modifier = dictatorial_extension
		}
		if = {
			limit = { has_variable = dictatorship_enabled }
			remove_variable = dictatorship_enabled
		}
		if = {
			limit = { has_variable = ach_dictator_appointed }
			remove_variable = dictatorship_enabled
		}
		if = {
			limit = {
				has_country_modifier = oaths_of_allegiance
			}
			remove_country_modifier = oaths_of_allegiance
		}
		if = {
			limit = {
				any_character = {
					has_character_modifier = elevated_pretender_charmod
				}
			}
			random_character = {
				limit = {
					has_character_modifier = elevated_pretender_charmod
				}
				remove_character_modifier = elevated_pretender_charmod
			}
		}
		if = {
			limit = {
				has_variable = ip_mon_36_flag
			}
			remove_variable = ip_mon_36_flag
		}
		if = {
			limit = { has_variable = ip_mon_38_flag }
			remove_variable = ip_mon_38_flag
		}
		if = {
			limit = { 
				scope:former_ruler = { has_variable = me_syr_current_tyrant_flag }
			}
			scope:former_ruler = { 
				remove_variable = me_syr_current_tyrant_flag
				save_scope_as = syracuse_old_tyrant
				employer = {
					trigger_event = {
						id = me_syracuse_1_democracy.3
						days = 1
					}
				}
			}
		}
		if = {
			limit = {
				is_monarchy = yes
				scope:former_ruler = { is_alive = no }
			}
			trigger_event = {
				id = gov_pol.9 #Loss of state loyalty
			}
		}
		if = {
			limit = {
				is_monarchy = yes
				scope:former_ruler = { is_alive = no }
			}
			trigger_event = {
				id = gov_pol.9 #Loss of state loyalty
			}
		}
		if = {
			limit = { has_country_modifier = me_epi_aborted_early }
			remove_country_modifier = me_epi_aborted_early
		}
		if = {
			limit = {
				is_republic = yes
			}
			current_ruler = {
				add_charisma = 1
			}
		}
		if = {
			limit = {
				scope:former_ruler = char:37
				tag = PRY
			}
			trigger_event = diadochi_flavor.8 #Antigonus bad
			trigger_event = diadochi_flavor.9 #Antigonus good
		}
	}
	on_actions = {
		on_republic_ruler_change
	}
	events = {
		family_events.5 #Rise of new Family
		new_ruler.1
		ip_republic.36
		succession_crisis.5
		character_events.8
		character_events.15
		diadochi_flavor.6
		roman_flavor.5 # Consul Conspiracy - Successful Election
		roman_flavor.6 # Consul Conspiracy - Unsuccessful Election
		italian_flavor.9 # Sicily and the Mamertines
		italian_flavor.15 # Sicily and the Mamertines fallback
		ip_monarchy.53 # Consort regency
		roman_flavor.13 # Dictator in Power
		dhe_iberia.4 # Pharnavaz becomes King of Iberia
		country_rename.1 # SEL/MRY/PRY name change
		me_roman_inheritance.1 # Roman Inheritance
	}
	random_events = {
		100 = 0
		25 = character_events.30
		5 = roman_flavor.1 # Start of Consul Conspiracy Event
	}
}


#If the rebels won.
#scope:target = ruler of losing side.
on_civil_war_lost = {
	effect = {
		scope:losing_side = {
			every_country_treasure = {
				transfer_treasure_to_country = root
			}
		}
		scope:losing_side = {
			save_scope_as = civil_war_target
		}
		if = {
			limit = {
				scope:losing_side = {
					government = dictatorship
				}
			}
			change_government = democratic_republic
		}
		if = {
			limit = {
				current_ruler = {
					has_variable = complete_pretender_support
					exists = var:complete_pretender_support
					var:complete_pretender_support = {
						alliance_with = root
					}
				}
			}
			save_scope_as = puppet_kingdom
			if = {
				limit = {
					current_ruler.var:complete_pretender_support.rank > root.rank
				}
				current_ruler.var:complete_pretender_support = {
					trigger_event = {
						id = warfare.14
					}
				}
			}
			else = {
				current_ruler.var:complete_pretender_support = {
					trigger_event = {
						id = warfare.15
					}
				}
			}
		}
	}
	events = {
		civil_war.3
		civil_war.6
		flavor_egy.11
		me_syracuse_1_democracy.29
		ip_republic.88
	}
}

#If original country won.
#scope:target = ruler of losing side.
on_civil_war_won = {
	effect = {
		scope:losing_side = {
			every_country_treasure = {
				transfer_treasure_to_country = root
			}
		}
		if = {
			limit = {
				is_iron_man = yes
				is_ai = no
				NOT = { 
					has_variable = ach_triumvir_var
				}
			}
			set_variable = {
				name = ach_triumvir_var
			}
		}
		scope:losing_side = {
			save_scope_as = civil_war_target
		}
		if = {
			limit = {
				has_variable = rome_schism_happened
			}
			remove_variable = rome_schism_happened
			if = {
				limit = {
					government = imperium
				}
				change_country_name = "roman_empire_name"
			}
			else_if = {
				limit = {
					is_monarchy = yes
				}
				change_country_name = "roman_kingdom_name"
			}
			else = {
				change_country_name = "ROM"
			}
			change_country_adjective = "roman"
		}
		if = {
			limit = {
				current_ruler = { has_variable = me_syr_current_tyrant_flag }
				NOT = { tag = SYR }
			}
			change_country_tag = SYR
		}
		if = {
			limit = {
				current_ruler = { has_variable = me_syr_current_tyrant_flag }
				NOT = { tag = SYR }
			}
			change_country_tag = SYR
		}
		if = {
			limit = {
				any_governorships = { has_legion_trigger = yes }
			}
			if = {
				limit = {
					tag = ROM
					is_republic = yes
					any_legion = { count < 2 }
					NOT = { has_law = punic_reforms }
				}
				change_law = punic_reforms
			}
			else_if = {
				limit = {
					tag = ROM
					is_republic = yes
					any_legion = { count >= 2 }
					NOT = { has_law = marian_reforms }
				}
				change_law = marian_reforms
			}
			else_if = {
				limit = {
					is_republic = yes
					any_legion = { count < 2 }
					NOT = { has_law = republican_recruitment_2 }
				}
				change_law = republican_recruitment_2
			}
			else_if = {
				limit = {
					is_republic = yes
					any_legion = { count >= 2 }
					NOT = { has_law = republican_recruitment_4 }
				}
				change_law = republican_recruitment_4
			}
			else_if = {
				limit = {
					is_monarchy = yes
					any_legion = { count < 2 }
					NOT = { has_law = work_for_the_best }
				}
				change_law = work_for_the_best
			}
			else_if = {
				limit = {
					is_monarchy = yes
					any_legion = { count >= 2 }
					NOT = { has_law = standing_army_law }
				}
				change_law = standing_army_law
			}
			#else = { #What was this doing? 
			#	every_governorships = {
			#		limit = { has_legion_trigger = yes }
			#		disband_legion = yes
			#	}
			#	set_legion_recruitment = disabled
			#}
		}
		if = {
			limit = {
				current_ruler = {
					has_variable = complete_pretender_support
					exists = var:complete_pretender_support
					var:complete_pretender_support = {
						alliance_with = root
					}
				}
			}
			save_scope_as = puppet_kingdom
			if = {
				limit = {
					current_ruler.var:complete_pretender_support.rank > root.rank
				}
				current_ruler.var:complete_pretender_support = {
					trigger_event = {
						id = warfare.14
					}
				}
			}
			else = {
				current_ruler.var:complete_pretender_support = {
					trigger_event = {
						id = warfare.15
					}
				}
			}
		}
	}
	events = {
		civil_war.1
		civil_war.5
		flavor_egy.10
		me_syracuse_1_democracy.28
		ip_republic.87
		dhe_iberia.5
		me_roman_9_eastern_glory.6
	}
}

on_character_death = {
	effect = {
		clear_ambition_effect = yes
		befriend_removal_effect = yes
		clear_befriending_var_effect = yes
		if = {
			limit = {
				has_variable = on_espionage_mission_origin
				var:on_espionage_mission_origin = {
					exists = this
					has_land = yes
				}
				has_variable = on_espionage_mission_recipient
				var:on_espionage_mission_recipient = {
					exists = this
					has_land = yes
				}
			}
			save_scope_as = spy
			var:on_espionage_mission_recipient = {
				save_scope_as = spied_upon
			}
			var:on_espionage_mission_origin = {
				save_scope_as = esp_o
			}
			scope:esp_o = {
				trigger_event = {
					id = country_diplomacy.46
				}
			}
		}
		remove_espionage_variables_effect = yes
		if = {
			limit = {
				has_triggered_character_modifier = disloyal_family_head_cmod
				is_general = yes
			}
			every_character_unit = {
				destroy_unit = yes
			}
		}
		if = { # Pyrrhus dies abroard
			limit = {
				this = char:70
				is_ruler = no
				age <= 22
				NOT = { employer = c:EPI }
				c:EPI = { has_land = yes }
			}
			c:EPI = {
				trigger_event = { id = dhe_dde_pyrrhus.10 }
			}
		}
		if = { # Pyrrhus - Memorable Life
			limit = {
				this = char:70
				is_ruler = yes
				employer = { 
					has_land = yes
					has_variable = pyrrhus_returns_flag
				}
			}
			employer = {
				trigger_event = { id = dhe_dde_pyrrhus.35 }
				me_epi_2_saved_variables_clearer_complete = yes
				me_epi_3_saved_variables_clearer_complete = yes
			}
		}
		# Wealth Inheritance
		if = { # Monarchy only - Ruler passes wealth to heir if they are related
			limit = {
				is_ruler = yes
				employer = {
					is_monarchy = yes
					exists = primary_heir
					OR = {
						primary_heir = { is_close_relative = ROOT }
						AND = {
							exists = primary_heir.family
							primary_heir.family = ROOT.family
						}
					}
				}
			}
			employer.primary_heir = {
				save_scope_as = holding_target
				add_gold = family_inheritance_svalue
			}
		}
		else_if = { # Head of Family passes wealth on
			limit = {
				is_head_of_family = yes
				exists = next_in_family
			}
			next_in_family = {
				save_scope_as = holding_target
				add_gold = family_inheritance_svalue
			}
		}
		else_if = { # Family member passes wealth to Head of Family
			limit = {
				is_head_of_family = no
				exists = family.head_of_family
				family.head_of_family = { employer = ROOT.employer }
			}
			family.head_of_family = {
				save_scope_as = holding_target
				add_gold = family_individual_inheritance_svalue
			}
		}
		add_gold = { # Clear deceased's bank accounts
			value = 0
			subtract = wealth
		}
		# Holding Inheritance
		if = { 
			limit = { num_holdings_owned > 0 }
			if = { # Give holdings to relevant character based on above
				limit = { 
					exists = scope:holding_target 
					NOT = {
						scope:holding_target = root
					}
				}
				while = {
					limit = { num_holdings_owned > 0 }
					random_holdings = { save_scope_as = holding_transfer }
					remove_holding = scope:holding_transfer
					scope:holding_target = { add_holding = scope:holding_transfer }
				}
				scope:holding_target = {
					trigger_event = {
						id = holding_mech.1
						days = 1 #Necessary
					}
				}
			}
		}
		# Succession Crisis
		if = {
			limit = {
				is_ruler = yes
				employer = {
					is_monarchy = yes
					has_land = yes
				}
			}
			save_scope_as = former_ruler
			employer = {
				if = {
					limit = {
						NOR = {
							has_variable = recent_succession_crisis
							has_civil_war = yes
						}
						any_successor = {
							loyalty < 33
							is_adult = yes
							is_ruler = no
							is_pretender = yes
							is_primary_heir = no
							NOT = {
								has_character_modifier = disloyal_successor_cmod
							}
						}
					}
					every_successor = {
						limit = {
							loyalty < 33
							is_adult = yes
							is_ruler = no
							is_pretender = yes
							is_primary_heir = no
							NOT = {
								has_character_modifier = disloyal_successor_cmod
							}
						}
						if = {
							limit = {
								NOT = {
									exists = scope:successor_general_1
								}
							}
							save_scope_as = successor_general_1
						}
						else_if = {
							limit = { 
								NOT = {
									exists = scope:successor_general_2
								}
							}
							save_scope_as = successor_general_2
						}
						else_if = {
							limit = {
								NOT = {
									exists = scope:successor_general_3
								}
							}
							save_scope_as = successor_general_3
						}
						else_if = {
							limit = {
								NOT = {
									exists = scope:successor_general_4
								}
							}
							save_scope_as = successor_general_4
						}
					}
					trigger_event = {
						id = succession_crisis.1
					}
				}
			}
		}
		if = {
			limit = {
				has_variable = adventuring_from
				NOT = {
					employer = var:adventuring_from
				}
				var:adventuring_from = {
					has_land = yes
				}
			}
			if = {
				limit = {
					has_variable = next_in_succession
				}
				set_local_variable = next_in_succession
			}
			location = {
				save_scope_as = death_location
			}
			save_scope_as = dead_merc
			var:adventuring_from = {
				trigger_event = {
					id = character_events.48
				}
			}
		}
		if = {
			limit = {
				has_variable = ip_mon_47_regent_consort
				employer = {
					has_land = yes
					current_ruler = {
						is_child_of = root
					}
				}
			}
			remove_variable = ip_mon_47_regent_consort
			save_scope_as = ip_mon_47_consort
			if = {
				limit = {
					NAND = {
						this = char:287
						employer.current_ruler = char:289
					}
				}
				employer = {
					trigger_event = { id = ip_monarchy.52 }
				}
			}
			else = {
				employer.current_ruler = { 
					remove_variable = ip_mon_47_regent_child
					remove_regent_modifier_effect = yes
				}
			}
		}
		if = {
			limit = {
				has_variable = ip_mon_47_regent_child
			}
			remove_variable = ip_mon_47_regent_child
			if = {
				limit = {
					remove_regent_modifier_trigger = yes
				}
				remove_regent_modifier_effect = yes
			}
			employer = {
				trigger_event = {
					id = ip_monarchy.49
				}
			}
		}
		if = {
			limit = { has_variable = me_syr_democracy_leader }
			remove_variable = me_syr_democracy_leader
			clear_saved_scope = democracy_leader
			save_scope_as = old_democracy_leader
			employer = {
				trigger_event = { id = me_syracuse_1_democracy.2 }
			}
		}
		if = {
			limit = { has_variable = me_syr_current_tyrant_flag }
			remove_variable = me_syr_current_tyrant_flag
			save_scope_as = syracuse_old_tyrant
			employer = {
				trigger_event = {
					id = me_syracuse_1_democracy.3
					days = 1
				}
			}
		}
		if = {
			limit = { has_variable = me_syr_foreign_leader_flag }
			remove_variable = me_syr_foreign_leader_flag
			save_scope_as = me_syracuse_old_foreign_request_character_scope
			if = {
				limit = {
					any_country = { has_variable = me_syr_foreign_country_flag }
				}
				random_country = {
					limit = { has_variable = me_syr_foreign_country_flag }
					save_scope_as = me_syracuse_foreign_request_scope
				}
				scope:me_syracuse_foreign_request_scope = {
					trigger_event = { id = me_syracuse_1_democracy.12 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = me_syr_heir_flag
				c:SYR = { has_variable = death_to_tyrants_flag }
				employer = {
					tag = SYR
					OR = {
						var:ongoing_revolutionary_route = 6
						AND = {
							has_completed_mission_task = syracuse_1_6_approach_heir
							NOT = { has_completed_mission_task = syracuse_1_7_assassinate }
						}
					}
				}
			}
			remove_variable = me_syr_heir_flag
			save_scope_as = me_syr_heir_scope
			c:SYR = {
				trigger_event = { id = me_syracuse_1_democracy.73 }
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_1_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_1_flag
			if = {
				limit = { 
					employer = { has_variable = gm_1_greek_country_flag }
				}
				employer = {
					trigger_event = { id = me_greek_1_black_sea.13 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_3_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_3_flag
			if = {
				limit = { 
					employer = { has_variable = gm_3_greek_country_flag }
				}
				employer = {
					trigger_event = { id = me_greek_3_italiote.26 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_4_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_4_flag
			if = {
				limit = { 
					employer = { has_variable = gm_4_greek_country_flag }
				}
				employer = {
					trigger_event = { id = me_greek_4_west.3 }
				}
			}
		}
		if = {
			limit = { has_variable = archimedes_flag }
			employer = {
				if = {
					limit = { has_country_modifier = archimedes_modifier }
					remove_country_modifier = archimedes_modifier
				}
			}
		}
		if = {
			limit = { 
				OR = {
					AND = {
						this = char:32 
						char:288 = {
							OR = {
								is_alive = no
								NOT = { employer = c:MAC }
							}
						}
					}
					AND = {
						this = char:288
						is_previous_ruler = yes
					}
				}
				char:289 = { 
					is_alive = yes
					employer = c:MAC
				}
				char:290 = { 
					is_alive = yes 
					employer = c:MAC
				}
			}
			c:MAC = {
				trigger_event = {
					id = dhe_macedon.7
					days = { 100 200 }
				}
			}
		}
		if = {
			limit = { this = char:52 }
			c:KIO = {
				trigger_event = { id = dhe_mithridates.9 }
			}
		}
		if = {
			limit = { has_variable = betrothed_flag }
			remove_variable = betrothed_flag
		}
	}
	events = {
		olympic.10 #inform patron country of athlete death
		ip_republic.33
	}
	random_events = {
		5 = character_events.1
		75 = 0
	}
}

on_character_created = {
	events = {
		character_events.49 # Baldness
	}
}

on_deified_ruler_death = {

}

on_tenth_birthday = {
	events = {
		character_events.49 # Baldness
	}
}

on_deficit_pulse = {
	trigger = {
		treasury <= -50
	}
	random_events = {
		10 = deficit.1
		10 = deficit.2
		10 = deficit.3
		10 = deficit.4
		10 = deficit.5
		10 = deficit.6
		100 = deficit.7
		25 = deficit.10
		50 = deficit.11
		100 = 0
	}
}

yearly_comet_pulse = {
	random_events = {
		100000 = 0
		1 = comet.1
	}
}

on_office_gained = {
	events = {
		office_gain.1
	}
}

on_office_lost = {
	events = {
		office_gain.2
	}
}

on_command_gained = {
	events = {
		office_gain.1
	}
}

on_command_lost = {
	events = {
		office_gain.2
	}
}

# Target is scope:target_culture, ROOT is country
on_culture_integration_0 = {
	
}

# Target is scope:target_culture, ROOT is country
on_culture_integration_25 = {
	trigger = {
		NOT = { has_variable = culture_integration_25 } # To prevent this on_action from firing multiple times for the same integrating culture as a result of an event option reducing progress
	}
	effect = {
		ordered_country_culture = {
			limit = {
				OR = {
					is_integrated = yes
					this.culture = root.culture
				}
			}
			max = 1
			check_range_bounds = no
			order_by = country_culture_pop_count
			ROOT = {
				set_variable = {
					name = biggest_country_culture_var
					value = {
						add = PREV.country_culture_pop_count
						multiply = 1.5
					}
				}
			}
		}
		remove_variable = culture_integration_75 # Remove variable in case player rapidly integrates multiple cultures faster than the variables disappear naturally
		set_variable = {
			name = culture_integration_25
			days = 730
		}
	}
	on_actions = {
		random_cultural_integration_event_25
	}
}

# Target is scope:target_culture, ROOT is country
on_culture_integration_75 = {
	trigger = {
		NOT = { has_variable = culture_integration_75 } # To prevent this on_action from firing multiple times for the same integrating culture as a result of an event option reducing progress
	}
	effect = {
		ordered_country_culture = {
			limit = {
				is_integrated = yes
			}
			max = 1
			check_range_bounds = no
			order_by = country_culture_pop_count
			ROOT = {
				set_variable = {
					name = biggest_country_culture_var
					value = PREV.country_culture_pop_count
				}
			}
		}
		remove_variable = culture_integration_25 # Remove variable in case player rapidly integrates multiple cultures faster than the variables disappear naturally
		set_variable = {
			name = culture_integration_75
			days = 730
		}
	}
	on_actions = {
		random_cultural_integration_event_75
	}
}

# Target is scope:target_culture, ROOT is country
on_culture_integration_100 = {
	
}

on_culture_increased_right = { 
#scope:target_culture = The culture being affected, has_pop_type_right will return the old pop type rights
#scope:target = The pop type, is_pop_type_right will return the new pop type right
	effect = {
		if = {
			limit = {
				scope:target_culture = {
					NOT = {
						has_country_culture_modifier = rights_increased
					}
				}
			}
			scope:target_culture = {
				add_country_culture_modifier = {
					name = rights_increased
					duration = 3650 #10 years
				}
			}
		}
		slavery_unhappiness_cleanup = yes #This removes slave_rights_imposed if culture stopped being slaves
		
		increased_rights_cleanup_effect = yes #Clears up rights that can only be held by non-integrated cultures if the culture was integrated.
	}
}

on_culture_reduced_right = {
#scope:target_culture = The culture being affected, has_pop_type_right will return the old pop type rights
#scope:target = The pop type, is_pop_type_right will return the new pop type right
	effect = {
		if = {
			limit = {
				scope:target_culture = {
					NOT = {
						has_country_culture_modifier = rights_revoked
					}
					NOT ={
						has_pop_type_right = citizen
						has_pop_type_right = nobles
					}
				}
			}
			scope:target_culture = {
				add_country_culture_modifier = {
					name = rights_revoked
					duration = 3650 #10 years
				}
			}
		}
		if = { #Citizenship revoked
			limit = {
				scope:target_culture = {
					OR ={
						has_pop_type_right = citizen
						has_pop_type_right = nobles
					}
					NOT = {
						has_country_culture_modifier = integration_status_removed
					}
				}
			}
			scope:target_culture = {
				add_country_culture_modifier = {
					name = integration_status_removed
					duration = 3650 #10 years
				}
			}
		}
		
		if = {
			limit = { scope:target_culture = { has_country_culture_modifier = rights_increased } }
			scope:target_culture = { remove_country_culture_modifier = rights_increased }
		}
		
		#Integrated to non Integrated Cleanup:
		
		reduced_rights_cleanup_effect = yes #Clears all rights that can only be held by integrated cultures if no longer integrated.
		
		# More angry if we were turned to slaves
		if = {
			limit = {
				scope:target = { is_pop_type_right = slaves }
				scope:target_culture = {
					NOT = {
						has_country_culture_modifier = slave_rights_imposed
					}
				}
			}
			scope:target_culture = {
				add_country_culture_modifier = {
					name = slave_rights_imposed
					duration = -1
				}
			}
		}
		slavery_unhappiness_cleanup = yes #This removes slave_rights_imposed if culture stopped being slaves
	}
}

on_giving_birth = {
	#scope:newborn is child, root is mother
	effect = {
		on_giving_birth_effect = yes
		scope:newborn = {
			if = {
				limit = {
					exists = employer
					exists = employer.current_ruler
					employer = { has_variable = imperial_lineage_finesse }
				}
				add_finesse = 2
			}
			if = {
				limit = {
					exists = employer
					exists = employer.current_ruler
					employer = { has_variable = imperial_lineage_zeal }
				}
				add_zeal = 2
			}
			if = {
				limit = {
					exists = employer
					exists = employer.current_ruler
					employer = { has_variable = imperial_lineage_charisma }
				}
				add_charisma = 2
			}
		}
		scope:newborn = {
			if = {
				limit = {
					exists = employer
					exists = employer.current_ruler
					employer = {
						invention = omen_power_inv_5
					}
					OR = {
						AND = {
							exists = father
							father = {
								is_deified = yes
							}
						}
						AND = {
							exists = mother
							mother = {
								is_deified = yes
							}
						}
					}
				}
				add_zeal = 1
				add_charisma = 1
				add_martial = 1
				add_finesse = 1
			}
		}
		if = {
			limit = {
				root = {
					has_variable = affair_pregnancy
				}
				employer = {
					has_land = yes
				}
			}
			root = {
				remove_variable = affair_pregnancy
			}
			scope:newborn = {
				save_scope_as = bastard_child
			}
			root.employer = {
				trigger_event = {
					id = ip_monarchy.39
				}
			}
		}
		scope:newborn = {
			if = {
				limit  = {
					NOT = {
						has_trait = lisp
					}
					is_alive = yes
				}
				random_list = {
					1 = {
						add_trait = lisp
					}
					99 = {  }
				}
			}
		}
	}
	events = {
		character_events.5
	}
	random_events = {
		1 = health.1
		1 = health.3
		1 = health.4
		30 = 0
		30 = health.5
	}
}

on_being_born = {
    effect = {
        inbreeding_effect = yes
        trigger_event = {
            id = character_events.35
            days = 1
        }
    }
}

on_zero_health = {
	effect = {
		clear_ambition_effect = yes
	}
	events = {
		death.1
	}
}

on_becoming_adult = {
	effect = {
		on_becoming_adult_effect = yes
		set_variable = {
			name = ambition_tombola
			value = { 
				integer_range = { 
					min = 1 
					max = 7
				} 
			}
			days = 10
		}
		if = {
			limit = {
				this = char:70
			}
			pyrrhus_of_age_effect = yes
		}
		if = {
			limit = {
				has_variable = ip_mon_47_regent_child
				is_ruler = yes
			}
			save_scope_as = ip_mon_47_heir
			random_country = {
				limit = {
					has_variable = ip_mon_47_regency
					current_ruler = {
						this = root
					}
				}
				trigger_event = {
					id = ip_monarchy.52
				}
			}
		}
	}
	events = {
		character_events.53
	}
}

on_winning_war = {
	effect = {
	}
	events = {
	}
}

on_losing_war = {
	effect = {
	}
	events = {

	}
	
}

on_ending_war = {
	effect = {
		if = {
			limit = {
				tag = TRE
				any_ended_war = {
					any_war_attacker = { THIS = c:TRE }
					any_war_defender = { THIS = c:GTE }
				}
			}
			c:TRE = {
				trigger_event = me_thrace_2_paper_kingdom.33
			}
		}
		if = {
			limit = {
				NOT = {
					tag = EPI
				}
				is_diadochus_trigger = yes
				char:70 = {
					employer = ROOT
				}
			}
			root = {
				trigger_event = {
					id = dhe_dde_pyrrhus.3
				}
			}
		}
	}
	events = {
		ip_republic.34
	}
}

dictator_power_return = {
	random_events = {
		85 = ip_republic.23
		15 = ip_republic.32
	}
}

on_being_captured = {
	effect = {
		if = {
			limit = {
				is_mercenary = no
			}
			set_variable = {
				name = came_from
				value = employer
			}
		}
		clear_ambition_effect = yes
	}
	events = {
		character_events.4
	}
}

on_being_ransomed_back = {
	effect = {
		remove_character_modifier = foreign_citizen
	}
}

on_being_released = {

}

on_enacting_omen = {
	events = {
		me_diadochi_empire_events.2
	}
}

on_change_pantheon = {
	events = {
		me_diadochi_empire_events.2
	}
}

on_being_imprisoned = {
	effect = {
		clear_ambition_effect = yes
		if = {
			limit = { has_variable = me_syr_democracy_leader }
			remove_variable = me_syr_democracy_leader
			clear_saved_scope = democracy_leader
			save_scope_as = old_democracy_leader
			employer = {
				trigger_event = { id = me_syracuse_1_democracy.2 }
			}
		}
		if = {
			limit = { 
				has_variable = me_syr_foreign_leader_flag
				c:SYR = { has_variable = death_to_tyrants_flag }
			}
			remove_variable = me_syr_foreign_leader_flag
			save_scope_as = me_syracuse_old_foreign_request_character_scope
			if = {
				limit = {
					employer = {
						NOT = { tag = SYR }
					}
				}
				employer = {
					trigger_event = {
						id = me_syracuse_1_democracy.12
						days = 3
					}
				}
			}
			if = {
				limit = { has_character_modifier = indisposed_charmod }
				hidden_effect = { remove_character_modifier = indisposed_charmod }
			}
			c:SYR = {
				trigger_event = {
					id = me_syracuse_1_democracy.12
					days = 3
				}
			}
		}
		if = {
			limit = { 
				has_variable = me_syr_heir_flag
				c:SYR = { has_variable = death_to_tyrants_flag }
				employer = {
					tag = SYR
					OR = {
						var:ongoing_revolutionary_route = 6
						AND = {
							has_completed_mission_task = syracuse_1_6_approach_heir
							NOT = { has_completed_mission_task = syracuse_1_7_assassinate }
						}
					}
				}
			}
			remove_variable = me_syr_heir_flag
			save_scope_as = me_syr_heir_scope
			c:SYR = {
				trigger_event = { id = me_syracuse_1_democracy.73 }
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_1_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_1_flag
			if = {
				limit = { 
					employer = { has_variable = gm_1_greek_country_flag }
				}
				employer = {
					trigger_event = { id = me_greek_1_black_sea.13 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_3_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_3_flag
			if = {
				limit = { 
					employer = { has_variable = gm_3_greek_country_flag }
				}
				employer = {
					trigger_event = { id = me_greek_3_italiote.26 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_4_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_4_flag
			if = {
				limit = { 
					employer = { has_variable = gm_4_greek_country_flag }
				}
				employer = {
					trigger_event = { id = me_greek_4_west.3 }
				}
			}
		}
		if = {
			limit = { has_variable = betrothed_flag }
			remove_variable = betrothed_flag
		}
	}
	events = {
		character_events.17
	}
}

on_move_country = { #scope:old_country is the origin country
	effect = {
		befriend_removal_effect = yes
		clear_befriending_var_effect = yes
		clear_ambition_effect = yes
		clear_loyalty_effect = yes
		if = {
			limit = { num_loyal_veterans > 0 }
			hidden_effect = {
				while = {
					limit = { num_loyal_veterans > 0 }
					add_loyal_veterans = -1
				}
			}
		}
		remove_espionage_variables_effect = yes
		if = {
			limit  = {
				has_character_modifier = inspire_disloyalty_modifier
			}
			remove_character_modifier = inspire_disloyalty_modifier
		}
		if = {
			limit = {
				has_variable = imprisoned_manually
			}
			remove_variable = imprisoned_manually
		}
		if = {
			limit = {
				has_triggered_character_modifier = disloyal_family_head_cmod
			}
			remove_triggered_character_modifier = disloyal_family_head_cmod
		}
		if = {
			limit = {
				has_variable = disloyal_family_head_var
			}
			remove_variable = disloyal_family_head_var
		}
		if = {
			limit = {
				has_variable = prominent_actor
			}
			remove_variable = prominent_actor
		}
		if = {
			limit = {
				has_character_modifier = increased_family_wages
			}
			remove_character_modifier = increased_family_wages
		}
		if = {
			limit = {
				is_mercenary = yes
				has_variable = pretender_from
				exists = var:pretender_from
				var:pretender_from = {
					has_land = yes
				}
				var:pretender_from = employer
				employer = {
					is_monarchy = yes
					has_land = yes
				}
			}
			save_scope_as = returning_pretender
			employer = {
				trigger_event = {
					id = succession_crisis.3
					days = { 1 720 }
				}
			}
		}
		if = {
			limit = {
				is_mercenary = no
			}
			set_variable = {
				name = came_from
				value = scope:old_country
			}
		}
		if = {
			limit = {
				num_holdings_owned > 0
				NOR = {
					has_trait = olympic_competitor
					employer = c:MER
				}
				employer = {
					has_civil_war = no
				}
			}
			every_holdings = {
				root = {
					remove_holding = prev
				}
			}
		}
		if = {
			limit = {
				prominence > 0
				NOT = {
					has_trait = olympic_competitor
				}
			}
			add_prominence = {
				value = 0
				subtract = prominence
			}
		}
		if = {
			limit = {
				popularity > 0
			}
			add_popularity = {
				value = 0
				subtract = {
					value = popularity
					divide = 2
				}
			}
		}
		if = {
			limit = { 
				has_variable = me_syr_democracy_leader
				employer = {
					NOT = { has_variable = me_syr_demo_civil_war_active }
				}
			}
			remove_variable = me_syr_democracy_leader
			clear_saved_scope = democracy_leader
			save_scope_as = old_democracy_leader
			employer = {
				trigger_event = { id = me_syracuse_1_democracy.2 }
			}
		}
		if = {
			limit = { 
				has_variable = me_syr_heir_flag
				c:SYR = { 
					has_variable = death_to_tyrants_flag
					NOR = {
						has_variable = me_syr_demo_civil_war_active 
						has_civil_war = yes
					}
					OR = {
						var:ongoing_revolutionary_route = 6
						AND = {
							has_completed_mission_task = syracuse_1_6_approach_heir
							NOT = { has_completed_mission_task = syracuse_1_7_assassinate }
						}
					}
				}
			}
			remove_variable = me_syr_heir_flag
			save_scope_as = me_syr_heir_scope
			c:SYR  = {
				trigger_event = { id = me_syracuse_1_democracy.73 }
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_1_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_1_flag
			if = {
				limit = { 
					var:came_from = { has_variable = gm_1_greek_country_flag }
				}
				var:came_from = {
					trigger_event = { id = me_greek_1_black_sea.13 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_3_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_3_flag
			if = {
				limit = { 
					var:came_from = { has_variable = gm_3_greek_country_flag }
				}
				var:came_from = {
					trigger_event = { id = me_greek_3_italiote.26 }
				}
			}
		}
		if = {
			limit = { 
				has_variable = gm_family_head_4_flag
			}
			save_scope_as = gm_old_family_head
			remove_variable = gm_family_head_4_flag
			if = {
				limit = { 
					var:came_from = { has_variable = gm_4_greek_country_flag }
				}
				var:came_from = {
					trigger_event = { id = me_greek_4_west.3 }
				}
			}
		}
		if = {
			limit = { has_variable = archimedes_flag }
			if = {
				limit = { 
					scope:old_country = { has_country_modifier = archimedes_modifier }
				}
				scope:old_country = { remove_country_modifier = archimedes_modifier }
			}
		}
		if = {
			limit = { has_variable = betrothed_flag }
			remove_variable = betrothed_flag
		}
		trigger_event = {
			id = warfare.13
			days = 2
		}
	}
	events = {
		character_events.4
		character_events.16 
	}
}

on_game_initialized = {
	effect = {
		### Unique Mechanics ###
		startup_variables_unique_mechanics_effect = yes
		### Unique Deities ###
		startup_variables_unique_deities_effect = yes
		### Achievement Checks ###
		startup_variables_achievement_effect = yes
		### Cultural Minority Rights ###
		startup_cultural_decisions_effect = yes
		### Other ###
		if = {
			limit = {
				has_law = work_for_the_best
			}
			set_legion_recruitment = capital
		}
		add_innovation = {
			value = oratory_tech
		}
		add_innovation = {
			value = military_tech
		}
		add_innovation = {
			value = civic_tech
		}
		add_innovation = {
			value = religious_tech
		}
		if = {
			limit = { tag = PRY }
			current_ruler = {
				add_rival = C:EGY.current_ruler
				add_rival = C:SEL.current_ruler
				add_rival = C:MAC.current_ruler
			}
			char:97 = {
				add_friend = char:38
			} 
			random_navy = {
				add_subunit = mega_galley
				add_subunit = mega_galley
				add_subunit = mega_galley
				add_subunit = octere
				add_subunit = octere
				add_subunit = octere
				add_subunit = octere
				add_subunit = octere
			}
			set_variable = me_ant_start_flag
			antigonid_legion_setup_effect = yes
			add_opinion = { target = c:MAC modifier = diadochi_rivals }
			add_opinion = { target = c:TRE modifier = diadochi_rivals }
			add_opinion = { target = c:EGY modifier = diadochi_rivals }
			add_opinion = { target = c:SEL modifier = diadochi_rivals }
		}
		if = {
			limit = { tag = MAC }
			char:32 = {
				trigger_event = {
					id = dhe_macedon.1 # Cassander illness
					days = { 700 760 } # 2 years
				}
			}
			char:288 = {
				trigger_event = {
					id = dhe_macedon.2 # Philip IV illness
					days = { 1400 1520 } # 4 years
				}
			}
			add_opinion = {
				modifier = pyrrhos_crowned_opmod
				target = c:EPI
			}
			current_ruler = {
				add_rival = C:PRY.current_ruler
				add_friend = C:TRE.current_ruler
			}
			char:10 = { move_country = C:PRY } #Antipatrid mother
			char:97 = { move_country = C:PRY } #Mithridates in Phrygia
			set_variable = me_mac_start_flag
			macedon_legion_setup_effect = yes
			add_opinion = { target = c:PRY modifier = diadochi_rivals }
			add_opinion = { target = c:TRE modifier = diadochi_rivals }
			add_opinion = { target = c:EGY modifier = diadochi_rivals }
			add_opinion = { target = c:SEL modifier = diadochi_rivals }
		}
		if = {
			limit = { tag = TRE }
			current_ruler = {
				add_friend = C:MAC.current_ruler
			}
			set_variable = me_thrace_start_flag
			thrace_legion_setup_effect = yes
			add_opinion = { target = c:MAC modifier = diadochi_rivals }
			add_opinion = { target = c:PRY modifier = diadochi_rivals }
			add_opinion = { target = c:EGY modifier = diadochi_rivals }
			add_opinion = { target = c:SEL modifier = diadochi_rivals }
		}
		if = {
			limit = { tag = EGY }
			current_ruler = {
				add_rival = C:PRY.current_ruler
				add_friend = C:SEL.current_ruler
			}
			egypt_legion_setup_effect = yes
			trigger_event = dhe_body.4
			add_opinion = { target = c:MAC modifier = diadochi_rivals }
			add_opinion = { target = c:TRE modifier = diadochi_rivals }
			add_opinion = { target = c:PRY modifier = diadochi_rivals }
			add_opinion = { target = c:SEL modifier = diadochi_rivals }
		}
		if = {
			limit = { tag = SEL }
			current_ruler = {
				add_rival = C:PRY.current_ruler
				add_friend = C:EGY.current_ruler
			}
			trigger_event = { id = country_rename.2 }
			seleukid_legion_setup_effect = yes
			add_opinion = { target = c:MAC modifier = diadochi_rivals }
			add_opinion = { target = c:TRE modifier = diadochi_rivals }
			add_opinion = { target = c:EGY modifier = diadochi_rivals }
			add_opinion = { target = c:PRY modifier = diadochi_rivals }
		}
		if = {
			limit = { tag = EPI }
			if = {
				limit = {
					NOT = { has_dlc = "Epirus Flavor Pack" }
				}
				trigger_event = {
					id = flavor_epi.1
					days = { 180 365 }
				}
			}
			if = {
				limit = { has_dlc = "Epirus Flavor Pack" }
				trigger_event = { id = dhe_dde_pyrrhus.40 }
				trigger_event = {
					id = dhe_dde_pyrrhus.1
					days = 730
				}
			}
			current_ruler = { add_friend = c:TLN.current_ruler } # Pyrrhos and Glaukias
			set_variable = me_epirus_start_flag
			epirus_legion_setup_effect = yes
		}
		if = {
			limit = { tag = TLN }
			current_ruler = {
				add_rival = c:MAC.current_ruler # Glaukias and Kassandros
			}
		}
		if = {
			limit = { tag = KIO }
			set_variable = kios_start_flag
		}
		if = {
			limit = { tag = SYR }
			set_variable = me_syracuse_start_flag
			random_navy = {
				add_subunit = octere
				add_subunit = octere
			}
			current_ruler = { 
				add_friend = char:319
				add_friend = char:264 
			}
			p:84 = {
				trigger_event = {
					id = flavor_syr.1
					days = { 13505 15695 } # 37 - 43 years
				}
			}
			trigger_event = {
				id = flavor_syr.3
				days = { 180 365 }
			}
		}
		if = {
			limit = { tag = SAM }
			add_opinion = {
				modifier = recent_conflicts
				target = c:ROM
			}
		}
		if = {
			limit = { tag = ROM }
			add_opinion = {
				modifier = recent_conflicts
				target = c:SAM
			}
		}
		if = {
			limit = { tag = SPA }
			add_opinion = {
				modifier = recent_conflicts
				target = c:MSE
			}
		}
		if = {
			limit = { tag = MSE }
			add_opinion = {
				modifier = recent_conflicts
				target = c:SPA
			}
		}
		if = {
			limit = { tag = ELI }
	        set_global_variable = {
	            name = olympic_counter_global_var
	            value = 119
	        }
			p:439 = {
				add_permanent_province_modifier = {
					name = olympic_games_modifier
					duration = -1
				}
				set_variable = {
					name = olympics_countdown # for debugging
					days = 1287
				}
				trigger_event = {
					id = olympic.12
					days = 1287 # 11 Apr 300 BC/454 AUC
				}
			}
		}
		if = {
			limit = {
				OR = {
					rank = local_power
					rank = regional_power
					rank = major_power
					rank = great_power
				}
				num_of_cities > 15
			}
			every_family = {
				ROOT = {
					random_owned_province = {
						limit = {
							is_capital = no
							NOT = {
								exists = holding_owner
							}
						}
						save_scope_as = first_holding
						weight = {
							modifier = {
								factor = 100000
								any_neighbor_province = {
									NOT = { exists = holding_owner }
								}
							}
						}
					}
				}
				head_of_family = {
					add_holding = scope:first_holding
				}
			}
		}

		# Thrace Odrysians timer

		if = {
			limit = {
				tag = TRE
				has_dlc = "Heirs of Alexander"
        		has_land = yes
			}
			set_variable = {
				name = thracian_mission_02_paper_kingdom_ODR_revolt_timer
				days = 7300
			}
		}
		
		#More for the bigger tags!
		
		if = {
			limit = {
				rank = regional_power
			}
			every_family = {
				head_of_family = { save_scope_as = hof }
				while = {
					count = 3
					ROOT = {
						random_owned_province = {
							limit = {
								is_capital = no
								OR = {
									NOT = {
										exists = holding_owner
									}
									AND = {
										exists = holding_owner
										holding_owner = {
											is_alive = no
										}
									}
								}
							}
							weight = {
								modifier = {
									factor = 10000
									any_neighbor_province = {
										trigger_if = {
											limit = {
												exists = holding_owner
											}
											holding_owner = scope:hof
										}
										trigger_else = {
											always = no
										}
									}
								}
							}
							save_scope_as = buy_holding_target
						}
					}
					head_of_family = {
						add_holding = scope:buy_holding_target
					}
				}
			}
		}
		else_if = {
			limit = {
				rank = major_power
			}
			every_family = {
				head_of_family = { save_scope_as = hof }
				while = {
					count = 10
					ROOT = {
						random_owned_province = {
							limit = {
								is_capital = no
								OR = {
									NOT = {
										exists = holding_owner
									}
									AND = {
										exists = holding_owner
										holding_owner = {
											is_alive = no
										}
									}
								}
							}
							weight = {
								modifier = {
									factor = 10000
									any_neighbor_province = {
										trigger_if = {
											limit = {
												exists = holding_owner
											}
											holding_owner = scope:hof
										}
										trigger_else = {
											always = no
										}
									}
								}
							}
							save_scope_as = buy_holding_target
						}
					}
					head_of_family = {
						add_holding = scope:buy_holding_target
					}
				}
			}
		}
		else_if = {
			limit = {
				rank = great_power
			}
			every_family = {
				head_of_family = { save_scope_as = hof }
				while = {
					count = 20
					ROOT = {
						random_owned_province = {
							limit = {
								is_capital = no
								OR = {
									NOT = {
										exists = holding_owner
									}
									AND = {
										exists = holding_owner
										holding_owner = {
											is_alive = no
										}
									}
								}
							}
							weight = {
								modifier = {
									factor = 10000
									any_neighbor_province = {
										trigger_if = {
											limit = {
												exists = holding_owner
											}
											holding_owner = scope:hof
										}
										trigger_else = {
											always = no
										}
									}
								}
							}
							save_scope_as = buy_holding_target
						}
					}
					head_of_family = {
						add_holding = scope:buy_holding_target
					}
				}
			}
		}
	} 
	events = {
		syr_flavour.1
		flavor_sel.1
		startup_events.1
		startup_events.2
		startup_events.7
		startup_events.8
		tutorial.1
		dhe_dde_pyrrhus.24
		flavor_egy.8
		dhe_heraclea_pontica.1
	}
}

on_province_colonized = {
	events = {
		dhe_rome.20
	}
}

on_ownership_change = { #province scope
	effect = {
		if = {
			limit = {
				is_iron_man = yes
				exists = owner
				owner = {
					is_ai = no
					has_land = yes
				}
			}
			owner = {
				if = {
					limit = {
						NOT = {
							has_variable = ach_render_unto_caesar_var
						}
					}
					set_variable = {
						name = ach_render_unto_caesar_var
					}
				}
			}
		}
		if = {
			limit = {
				exists = owner
				owner = {
					has_land = yes
					tag = ROM
				}
				has_variable = roman_colonia_flag
				NOR = {
					has_province_modifier = italian_colonia_military_pmod
					has_province_modifier = italian_colonia_civic_pmod
					has_province_modifier = italian_colonia_religious_pmod
					has_province_modifier = italian_colonia_trade_pmod
					has_province_modifier =  italian_colonia_pmod
				}
			}
			trigger_event = {
				id = me_roman_1_roman_italia.26
			}
		}
		if = {
			limit = {
				exists = holding_owner
			}
			holding_owner = {
				remove_holding = root
			}
		}
		if = {
			limit = { has_variable = sm_rebel_base }
			save_scope_as = sm_old_base
			remove_variable = sm_rebel_base
			if = {
				limit = {
					c:SYR = { has_land = yes }
				}
				c:SYR = {
					trigger_event = { id = me_syracuse_1_democracy.21 }
				}
			}
		}
		if = {
			limit = {
				any_in_list = {
					list = gm_1_hellenic_liberation_list
					this = root
				}
			}
			if = {
				limit = {
					OR = {
						AND = {
							has_owner = yes
							owner = {
								country_culture_group = hellenic
							}
						}
						has_owner = no
					}
				}
				remove_from_list = gm_1_hellenic_liberation_list
			}
			if = {
				limit = { has_variable = gm_1_bartered_flag }
				remove_variable = gm_1_bartered_flag
			}
		}
		if = {
			limit = { 
				has_owner = yes 
				has_variable = me_epi_2_rome_cap_flag
				exists = scope:me_epirus_scope
				owner = scope:me_epirus_scope
				NOT = {
					scope:me_epirus_scope = { has_variable = me_epi_2_captured_flag }
				}
			}
			scope:me_epirus_scope = { set_variable = me_epi_2_captured_flag }
		}
	}
	events = {
		dhe_city_fall.1
		dhe_city_fall.2
		dhe_city_fall.3
		dhe_city_fall.4
		dhe_city_fall.5
		dhe_city_fall.6
		dhe_city_fall.7
		dhe_city_fall.8
		dhe_city_fall.9
		dhe_city_fall.10
		dhe_city_fall.11
		dhe_city_fall.12
		dhe_city_fall.13
		dhe_city_fall.14
		dhe_city_fall.15
		dhe_city_fall.16
		dhe_city_fall.17
		dhe_city_fall.100
		dhe_body.3
		dhe_carthage.4
		dhe_carthage.6
		dhe_carthage.10
		dhe_carthage.11
		dhe_carthage.12
		comet.2
		dhe_rome.20
	}
}

on_province_occupied = { #province scope, it will fire AS WELL as on_siege_won
	effect = {
		if = {
			limit = {
				this = p:3256
				this = c:CAR.capital_scope
				exists = scope:me_syracuse_scope
				controller = scope:me_syracuse_scope
				OR = {
					controller = scope:gm_2_greek_scope
					controller = { is_subject_of = scope:me_syracuse_scope }
				}
			}
			scope:me_syracuse_scope = { set_variable = syr_occupied_carthage_flag }
		}
		if = {
			limit = {
				this = p:428
				exists = scope:gm_2_greek_scope
				OR = {
					controller = scope:gm_2_greek_scope
					controller = { is_subject_of = scope:gm_2_greek_scope }
				}
			}
			scope:gm_2_greek_scope = { set_variable = me_gre_2_14_flag }
		}
		if = {
			limit = { 
				has_owner = yes 
				has_variable = me_epi_2_rome_cap_flag
				exists = scope:me_epirus_scope
				controller = scope:me_epirus_scope
				NOT = {
					scope:me_epirus_scope = { has_variable = me_epi_2_captured_flag }
				}
			}
			scope:me_epirus_scope = { set_variable = me_epi_2_captured_flag }
		}
	}
	events = {
		fire_events.1
		slave_revolts.2 #Interactive Looting
		slave_revolts.5 #Interactive Looting of capital
	}
}

on_great_battle_won_country = { #root = country scope of the main unit on the winning side, scope:actor = main unit on the winning side, scope:target = main unit on the losing side
	effect = {
		if = {
			limit = {
				scope:actor = {
					exists = commander
				}
			}
			scope:actor.commander = {
				set_variable = {
					name = great_battle_won_flag
					days = 720
				}
				trigger_event = {
					on_action = custom_on_great_battle_commander
				}
			}
		}
		if = {
			limit = {
				scope:target.unit_owner = c:REB #All REB stacks are slave stacks
			}
			scope:target.unit_location = { #Where did the rebels die?
				if = {
					limit = {
						has_owner = yes #If the slaves wandered into no mans land and died there they are lost.
					}
					owner = { #The country in which the Slaves were crushed.
						save_scope_as = country_dealing_with_slave_revolt
						if = {
							limit = {
								has_country_modifier = ongoing_slave_revolt
							}
							remove_country_modifier = ongoing_slave_revolt #Right away
						}
						set_local_variable = {
							name = slaves_defeated
							value = { value = scope:target.unit_size }
						}
						trigger_event = { id = slave_revolts.3 }
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					exists = commander
					commander = {
						this = char:70
						is_alive = yes
						is_ruler = yes
						is_general = yes
						NOT = { has_variable = pyrrhus_fallback_return_flag }
						employer = { has_land = yes }
					}
				}
				scope:target = {
					exists = commander
					commander = {
						is_alive = yes
						OR = {
							has_trait = daring
							has_trait = brave
							has_trait = reckless
							has_trait = proud
						}
					}
				}
			}
			trigger_event = { id = dhe_dde_pyrrhus.33 }
		}
		if = {
			limit = {
				scope:actor = {
					exists = commander
					commander = {
						this = char:70
						is_alive = yes
						is_ruler = yes
						is_general = yes
						NOT = { has_variable = pyrrhus_fallback_return_flag }
						employer = { has_land = yes }
						NOT = { has_trait = cautious }
					}
				}
				scope:target.unit_owner = {
					country_culture_group = latin
					capital_scope = {
						OR = {
							is_in_region = central_italy_region
							is_in_region = magna_graecia_region
						}
					}
				}
			}
			trigger_event = { id = dhe_dde_pyrrhus.36 }
		}
		if = {
			limit = {
				scope:actor = { has_legion_trigger = yes }
			}
			if = {
				limit = { exists = scope:actor.commander }
				scope:actor.legion = {
					add_legion_history = {
						key = great_battle_won_history
						commander = scope:actor.commander
						province = scope:actor.unit_location
					}
				}
			}
			else = {
				scope:actor.legion = {
					add_legion_history = {
						key = great_battle_won_history
						commander = scope:actor.unit_owner.current_ruler
						province = scope:actor.unit_location
					}
				}
			}
		}
	}
	events = {
		distinction.19
	}
	random_events = {
		100 = 0
		50 = ip_monarchy.60
		50 = ip_monarchy.61
		10 = distinction.1
		10 = distinction.2
		10 = distinction.3
		10 = distinction.4
		10 = distinction.5
		10 = distinction.8
		10 = distinction.9
		5 = distinction.13
		10 = distinction.14
		10 = distinction.15
		15 = distinction.16
		10 = distinction.18
		5 = distinction.20
	}
	
}

on_battle_won_country = { #root = country scope of the main unit on the winning side, scope:actor = main unit on the winning side, scope:target = main unit on the losing side
	events = {
	}
	effect = {
		if = {
			limit = {
				scope:target.unit_owner = c:REB #All REB stacks are slave stacks
			}
			scope:target.unit_location = { #Where did the rebels die?
				if = {
					limit = {
						has_owner = yes #If the slaves wandered into no mans land and died there they are lost.
					}
					scope:target = { #Cleanup origin
						if = {
							limit = {
								has_variable = slave_army_origin
								var:slave_army_origin = {
									has_land = yes
								}
							}
							var:slave_army_origin = {
								if = {
									limit = {
										has_country_modifier = ongoing_slave_revolt
									}
									remove_country_modifier = ongoing_slave_revolt
								}
								every_owned_province = {
									limit = { controller = c:REB }
									set_controller = var:slave_army_origin
								}
							}
						}
					}
					owner = { #The country in which the Slaves were crushed.
						save_scope_as = country_dealing_with_slave_revolt
						if = {
							limit = {
								has_country_modifier = ongoing_slave_revolt
							}
							remove_country_modifier = ongoing_slave_revolt #Right away
						}
						set_local_variable = {
							name = slaves_defeated
							value = { value = scope:target.unit_size }
						}
						trigger_event = { id = slave_revolts.3 }
					}
				}
				else = {
					scope:target = { #Cleanup origin
						if = {
							limit = {
								has_variable = slave_army_origin
								var:slave_army_origin = {
									has_land = yes
								}
							}
							var:slave_army_origin = {
								if = {
									limit = {
										has_country_modifier = ongoing_slave_revolt
									}
									remove_country_modifier = ongoing_slave_revolt
								}
								every_owned_province = {
									limit = { controller = c:REB }
									set_controller = var:slave_army_origin
								}
							}
						}
					}
					scope:actor.unit_owner = { #Deal with it for actor
						save_scope_as = country_dealing_with_slave_revolt
						set_local_variable = {
							name = slaves_defeated
							value = { value = scope:target.unit_size }
						}
						trigger_event = { id = slave_revolts.3 }
					}
					
				}
			}
		}
	}
}

on_great_battle_lost_country = { #root = country scope of the main unit on the losing side, scope:actor = main unit on the losing side, scope:target = main unit on the winning side
	effect = {
		if = {
			limit = {
				scope:actor = { has_legion_trigger = yes }
			}
			if = {
				limit = { exists = scope:actor.commander }
				scope:actor.legion = {
					add_legion_history = {
						key = great_battle_lost_history
						commander = scope:actor.commander
						province = scope:actor.unit_location
					}
				}
			}
			else = {
				scope:actor.legion = {
					add_legion_history = {
						key = great_battle_lost_history
						commander = scope:actor.unit_owner.current_ruler
						province = scope:actor.unit_location
					}
				}
			}
		}
	}
	random_events = {
		95 = 0
        5 = dhe_rome.19
        50 = ip_monarchy.62
        50 = ip_monarchy.63
        10 = distinction.21
	}
}

on_battle_lost_country = { #root = country scope of the main unit on the losing side, scope:actor = main unit on the losing side, scope:target = main unit on the winning side
	events = {
		dhe_rome.14
	}
	random_events = {
		199 = 0
		1 = dhe_rome.19
	}
}

# scope is country being annexed
# scope:actor = country doing the annexing
on_military_annex = {
	effect = {
		every_country_treasure = {
			add_to_list = annexed_treasures
		}
		on_annexation_event_effect = yes
		if = {
			limit = {
				OR = {
					has_variable = me_syr_foreign_country_flag
					has_variable = me_syr_deal_with_devil_flag
				}
			}
			save_scope_as = me_syr_annexed_scope
			if = {
				limit = {
					any_country = { has_variable = death_to_tyrants_flag }
				}
				random_country = {
					limit = { has_variable = death_to_tyrants_flag }
					trigger_event = { id = me_syracuse_1_democracy.60 }
				}
			}
		}
	}
}

on_diplomatic_annex = {
	effect = {
		every_country_treasure = {
			add_to_list = annexed_treasures
		}
		on_diplo_annexation_event_effect = yes
	}
}

on_civil_war_annex = {
	effect = {
		on_annexation_event_effect = yes
	}
}


on_invention = {
	effect = {
		if = {
			limit = {
				is_tutorial_active = yes
			}
			set_variable = {
				name = invention_purchased
			}
		}
		if = {
			limit = {
				is_iron_man = yes
				is_ai = no
				has_land = yes
			}
			if = {
				limit = {
					NOT = {
						has_variable = ach_circles_var
					}
				}
				set_variable = {
					name = ach_circles_var
					value = 1
				}
			}
			else = {
				change_variable = {
					name = ach_circles_var
					add = 1
				}
			}
		}
	}
}

# Scope is the governor getting his policy changed
on_policy_change = {
	effect = {
		if = {
			limit = { is_ruler = no }
			employer = { 
				add_tyranny = {
					value = 125
					subtract = root.employer.current_ruler.popularity
					multiply = 0.01
				}
			}
		}
	}
}


# Scope is character losing holding, with target the province lost.
on_holding_lost = {
	#effect = {
		#if = { #Deprecated
		#	limit = {
		#		is_alive = yes
		#	}
		#	add_character_modifier = {
		#		name = holding_lost
		#		duration = 1825
		#		mode = extend
		#	}
		#}
	#}
}

#character yearly pulses
disease_possibilities = {
	trigger = {
		is_alive = yes
		exists = employer
		has_any_tier_1_2_3_illness_trigger = yes
	}
	random_events = {
		10 = traits.8
		10 = traits.10
		10 = traits.11
		10 = traits.12
		10 = traits.14 
		10 = traits.15 
		150 = 0
	}	
}

treatment_pulse = {
	trigger = {
		is_alive = yes
		has_variable = seeking_treatment
	}
	random_events = {
		60 = treatment.2
		10 = treatment.5
	}
}

character_story_events = 
{
	random_events = 
	{
		200 = 0
		#Internal politics events
		2 = ip_generic.1
		1 = ip_generic.3
		1 = ip_generic.4
		1 = ip_generic.5
		1 = ip_republic.4
		1 = ip_republic.18
		2 = ip_republic.19
		#Get friends/rivals events
		2 = friend_rival.15
		#Mentor/Mentee events
		2 = friend_rival.7
		2 = friend_rival.8
		2 = friend_rival.9
		2 = friend_rival.10
		# Tribal Pol events
		50 = tribal_pol.24
		# Cult of Fortune events
		1 = dhe_fortune_cult.10
		1 = dhe_fortune_cult.11
		# Isis Cult events
		3 = dhe_isis_cult.10
		1 = dhe_isis_cult.11
		1 = dhe_isis_cult.12
		1 = dhe_isis_cult.13
		1 = dhe_isis_cult.14
		# Eleusinian Mysteries
		1 = me_athens_02_attica.16
		# Other
		3 = character_events.14
		200 = character_events.18
		1 = ip_monarchy.21
		1 = ip_monarchy.25
		1 = ip_monarchy.41
		1 = ip_monarchy.38
	}
}

character_traits_pulse = 
{
	random_events = 
	{
		1000 = 0
		300 = traits.1
		2 = traits.2
	}

}

yearly_medical_pulse = 
{
	random_events = 
	{
		150 = 0
		#Illness
		4 = traits.4
		2 = traits.6
		2 = traits.8
		1 = health.6 # depression
		4 = health.7 # getting better from depression
		30 = death.2 # old age
		1 = traits.18
	}
}

yearly_debt_pulse = {
	trigger = {
		wealth < 0
		prisoner = no
		is_adult = yes
	}
	random_events = {
		20 = 0
		20 = character_events.10
		20 = character_events.12
		20 = character_events.13
		20 = character_events.19
	}
}

yearly_culture_religion_switch_pulse = {
	random_events = {
		98 = 0
		1 = character_events.21
		1 = character_events.22
		2 = character_events.23
		2 = character_events.24
	}
}

yearly_character_murder_pulse = {
	events = {
	
	}
}


yearly_disloyal_generals_delay_pulse = {
	trigger = {
		is_general = yes
		loyalty <= 50
		NOT = {
			has_character_modifier = disloyal_successor_cmod
		}
	}
	random_events = {
		50 = 0
		50 = commander_loyalty.4
	}
}

yearly_financial_support_pulse = {
	random_events = {
		100 = 0
		50 = character_events.36
		50 = character_events.37
	}
}

on_subject_defect = { #scope:future_overlord = country that stole vassal, scope:target_subject  = vassal being stolen
	effect = {
		add_opinion = {
			modifier = stole_a_vassal_from_us
			target = scope:future_overlord
		}
		
		add_opinion = {
			modifier = free_from_old_overlord
			target = scope:target_subject
		}
	}
}

on_great_work_anniversary = {
	events = {
	}
}

on_great_work_completed = {	
	effect = {
		trigger_event = {
			id = "gw_existing.2"
			days = 1825
        }
		
		if = {
			limit = {
				is_iron_man = yes
				is_ai = no
				has_land = yes
			}
			if = {
				limit = {
					NOT = {
						has_variable = ach_gw_built_var
					}
				}
				set_variable = {
					name = ach_gw_built_var
					value = 1
				}
			}
			else = {
				change_variable = {
					name = ach_gw_built_var
					add = 1
				}
			}
		}
	}
	events = {
		gw_completed.1
		gw_completed.2
		gw_completed.3
	}
}

on_great_work_destroyed = {
#scope:target = the builder of the destroyed great work
	effect = {
		if = {
			limit = {
				NOT = { scope:target = root }
				is_iron_man = yes
				is_ai = no
				has_land = yes
			}
			if = {
				limit = {
					NOT = {
						has_variable = ach_gw_destroyed_var
					}
				}
				set_variable = {
					name = ach_gw_destroyed_var
					value = 1
				}
			}
			else = {
				change_variable = {
					name = ach_gw_destroyed_var
					add = 1
				}
			}
		}
	}
}

on_action_requiring_senate_approval = { #If you change this, also change the scripted effect: change_religion_effect
	effect = {
		if = {
			limit = {
				has_senate_approval < define:NPolitics|SENATE_REQUIRED_APPROVAL_WITHOUT_PENALTIES
				is_republic = yes
				is_ai = no
				NOT = { has_variable = dictatorship_enabled }
				NOT = { has_variable = one_senatorial_bypass }
			}
			add_tyranny = {
				# Calculates the percentage of disapproval
				value = define:NPolitics|SENATE_REQUIRED_APPROVAL_WITHOUT_PENALTIES
				subtract = has_senate_approval
				divide = define:NPolitics|SENATE_REQUIRED_APPROVAL
				
				# This is the real value that you want for 100% of the effect
				multiply = 20
			}
		}
		if = {
			limit = { has_variable = one_senatorial_bypass }
			custom_tooltip = senatorial_bypass_spent_tt
			remove_variable = one_senatorial_bypass
			set_ignore_senate_approval = no
		}
	}
}

on_legion_raised = {
   # what: on the end of the day after a legion is created
   # scope: legion
   effect = {
	   	if = {
	   		limit = { # stop starting legions from receiving events/history entries
	   			has_dlc = "Heirs of Alexander"
	   			NAND = {
	   				current_date < 450.10.10
	   				OR = {
		   				any_legion_commander = {
		   					OR = {
		   						THIS = char:38 # Demetrios/Antigonids
		   						THIS = char:26 # Antiochus/Seleukids
		   						THIS = char:46 # Magas/Egypt
		   						THIS = char:149 # Philippos/Macedon
		   						THIS = char:368 # Alkimachos/Thrace
		   						THIS = char:118 # Neoptolemos/Epirus
		   					}
		   				}
		   				any_legion_unit = {
		   					exists = commander
		   					commander = {
			   					OR = {
			   						THIS = char:38 # Demetrios/Antigonids
			   						THIS = char:26 # Antiochus/Seleukids
			   						THIS = char:46 # Magas/Egypt
			   						THIS = char:149 # Philippos/Macedon
			   						THIS = char:368 # Alkimachos/Thrace
			   						THIS = char:118 # Neoptolemos/Epirus
			   					}
			   				}
		   				}
		   			}
		   		}
	   		}
			if = {
				limit = {
					owner = {
						NOT = {
				            any_legion = { has_distinction = distinction_legio_primagena }
				        }
					}
				}
				if = {
					limit = {
						owner = {
							is_ai = yes
							has_civil_war = yes
						}
					}
					owner = {
						save_scope_as = mutineer_revolting_country
						trigger_event = distinction.40
					}
				}
				else_if = {
					limit = {
						NOT = { has_distinction = distinction_legio_primagena }
					}
					save_scope_as = primagena_legion
					owner = { trigger_event = distinction.7 }
				}
			}
			else = {
				add_legion_history = {
					key = legion_raised_history
					commander = owner.current_ruler
					province = owner.capital_scope
				}
			}
	    }
		add_distinction = distinction_legion_default
	}
}

on_disband_legion_unit = {
	# what: when units belonging to a legion are disbanded.
	# scope country, 
	# scope:target legion,
	# scope:unit unit,
}

on_legion_dissolved = {
	# what: just before a legion is completely destroyed and their remaining units disbanded.
	# note: empty legions are not destroyed automatically,
	# scope legion,
}

on_gw_construction_job_completed = {
	#Scope Character
	effect = {
		add_gold = 200
		add_loyalty = loyalty_gw_job_completed
		add_prominence = prominence_medium
		add_popularity = popularity_large
		add_finesse = 1
	}
}
