CCCPaste

script for Necron battle

import("ScarUtil.scar")
import("WXPScarUtil.scar")


function OnGameSetup()
	Setup_Player(1, "BERKYT", "necron_race", 1)
	-- Setup_Player(0, "BERKYT", "necron_race", 0)
	
	g_Player1 = World_GetPlayerAt(0)
	g_Player2 = World_GetPlayerAt(1)
	
	Misc_PlayerTeamColor(g_Player2, "default_2")
	
	g_is_first_wave = true
	g_checked_triggers_flayed = {}
	g_table_squad_stuck_timer = {}
	g_time_constant = {
		one_min = 60,
		one_min_thirty = 60 + 30,
		two_min = 60 * 2,
		five_min = 60 * 5,
		ten_min = 60 * 10
	}
	g_time_wave = 0
	g_global_time = 0
	g_num_of_wave = 0
	g_interval_wave = g_time_constant.two_min
	g_is_wave = false
	g_ad_count = 0
	g_check_triggers = {}
	g_check_tasks = {}
	g_check_ec = {}
	g_check_all = {}
	
	g_check_ec["NIS_Dialog_If_Exist_EC"] = 0
end


function OnInit()	
	InitHQPlayer()
	Fade_Start(2, true)
	
	DeleteHq("mkr_BERKYT_script_deleteSquads", "mkr_BERKYT_script_deleteEntities")
	
	Rule_SetupMusicPlaylist()
	
	Util_StartNIS( EVENTS.NIS_Opening ) 
	
	UpgradeLP()
	UpgradeMonoliths()
	NecronResearch()
	-- DebugMode()
	Player_SetAllResources(g_Player1, 2000, 2000)
	
	Rule_Add(CheckMarkerFlayeds)
	Rule_Add(CheckMarkerHomeFlayeds)
	Rule_Add(CheckMarkerTaskOne)
	Rule_Add(CheckHPEenergyCore)
	Rule_Add(WinMode)
	Rule_Add(CheckIsUnderAttackMainBase)
	
	Rule_AddOneShot(StartAttack, g_time_constant.two_min + 30)
	Rule_AddOneShot(InitArmyNecron, g_time_constant.one_min_thirty)
	Rule_AddOneShot(MainObjective, g_time_constant.one_min)
	Rule_AddOneShot(Objective_2, g_time_constant.one_min + 15)
	Rule_AddOneShot(StartDialog, g_time_constant.one_min + 20)
	
	Rule_AddInterval(GlobalGameTimer, 1)
	Rule_AddInterval(InitWave, 1)
	Rule_AddInterval(CheckHPHQPlayer, 1)
	Rule_AddInterval(Ad, g_time_constant.five_min)
end


Scar_AddInit(OnInit)


function StartDialog()
	Util_StartNIS( EVENTS.NIS_Dialog_Start )
end

function InitHQPlayer()
	Player_GetAllEntitiesNearMarker(g_Player1, "hq_player", "mkr_hq_player")
end


function CheckHPHQPlayer()
	print("EGroup_GetAvgHealth(hq_player)="..EGroup_GetAvgHealth("hq_player"))
	if EGroup_GetAvgHealth("hq_player") <= 0 and g_check_all["hq_player"] == nil then
		g_check_all["hq_player"] = true
		
		Util_MissionTitle("You lose.")
		
		Rule_AddOneShot(GameOver, 5)
	end
end


function MainObjective()
	Ping_Marker("mkr_task_main", false, attack)
	local obj_table = {title_id = 10075533, short_desc_id = 10075534, help_tip_id = 10075535}
	Objective_Add(obj_table, true)
end


function Objective_1()
	for i = 1, 3 do
		Ping_Marker("task_1_"..i, false, attack)
	end
	
	local obj_table = {title_id = 10075536, short_desc_id = 10075537, help_tip_id = 10075538}
	Objective_Add(obj_table, false)
end

function Objective_2()
	Ping_Marker("mkr_hq_player", false, attack)
	
	local obj_table = {title_id = 10075551, short_desc_id = 10075552, help_tip_id = 10075553}
	Objective_Add(obj_table, true)
end


