scripted_gui = {

	scripted_influence_option_buttons = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "influence_option_buttons"
		
		visible = {
		  always = yes
		}
		
		properties = {
			opt_influence_action_button = {
				image = "[select_influence_action_button]"
			}
			opt_aid_button = {
				image = "[select_aid_button]"
			}
			opt_aid_military_button = {
				image = "[select_aid_military_button]"
			}
			opt_target_other_button = {
				image = "[select_target_other_button]"
			}
			opt_manipulate_politics_button = {
				image = "[select_manipulate_politics_button]"
			}
			opt_coup_button = {
				image = "[select_coup_button]"
			}
			opt_economic_exploitation_button = {
				image = "[select_economic_exploitation_button]"
			}
			opt_make_puppet_button = {
				image = "[select_make_puppet_button]"
			}
		}
		
		triggers = {
		
			opt_influence_action_button_click_enabled = {
				ROOT = { has_political_power > 100 }
			}
			
			opt_aid_button_click_enabled = {
				#our country is a top 7 influencer
				is_influencer = yes
				#selected country have lower GDP/C than us
				check_variable = { gdp_capita < ROOT.gdp_capita }
			}
			
			opt_manipulate_politics_button_click_enabled = {
				
				OR = {
					AND = {
						check_variable = { influence_array^0 = ROOT }
						check_variable = { influence_array_calc^0 > 0.2 }
					}
					AND = {
						check_variable = { influence_array^1 = ROOT }
						check_variable = { influence_array_calc^1 > 0.2 }
					}
					AND = {
						check_variable = { influence_array^2 = ROOT }
						check_variable = { influence_array_calc^2 > 0.2 }
					}
				}
			}
			
			opt_make_puppet_button_click_enabled = {
				
				AND = {
					check_variable = { influence_array^0 = ROOT }
					check_variable = { influence_array_calc^0 > 0.8 }
					is_same_government = yes
					NOT = { is_puppet_of = ROOT }
					NOT = { has_war = yes }
				}
				
			}
			
			opt_coup_button_click_enabled = {
				
				NOT = { is_same_government = yes }
				NOT = { is_puppet_of = ROOT }
				NOT = { has_war = yes }
				ROOT = { has_political_power > 200 }
				
				OR = {
					AND = {
						check_variable = { influence_array^0 = ROOT }
						check_variable = { influence_array_calc^0 > 0.3 }
					}
					AND = {
						check_variable = { influence_array^1 = ROOT }
						check_variable = { influence_array_calc^1 > 0.3 }
					}
				}
			}
			
			opt_economic_exploitation_button_click_enabled = {
				
				AND = {
					check_variable = { influence_array^0 = ROOT }
					check_variable = { influence_array_calc^0 > 0.5 }
					NOT = { is_puppet_of = ROOT }
				}
				#not twice
				NOT = {
					meta_trigger = {
						text = {
							has_idea = [CHECKTAG]_tribute_idea
						}
						CHECKTAG = "[?var:influence_array^0.GetTag]"
					}
				}
			}
			opt_target_other_button_click_enabled = {
				OR = {
					check_variable = { influence_array^0 = ROOT }
					check_variable = { influence_array^1 = ROOT }
					check_variable = { influence_array^2 = ROOT }
				}
			}
			
			#hide for yourself
			opt_influence_action_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_aid_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_aid_military_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_target_other_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_manipulate_politics_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_coup_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_economic_exploitation_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
			opt_make_puppet_button_visible = {
				NOT = {
					TAG = ROOT
				}
			}
		}
		
		effects = {
			
			#influence
			opt_influence_action_button_click = {
			
				ROOT = { add_political_power = -100 }
				
				set_temp_variable = { influence_gain = ROOT.influence_multiplier } #from global rank idea
				multiply_temp_variable = { influence_gain = 10 } #base gain
				for_loop_effect = {
					end = influence_array^num
					value = v
					if = {
						limit = {
							check_variable = { influence_array^v = ROOT }
						}
						add_to_variable = { influence_array_val^v = influence_gain }
						set_country_flag = found
					}
				}
				if = {
					limit = { NOT = { has_country_flag = found } }
						add_to_array = { influence_array = ROOT.id }
						add_to_array = { influence_array_val = influence_gain }
				}
				clr_country_flag = found
				recalculate_influence = yes
			}
			
			# give gift of money
			opt_aid_button_click = {
				
				ROOT = {
					PREV = {
						country_event = { id = influence.0 }
					}
				}
			}
			
			##target select influence
			opt_target_other_button_click = {
				
				ROOT = {
					PREV = {
						country_event = { id = influence.2 }
					}
				}
			}
			
			opt_manipulate_politics_button_click = {
				
				#Add +5 to our outlook
				if = {
					limit = {
						ROOT = { has_government = fascism }
					}
					add_popularity = {
						ideology = fascism
						popularity = 0.05
					}
				}
				if = {
					limit = {
						ROOT = { has_government = neutrality }
					}
					add_popularity = {
						ideology = neutrality
						popularity = 0.05
					}
				}
				if = {
					limit = {
						ROOT = { has_government = communism }
					}
					add_popularity = {
						ideology = communism
						popularity = 0.05
					}
				}
				if = {
					limit = {
						ROOT = { has_government = nationalist }
					}
					add_popularity = {
						ideology = nationalist
						popularity = 0.05
					}
				}
				if = {
					limit = {
						ROOT = { has_government = democratic }
					}
					add_popularity = {
						ideology = democratic
						popularity = 0.05
					}
				}
				
				#add +5 to our party
				ROOT = {
					for_each_loop = {
						array = ruling_party
						value = v
						add_to_variable = { PREV.party_pop_array^v = 0.05 }
					}
				}
				
				#remove 10% influence
				set_temp_variable = { influence_reduce = influence_total } #from global rank idea
				multiply_temp_variable = { influence_reduce = 0.1 } #10%
				for_loop_effect = {
					end = influence_array^num
					value = v
					if = {
						limit = {
							check_variable = { influence_array^v = ROOT }
						}
						subtract_from_variable = { influence_array_val^v = influence_reduce }
					}
				}
				recalculate_influence = yes
				
				#reduce relations if different gov
				if = {
					limit = {
						NOT = { is_same_government = yes }
					}
					add_opinion_modifier = {
							target = ROOT
							modifier = supported_opposition
					}
				}
			}
			opt_coup_button_click = {
				
				ROOT = {
					PREV = {
						country_event = { id = influence.4 }
					}
				}
			}
			opt_make_puppet_button_click = {
			
				#eventually remove explotation idea (shouldn't double up)
				for_loop_effect = {
					end = influence_array^num
					value = v

					meta_effect = {
						text = {
							if = {
								limit = { has_idea = [THISTAG]_tribute_idea }
								remove_ideas = [THISTAG]_tribute_idea
							}
						}
						THISTAG = "[?var:influence_array^v.GetTag]"
					}
				}
				
				ROOT = {
					set_autonomy = {
						target = PREV
						autonomy_state = autonomy_satellite_state
						freedom_level = 0.5
					}
					add_named_threat = {
						threat = 5
						name = created_puppet_loc
					}
					PREV = { gui_effect_puppet_match_ruling_party_to_overlord = yes }
				}
				every_neighbor_country = {
					add_opinion_modifier = {
						target = ROOT
						modifier = puppeted_neighbor
					}
				}
			}
			
			opt_economic_exploitation_button_click = {
				
				meta_effect = {
					text = {
						add_ideas = [ROOTTAG]_tribute_idea
					}
					ROOTTAG = "[?var:influence_array^0.GetTag]"
				}
				
				#remove 10% influence
				set_temp_variable = { influence_reduce = influence_total } #from global rank idea
				multiply_temp_variable = { influence_reduce = 0.1 } #10%
				for_loop_effect = {
					end = influence_array^num
					value = v
					if = {
						limit = {
							check_variable = { influence_array^v = ROOT }
						}
						subtract_from_variable = { influence_array_val^v = influence_reduce }
					}
				}
				recalculate_influence = yes
				
				#opinions
				add_opinion_modifier = {
					target = ROOT
					modifier = exploited_us
				}
				every_neighbor_country = {
					add_opinion_modifier = {
						target = ROOT
						modifier = exploited_neighbor
					}
				}
			}
		}
	}

	domestic_influence_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "domestic_influence_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_1_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_1_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_2_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_2_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_3_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_3_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_4_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_4_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_5_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_5_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_6_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_6_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
	position_7_diplo = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
		
		window_name = "position_7_diplo"
		
		visible = {
		  always = yes
		}
		
		effects = { }
	}
}

