scripted_gui = {

	dst_main_container_B = {
	
		context_type = selected_state_context
		
		window_name = "dst_main_container_B"
		
		visible = {
			ROOT = {
				is_ai = no
				has_global_flag = dst_B_enabled
				OR = {
					has_country_flag = tp_is_host
					NOT = {
						has_global_flag = tp_is_multiplayer
					}
				}
			}
		}

		triggers = {
			dst_add_template_click_enabled = {
				any_country = {
					owns_state = PREV
					NOT = {
						has_template = "Crack Unit Type 3"
					}
				}
			}
			dst_increase_exp_click_enabled = {
				check_variable = { global.dst_exp_value < 1 }
			}
			dst_decrease_exp_click_enabled = {
				check_variable = { global.dst_exp_value > 0 }
			}
			dst_increase_eq_click_enabled = {
				check_variable = { global.dst_eq_value < 1 }
			}
			dst_decrease_eq_click_enabled = {
				check_variable = { global.dst_eq_value > 0 }
			}
			dst_enable_template_1_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit"
					NOT = { has_country_flag = dst_template_1_enabled }
				}
			}
			dst_disable_template_1_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit"
					has_country_flag = dst_template_1_enabled
				}
			}
			dst_template_1_text_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit"
				}
			}
			dst_enable_template_2_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit Type 2"
					NOT = { has_country_flag = dst_template_2_enabled }
				}
			}
			dst_disable_template_2_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit Type 2"
					has_country_flag = dst_template_2_enabled
				}
			}
			dst_template_2_text_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit Type 2"
				}
			}
			dst_enable_template_3_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit Type 3"
					NOT = { has_country_flag = dst_template_3_enabled }
				}
			}
			dst_disable_template_3_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit Type 3"
					has_country_flag = dst_template_3_enabled
				}
			}
			dst_template_3_text_visible = {
				any_country = {
					owns_state = PREV
					has_template = "Crack Unit Type 3"
				}
			}
			dst_spawn_custom_1_click_enabled = {
				any_country = {
					owns_state = PREV
					OR = {
						has_country_flag = dst_template_1_enabled
						has_country_flag = dst_template_2_enabled
						has_country_flag = dst_template_3_enabled
					}
					OR = {
						has_template = "Crack Unit"
						has_template = "Crack Unit Type 2"
						has_template = "Crack Unit Type 3"
					}
				}
			}
			dst_spawn_custom_5_click_enabled = {
				any_country = {
					owns_state = PREV
					OR = {
						has_country_flag = dst_template_1_enabled
						has_country_flag = dst_template_2_enabled
						has_country_flag = dst_template_3_enabled
					}
					OR = {
						has_template = "Crack Unit"
						has_template = "Crack Unit Type 2"
						has_template = "Crack Unit Type 3"
					}
				}
			}
			dst_spawn_custom_10_click_enabled = {
				any_country = {
					owns_state = PREV
					OR = {
						has_country_flag = dst_template_1_enabled
						has_country_flag = dst_template_2_enabled
						has_country_flag = dst_template_3_enabled
					}
					OR = {
						has_template = "Crack Unit"
						has_template = "Crack Unit Type 2"
						has_template = "Crack Unit Type 3"
					}
				}
			}
			dst_spawn_custom_50_click_enabled = {
				any_country = {
					owns_state = PREV
					OR = {
						has_country_flag = dst_template_1_enabled
						has_country_flag = dst_template_2_enabled
						has_country_flag = dst_template_3_enabled
					}
					OR = {
						has_template = "Crack Unit"
						has_template = "Crack Unit Type 2"
						has_template = "Crack Unit Type 3"
					}
				}
			}
			dst_delete_button_2_click_enabled = {
				any_country = {
					owns_state = PREV
					OR = {
						has_country_flag = dst_template_1_enabled
						has_country_flag = dst_template_2_enabled
						has_country_flag = dst_template_3_enabled
					}
					OR = {
						has_template = "Crack Unit"
						has_template = "Crack Unit Type 2"
						has_template = "Crack Unit Type 3"
					}
				}
			}
		}

		effects = {
		
			dst_help_button_2_click = {
				ROOT = {
					country_event = toolpack.3
				}
			}
			dst_delete_button_2_click = {
				tcw_clear_all_global_confirms = yes
				set_global_flag = tp_open_confirmation_window
				set_global_flag = dst_b_confirm_unit_deletion 
				random_country = {
					limit = { owns_state = PREV }
					set_country_flag = dstb_unit_deletion_target
				}
			}
			dst_add_template_click = {
				random_country = {
					limit = { owns_state = PREV }
					set_country_flag = toolpack_allow_crack_name
					if = {
						limit = {
							has_template = "Crack Unit Type 2"
							NOT = { has_template = "Crack Unit Type 3" }
						}
						division_template = {
							name = "Crack Unit Type 3"
							division_names_group = TP_TYPE_01
							regiments = {
								infantry = { x = 0 y = 0 }
								infantry = { x = 0 y = 1 }
								infantry = { x = 0 y = 2 }
								infantry = { x = 0 y = 3 }
								infantry = { x = 0 y = 4 }
					
								infantry = { x = 1 y = 0 }
								infantry = { x = 1 y = 1 }
								infantry = { x = 1 y = 2 }
								infantry = { x = 1 y = 3 }
								infantry = { x = 1 y = 4 }
							}
						}
					}
					if = {
						limit = {
							has_template = "Crack Unit"
							NOT = { has_template = "Crack Unit Type 2" }
						}
						division_template = {
							name = "Crack Unit Type 2"
							division_names_group = TP_TYPE_01
							regiments = {
								infantry = { x = 0 y = 0 }
								infantry = { x = 0 y = 1 }
								infantry = { x = 0 y = 2 }
								infantry = { x = 0 y = 3 }
								infantry = { x = 0 y = 4 }
					
								infantry = { x = 1 y = 0 }
								infantry = { x = 1 y = 1 }
								infantry = { x = 1 y = 2 }
								infantry = { x = 1 y = 3 }
								infantry = { x = 1 y = 4 }
							}
						}
					}
					if = {
						limit = {
							NOT = { has_template = "Crack Unit" }
						}
						division_template = {
							name = "Crack Unit"
							division_names_group = TP_TYPE_01
							regiments = {
								infantry = { x = 0 y = 0 }
								infantry = { x = 0 y = 1 }
								infantry = { x = 0 y = 2 }
								infantry = { x = 0 y = 3 }
								infantry = { x = 0 y = 4 }
					
								infantry = { x = 1 y = 0 }
								infantry = { x = 1 y = 1 }
								infantry = { x = 1 y = 2 }
								infantry = { x = 1 y = 3 }
								infantry = { x = 1 y = 4 }
							}
						}
					}
				}
			}
			dst_add_army_experience_click = {
				ROOT = {
					army_experience = 50
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 11 }
				}
			}
			dst_remove_army_experience_click = {
				ROOT = {
					army_experience = -50000
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 11 }
				}
			}
			dst_add_air_experience_click = {
				ROOT = {
					air_experience = 50
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 11 }
				}
			}
			dst_remove_air_experience_click = {
				ROOT = {
					air_experience = -50000
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 11 }
				}
			}
			dst_add_command_power_click = {
				ROOT = {
					add_command_power = 50
				}
			}
			dst_remove_command_power_click = {
				ROOT = {
					add_command_power = -50000
				}
			}
			dst_increase_exp_click = {
				if = {
					limit = {
						check_variable = { global.dst_exp_value < 100 }
					}
					add_to_variable = {
						var = global.dst_exp_value
						value = 0.1
					}
				}
			}
			dst_decrease_exp_click = {
				if = {
					limit = {
						check_variable = { global.dst_exp_value > 0 }
					}
					subtract_from_variable = {
						var = global.dst_exp_value
						value = 0.1
					}
				}
			}
			dst_increase_eq_click = {
				if = {
					limit = {
						check_variable = { global.dst_eq_value < 100 }
					}
					add_to_variable = {
						var = global.dst_eq_value
						value = 0.1
					}
				}
			}
			dst_decrease_eq_click = {
				if = {
					limit = {
						check_variable = { global.dst_eq_value > 0 }
					}
					subtract_from_variable = {
						var = global.dst_eq_value
						value = 0.1
					}
				}
			}
			dst_enable_template_1_click = {
				random_country = {
					limit = { owns_state = PREV }
					set_country_flag = dst_template_1_enabled
				}
			}
			dst_disable_template_1_click = {
				random_country = {
					limit = { owns_state = PREV }
					clr_country_flag = dst_template_1_enabled
				}
			}
			dst_enable_template_2_click = {
				random_country = {
					limit = { owns_state = PREV }
					set_country_flag = dst_template_2_enabled
				}
			}
			dst_disable_template_2_click = {
				random_country = {
					limit = { owns_state = PREV }
					clr_country_flag = dst_template_2_enabled
				}
			}
			dst_enable_template_3_click = {
				random_country = {
					limit = { owns_state = PREV }
					set_country_flag = dst_template_3_enabled
				}
			}
			dst_disable_template_3_click = {
				random_country = {
					limit = { owns_state = PREV }
					clr_country_flag = dst_template_3_enabled
				}
			}
			dst_spawn_custom_1_click = {
				random_country = {
					limit = { owns_state = PREV }
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 9 }
					if = {
						limit = { has_country_flag = dst_template_1_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_2_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_3_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
				}
			}
			dst_spawn_custom_5_click = {
				random_country = {
					limit = { owns_state = PREV }
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 9 }
					if = {
						limit = { has_country_flag = dst_template_1_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 5
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 5
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_2_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 5
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 5
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_3_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 5
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 5
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
				}
			}
			dst_spawn_custom_10_click = {
				random_country = {
					limit = { owns_state = PREV }
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 9 }
					if = {
						limit = { has_country_flag = dst_template_1_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 10
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 10
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_2_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 10
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 10
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_3_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 10
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 10
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
				}
			}
			dst_spawn_custom_50_click = {
				random_country = {
					limit = { owns_state = PREV }
					toolpack_cycle_action_log_variables = yes
					add_to_array = { global.toolpack_mp_action_array_targets = THIS }
					add_to_array = { global.toolpack_mp_action_array = 9 }
					if = {
						limit = { has_country_flag = dst_template_1_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 50
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit\" division_template = \"Crack Unit\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 50
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_2_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 50
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 2\" division_template = \"Crack Unit Type 2\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 50
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
					if = {
						limit = { has_country_flag = dst_template_3_enabled }
						PREV = {
							if = {
								limit = {
									check_variable = { global.dst_eq_value = 0 }
								}
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = 0 start_equipment_factor = 0.001" 
											owner = PREV
											count = 50
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
							else = {
								meta_effect = {
									text = {
										create_unit = {
											division = "name = \"Crack Unit Type 3\" division_template = \"Crack Unit Type 3\" start_experience_factor = [TP_UNIT_XP] start_equipment_factor = [TP_UNIT_EQ]" 
											owner = PREV
											count = 50
										}
									}
									TP_UNIT_XP = "[?global.dst_exp_value]"
									TP_UNIT_EQ = "[?global.dst_eq_value]"
								}
							}
						}
					}
				}
			}
		}
	}
}
		