-- This function created by SWayfarer
function DeleteHq(mkr_sg, mkr_eg)
    local i1 = 0
    local eg = "rjgrfjlrefvrfgftgb"
    local sg = "brjrfgbkfgnf3243re"
    
    if (Marker_Exists(mkr_eg, "basic_marker")) then
        for i1 = 1, World_GetPlayerCount() do
            Player_GetAllEntitiesNearMarker(World_GetPlayerAt(i1 - 1), eg, mkr_eg)
            
            EGroup_DestroyAllEntities(eg)
            EGroup_Destroy(eg)
        end
    else
        print(" (Error) Can't remove entities because special marker not exists!")
    end
    
    if (Marker_Exists(mkr_sg, "basic_marker")) then
        for i1 = 1, World_GetPlayerCount() do
            
            Player_GetAllSquadsNearMarker(World_GetPlayerAt(i1 - 1), sg, mkr_sg)
            
            SGroup_DestroyAllSquads(sg)
            SGroup_Destroy(sg)
        end
    else
        print(" (Error) Can't remove squads because special marker not exists!")
    end
end
--


function GameOver()
	World_SetGameOver()
end


function CheckHPEenergyCore()
	local sum_ec = 0
	
	for i = 1, 3 do
		sum_ec = sum_ec + EGroup_GetAvgHealth("eg_energy_cores_"..i)
	end
	
	if sum_ec == 0 and g_check_tasks["eg_energy_cores"] == nil then
		g_check_tasks["eg_energy_cores"] = false
		
		local title_id_1 = 10075536
		Objective_SetState ( title_id_1,  OS_Complete)
	end
end


function CheckIsUnderAttackMainBase()	
	if EGroup_IsUnderAttack("eg_main_mono", true) then
		for i = 1, 999 do
			local mkr = "mkr_energy_core_warrior_"..i 
			local eg_energy_cores = "eg_energy_cores_"..i
			
			if Marker_Exists(mkr, "basic_marker") and EGroup_Exists(eg_energy_cores) then
			
				if g_check_ec[eg_energy_cores] == nil then
					g_check_ec[eg_energy_cores] = true
					
					SpanwUnitIfEnergyCoreExist(eg_energy_cores, mkr)
				end
				
			end
		end
		
		if g_check_ec["NIS_Dialog_If_Exist_EC"] == 0 then
			g_check_ec["NIS_Dialog_If_Exist_EC"] = 1
			
			Util_StartNIS(EVENTS.NIS_Dialog_If_Exist_EC)
		end
	end
end


function TableLength(t)
    local len = 0
	
    for _, _ in pairs(t) do
        len = len + 1
    end
 
    return len
end


function SpanwUnitIfEnergyCoreExist(e_group, mkr)
	local artefacts_units_of_solemnace = {
		"guard_squad_baneblade",
		"eldar_squad_avatar",
		"chaos_squad_bloodthirster",
		"necron_night_bringer",
		"ork_squad_squiggoth",
		"space_marine_squad_land_raider",
		"tau_hammerhead_gunship_squad",
	}

	if EGroup_GetAvgHealth(e_group) ~= 0 then
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_artefacts_units_of_solemnace_"..mkr, artefacts_units_of_solemnace[World_GetRand(1, TableLength(artefacts_units_of_solemnace))], mkr, 1, 999)
		Cmd_AttackMoveMarker("sg_artefacts_units_of_solemnace_"..mkr, "mkr_focus")
	end
end


function WinMode()
	local eg_main_mono = "eg_main_mono"
	
	if EGroup_GetAvgHealth(eg_main_mono) == 0 and g_check_tasks[eg_main_mono] == nil then
		g_check_tasks[eg_main_mono] = true
		local mkr_delete = "mkr_delete_all_for_cinematic"
		
		DeleteHq(mkr_delete, mkr_delete)
		Util_MissionTitle("You Win!")
		
		local title_id_1 = 10075533
		Objective_SetState ( title_id_1,  OS_Complete)
		
		Util_StartNIS(EVENTS.NIS_Final)
		-- GameOver()
	end
end 


function Rule_SetupMusicPlaylist()
	t_music = {"MU_IG_THEME_Nightbringer", "MU_IG_STR_Necron", "MU_IG_STR_Necron_perc", "MU_IG_STR_Necron_perc_brass", "MU_IG_STR_Necron_perc_str"}
	Playlist_Manager( PC_Music, t_music, true, true , {20, 40})
	t_ambient_sound = {"AM_IG_STR_Necron"}
	Playlist_Manager( PC_Ambient, t_ambient_sound, true, true , {2, 4})	
end


function UpgradeMonoliths()
	EGroup_ForceAddOn("eg_Monolith_1", "addon_necron_hq_2")
	
	for i = 2, 9 do
		EGroup_ForceAddOn("eg_Monolith_"..i, "addon_necron_hq_"..World_GetRand(1, 2))
	end
end


function TompSpyders()
	--Necron Tomb Spyders = 3
	for i = 1, 3 do
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TombSpyder_"..i, "necron_tomb_spyder_squad", "mkr_S_TombSpyder_"..i, 1, 1)
		Cpu_LockSGroupAcrossPlayers("sg_TombSpyder_"..i)
		World_SetDeadMissionStart("sg_TombSpyder_"..i)
	end
end 

function NecronResearch()
	Player_GrantResearch (g_Player2,  "necron_night_bringer_research")
	Player_GrantResearch (g_Player2,  "necron_resurrection_orb_research")
	Player_GrantResearch (g_Player2,  "necron_night_bringer_research")
	Player_GrantResearch (g_Player2,  "necron_beacon_research")
	Player_GrantResearch (g_Player2,  "necron_beacon_research2")
end


function UpgradeLP()
	for num = 1, 9 do 
		EGroup_ForceAddOn("eg_lp_"..num, "addon_necron_list_post_2")
	end
end


function DebugMode()
	FOW_RevealAll()
	for i = 1, 999 do
		local mkr = "mkr_debug_"..i
		
		if Marker_Exists(mkr, "basic_marker") then
			Util_CreateSquadsAtMarkerEx(g_Player1, "saasdasdasd", "tau_hammerhead_gunship_squad", mkr, 5, 999)
		end
	end
	Util_CreateSquadsAtMarkerEx(g_Player1, "saasdasdasd", "tau_hammerhead_gunship_squad", "mkr_focus", 5, 999)
	Util_CreateSquadsAtMarkerEx(g_Player1, "saasdasdasd", "tau_hammerhead_gunship_squad", "mkr_par_1", 5, 999)
	Util_CreateSquadsAtMarkerEx(g_Player1, "saasdasdasd", "tau_hammerhead_gunship_squad", "mkr_cinematic_final_nw_1", 5, 999)
end


function Test()
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_NISDeepstrike1", "necron_flayed_one_squad", "mkr_flayed_11", 1, 999)
	SGroup_DeSpawn("sg_NISDeepstrike1")
	Squad_DeepStrikeToPos(SGroup_FromName("sg_NISDeepstrike1"), "monolith", Marker_GetPosition(Marker_FromName("mkr_flayed_11", "basic_marker")))
end


function PlayerHasAnySquadAtMarker(playerId, mkr)
    local sgName = "sg_unit_198203701311592837098181283"

    SGroup_CreateIfNotFound(sgName)
    SGroup_Clear(sgName)
    Player_GetAllSquadsNearMarker(playerId, sgName, mkr)

    if (SGroup_Count(sgName) > 0) then
        return true
    end

    return false
end


function GlobalGameTimer()
	g_global_time = g_global_time + 1
end


function TimerWave()
	if not g_is_wave then
		g_time_wave = g_time_wave + 1
	end
end


function CheckingSquadStuck(sg_wave_troops_team)
	local time_wait = g_time_constant.one_min_thirty
	
	SGroup_CreateIfNotFound(sg_wave_troops_team)
	
	if SGroup_IsUnderAttack(sg_wave_troops_team, false) == false then
		g_table_squad_stuck_timer[sg_wave_troops_team] = g_table_squad_stuck_timer[sg_wave_troops_team] + 1
		
		if g_table_squad_stuck_timer[sg_wave_troops_team] >= time_wait then
			SGroup_DestroyAllSquads(sg_wave_troops_team)
			g_table_squad_stuck_timer[sg_wave_troops_team] = 0
			g_is_wave = false
		end
	else
		g_table_squad_stuck_timer[sg_wave_troops_team] = 0
	end		
end


function GetMaxNumberOfMarker(name_mkr)
	local max_num_mkr = 0
		
	for i = 1, 999 do
		local mkr = name_mkr..i
	
		if Marker_Exists(mkr, "basic_marker") then
			max_num_mkr = max_num_mkr + 1
		end
	end
	
	return max_num_mkr
end


function InitWave()
	local sg_one_wave = "sg_one_wave"
	
	SGroup_CreateIfNotFound(sg_one_wave)
	
	TimerWave()
	
	if g_time_wave > g_interval_wave then
		g_is_wave = true
		g_table_squad_stuck_timer[sg_one_wave] = 0
		
		if SGroup_GetAvgHealth(sg_one_wave) == 0 then
			g_time_wave = 0
			CreateWave(sg_one_wave)
		end
	elseif g_is_wave and g_table_squad_stuck_timer[sg_one_wave] ~= nil then
		CheckingSquadStuck(sg_one_wave)
	end
end


function CreateWave(sg_one_wave)
	g_num_of_wave = g_num_of_wave + 1
	
	local waves = {}
	local max_num_mkr = GetMaxNumberOfMarker("mkr_wave_spawn_")
	
	if g_num_of_wave == 1 then
		for i = 1, World_GetRand(1, 3) do 
			local mkr = "mkr_wave_spawn_"
			
			waves["wave"..i] = {
				group1 = 
					{type_unit = "necron_basic_warrior_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group2 = 
					{type_unit = "necron_wraith_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(1, 3)},
			}
		end
	elseif g_num_of_wave == 2 then
		for i = 1, World_GetRand(1, 3) do 
			local mkr = "mkr_wave_spawn_"
			
			waves["wave"..i] = {
				group1 = 
					{type_unit = "necron_basic_warrior_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group2 = 
					{type_unit = "necron_wraith_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(1, 3)},
				group3 = 
					{type_unit = "necron_immortal_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
			}
		end
	elseif g_num_of_wave == 3 then
		for i = 1, World_GetRand(1, 3) do 
			local mkr = "mkr_wave_spawn_"
			
			waves["wave"..i] = {
				group1 = 
					{type_unit = "necron_basic_warrior_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group2 = 
					{type_unit = "necron_wraith_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(1, 3)},
				group3 = 
					{type_unit = "necron_immortal_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group4 = 
					{type_unit = "necron_destroyer_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
			}
		end
	elseif g_num_of_wave == 4 then
		for i = 1, World_GetRand(1, 3) do 
			local mkr = "mkr_wave_spawn_"
			
			waves["wave"..i] = {
				group1 = 
					{type_unit = "necron_basic_warrior_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group2 = 
					{type_unit = "necron_wraith_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(1, 3)},
				group3 = 
					{type_unit = "necron_immortal_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group4 = 
					{type_unit = "necron_destroyer_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group5 = 
					{type_unit = "necron_heavy_destroyer_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
			}
		end
	else
		for i = 1, World_GetRand(1, 2) do 
			local mkr = "mkr_wave_spawn_"
			
			waves["wave"..i] = {
				group1 = 
					{type_unit = "necron_basic_warrior_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group2 = 
					{type_unit = "necron_wraith_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(1, 3)},
				group3 = 
					{type_unit = "necron_immortal_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group4 = 
					{type_unit = "necron_destroyer_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group5 = 
					{type_unit = "necron_heavy_destroyer_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group6 = 
					{type_unit = "necron_lord_destroyer_squad", count_unit = 1, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group7 = 
					{type_unit = "necron_pariah_squad", count_unit = 999, mkr_spawn = mkr..World_GetRand(1, max_num_mkr), mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 1)},
				group8 = 
					{type_unit = "necron_wraith_squad", count_unit = 1, mkr_spawn = "mkr_wave_spawn_surprise", mkr_attack = "mkr_focus", s_group = sg_one_wave, count_squad = World_GetRand(0, 2)},
			}
			
			--Command_EntityBuild(g_Player2, EGroup_FromName("eg_Monolith_1"), "necron_tomb_spyder_squad")
		end
	end
	
	SpawnWave(waves)
	
	if g_is_first_wave then
		g_is_first_wave = false
		Util_StartNIS( EVENTS.NIS_FirstWave ) 
	end
end


function InitArmyNecron()
	function LocalCreateSquadsOnAllMarkers(type_unit, mkr_spawn, stance)
		local s_group =  "sg_all_army"
		
		for i = 1, 999 do
			local mkr = mkr_spawn..i
			
			if Marker_Exists(mkr, "basic_marker") then
				Util_CreateSquadsAtMarkerEx(g_Player2, s_group, type_unit, mkr, 1, 999)
				Cmd_SetStance(s_group, stance)
			end
		end
	end
	
	LocalCreateSquadsOnAllMarkers("necron_basic_warrior_squad", "mkr_nw_", STANCE_Attack)
	LocalCreateSquadsOnAllMarkers("necron_immortal_squad", "mkr_im_", STANCE_Attack)
	LocalCreateSquadsOnAllMarkers("necron_destroyer_squad", "mkr_destr_", STANCE_Attack)
	LocalCreateSquadsOnAllMarkers("necron_heavy_destroyer_squad", "mkr_big_destr_", STANCE_Attack)
	LocalCreateSquadsOnAllMarkers("necron_lord_destroyer_squad", "mkr_lord_destr_", STANCE_Attack)
	LocalCreateSquadsOnAllMarkers("necron_pariah_squad", "mkr_par_", STANCE_Attack)
	LocalCreateSquadsOnAllMarkers("necron_restored_monolith_squad", "mkr_mon_", STANCE_Attack)
end


function CheckMarkerTaskOne()
	local mkr = "mkr_trigger_task_1"
	
	if g_check_triggers[mkr] == nil then
		if PlayerHasAnySquadAtMarker(g_Player1, mkr) then
			g_check_triggers[mkr] = true
			
			Util_StartNIS(EVENTS.NIS_TaskOne) 
			Rule_AddOneShot(Objective_1, 45)
		end
	end
end


function CheckMarkerFlayeds()
	for num = 1, 999 do
		local mkr = "mkr_flayed_"..num
		
		if Marker_Exists(mkr, "basic_marker") then
			if g_checked_triggers_flayed[mkr] == nil then
				if PlayerHasAnySquadAtMarker(g_Player1, mkr) then
					g_checked_triggers_flayed[mkr] = true
					local sg = "sg_flayed_deepstrike"..num
					
					Util_CreateSquadsAtMarkerEx(g_Player2, sg, "necron_flayed_one_squad", "mkr_flayed_"..num, World_GetRand(1,3), 999)
					SGroup_DeSpawn(sg)
					Squad_DeepStrikeToPos(SGroup_FromName(sg), "monolith", Marker_GetPosition(Marker_FromName(mkr, "basic_marker")))
					Cmd_SetStance(sg, STANCE_Attack)
				end
			end
		end
	end
end


function CheckMarkerHomeFlayeds()
	for num = 1, 999 do
		local mkr = "mkr_flayed_home_"..num
		
		if Marker_Exists(mkr, "basic_marker") then
			if g_checked_triggers_flayed[mkr] == nil then
				if PlayerHasAnySquadAtMarker(g_Player1, mkr) then
					g_checked_triggers_flayed[mkr] = true
					local sg = "sg_flayed_home_deepstrike"..num
					
					Util_CreateSquadsAtMarkerEx(g_Player2, sg, "necron_flayed_one_squad", "mkr_flayed_"..num, 1, World_GetRand(1,3))
					SGroup_DeSpawn(sg)
					Squad_DeepStrikeToPos(SGroup_FromName(sg), "monolith", Marker_GetPosition(Marker_FromName(mkr, "basic_marker")))
					Cmd_SetStance(sg, STANCE_Attack)
				end
			end
		end
	end
end


function SpawnGroupUnitAndMoveAttack(type_unit, count_unit, mkr_spawn, mkr_attack, s_group)
	Util_CreateSquadsAtMarkerEx(g_Player2, s_group, type_unit, mkr_spawn, 1, count_unit)
	Cmd_AttackMoveMarker(s_group, mkr_attack)
end


function SpawnGroupUnit(type_unit, count_unit, mkr_spawn, s_group)
	Util_CreateSquadsAtMarkerEx(g_Player2, s_group, type_unit, mkr_spawn, 1, count_unit)
end


function SpawnWave(waves)
	for _, wave in pairs(waves) do
		if type(wave) == "table" then
			for _, group in pairs(wave) do
				if type(group) == "table" then
					for i = 1, group.count_squad do
						SpawnGroupUnitAndMoveAttack(group.type_unit, group.count_unit, group.mkr_spawn, group.mkr_attack, group.s_group)
					end
				end
			end
		end
	end
end


function StartAttack()	
	for num = 1, 3 do
		local sg = "sg_flayed_deepstrike_start_attack_"..num
		local mkr = "mkr_flayed_start_"..num
		
		Util_CreateSquadsAtMarkerEx(g_Player2, sg, "necron_flayed_one_squad", mkr, 1, World_GetRand(1,2))
		SGroup_DeSpawn(sg)
		Squad_DeepStrikeToPos(SGroup_FromName(sg), "monolith", Marker_GetPosition(Marker_FromName(mkr, "basic_marker")))
		Cmd_SetStance(sg, STANCE_Attack)
	end
end


function Sberbank()
	Util_MissionTitle("Sberbank: 5469 4000 2976 6750 (Check ReadMe - file)")
end


function VKontakte()
	Util_MissionTitle("VKontakte: https://vk.com/club177090833 (Check ReadMe - file)")
end


function Site_En()
	Util_MissionTitle("Visit my website and receive exclusive information!(Check ReadMe - file)")
end


function Site_Ru()
	Util_MissionTitle("Посетите мой сайт и получайте эксклюзивную информацию!(Проверьте 'ReadMe' - файл)")
end


function GameOver()
	World_SetGameOver()
end


function Ad()
	if g_ad_count == 0 then 
		Sberbank()
	elseif g_ad_count == 1 then
		Site_En()
	elseif g_ad_count == 2 then
		VKontakte()
	else
		g_ad_count = -1
	end
	
	g_ad_count = g_ad_count + 1
end