function WorldLoaded()
	SetupPlayers()
	Factionchecker()
	ShowRoundSign()
	Trigger.AfterDelay(94, function()
	StartUnitChooser()
	end)
	WinGameP1 = Multi0.AddPrimaryObjective("Win most of the rounds!")
	WinGameP2 = Multi1.AddPrimaryObjective("Win most of the rounds!")
	WinGameP3 = Multi2.AddPrimaryObjective("Win most of the rounds!")
	WinGameP4 = Multi3.AddPrimaryObjective("Win most of the rounds!")
	StartingNotifications()
end

StartingNotifications = function()
	Media.PlaySpeechNotification( allplayers, "GameLoaded")
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		Media.DisplayMessage("Welcome to the Landing Party minigame", "Game-Brain", Red)	
	end)
	Trigger.AfterDelay(DateTime.Seconds(5), function()
		Media.DisplayMessage("Please choose your action forces now", "Game-Brain", Red)
		Trigger.AfterDelay(DateTime.Seconds(4), function()
			Media.DisplayMessage("Buy your favourite Units with the Supply-Trucks, just move them on the Pictures.", "Game-Brain", Red)
			Media.PlaySoundNotification( allplayers, "Beacon")
			Beacon.New(Multi0, e1picturem0.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi0, e3picturem0.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi0, e10picturem0.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi0, e11picturem0.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi0, e12picturem0.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi0, e13picturem0.CenterPosition, Utils.RandomInteger(100, 300), true)

			Beacon.New(Multi1, e1picturem1.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi1, e3picturem1.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi1, e10picturem1.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi1, e11picturem1.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi1, e12picturem1.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi1, e13picturem1.CenterPosition, Utils.RandomInteger(100, 300), true)

			Beacon.New(Multi2, e1picturem2.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi2, e3picturem2.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi2, e10picturem2.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi2, e11picturem2.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi2, e12picturem2.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi2, e13picturem2.CenterPosition, Utils.RandomInteger(100, 300), true)

			Beacon.New(Multi3, e1picturem3.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi3, e3picturem3.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi3, e10picturem3.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi3, e11picturem3.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi3, e12picturem3.CenterPosition, Utils.RandomInteger(100, 300), true)
			Beacon.New(Multi3, e13picturem3.CenterPosition, Utils.RandomInteger(100, 300), true)
		end)
	end)
end

countH1 = 0
countH2 = 0
countH3 = 0
countH4 = 0
countH5 = 0
countH6 = 0
countV3 = 0
countV4 = 0
countV5 = 0
countV6 = 0
Round = 1

MakemidCover = function()
	if Round == 1 then
		if countH5 < 31 then
			newactor = Actor.Create("nix03", true, { Location = CPos.New(12,15) + CVec.New(countH5, countV5), Owner = France })
			countH5 = countH5 + 3
			MakemidCover()
		elseif countV5 < 24 then
			countH5 = 0
			countV5 = countV5 + 3
			MakemidCover()
		end
	elseif Round == 2 then
		if countH5 < 15 then
			newactor = Actor.Create("nix03", true, { Location = CPos.New(21,15) + CVec.New(countH5, countV5), Owner = France })
			countH5 = countH5 + 3
			MakemidCover()
		elseif countV5 < 24 then
			countH5 = 0
			countV5 = countV5 + 3
			MakemidCover()
		end
	end

end

countVF1 = 0
countHF1 = 0
countVF2 = 0
countHF2 = 0

BattleFloor = function()
	if countVF1 < 13 then
		newactor = Actor.Create("maptile13", true, { Location = CPos.New(0,20) + CVec.New(countHF1, countVF1), Owner = France })
		newactor = Actor.Create("maptile13", true, { Location = CPos.New(48,20) + CVec.New(countHF1, countVF1), Owner = France })
		countVF1 = countVF1 + 4
	elseif countHF1 < 5 then
		countVF1 = 0
		countHF1 = countHF1 + 4
	end
	if countVF2 < 40 then
		newactor = Actor.Create("maptile13", true, { Location = CPos.New(8,8) + CVec.New(countHF2, countVF2), Owner = France })
		newactor = Actor.Create("maptile13", true, { Location = CPos.New(36,8) + CVec.New(countHF2, countVF2), Owner = France })
		countVF2 = countVF2 + 4
		BattleFloor()
	elseif countHF2 < 8 then
		countVF2 = 0
		countHF2 = countHF2 + 4
		BattleFloor()
	end
end

Positions = {
	maptile_4 = { CPos.New(8,52), CPos.New(12,52), CPos.New(16,52), CPos.New(36,52), CPos.New(40,52), CPos.New(44,52), CPos.New(24,48), CPos.New(28,48) } ,

	maptile_8 = { CPos.New(8,0), CPos.New(12,0), CPos.New(16,0), CPos.New(36,0), CPos.New(40,0), CPos.New(44,0), CPos.New(24,4), CPos.New(28,4) } ,

	maptile_7 = { CPos.New(8,4), CPos.New(12,4), CPos.New(16,4), CPos.New(36,4), CPos.New(40,4), CPos.New(44,4), CPos.New(20,8), CPos.New(24,8), CPos.New(28,8), CPos.New(32,8), CPos.New(20,44), CPos.New(24,44), CPos.New(28,44), CPos.New(32,44), CPos.New(4,8), CPos.New(4,12), CPos.New(4,16), CPos.New(4,36), CPos.New(4,40), CPos.New(4,44), CPos.New(48,8), CPos.New(48,12), CPos.New(48,16), CPos.New(48,36), CPos.New(48,40), CPos.New(48,44), CPos.New(8,48), CPos.New(12,48), CPos.New(16,48), CPos.New(36,48), CPos.New(40,48), CPos.New(44,48) }
 }

CheckFlagOwners = function()
	if not NoBattle then
		Trigger.AfterDelay(DateTime.Seconds(1), function()
			CheckFlagOwners()
		end)
		if Flag1.Owner == Multi0 or Flag1.Owner == Multi1 then
			Team1ownsFlag1 = true
			Team2ownsFlag1 = false
		elseif Flag1.Owner == Multi2 or Flag1.Owner == Multi3 then
			Team2ownsFlag1 = true
			Team1ownsFlag1 = false
		end
		if Flag2.Owner == Multi0 or Flag2.Owner == Multi1 then
			Team1ownsFlag2 = true
			Team2ownsFlag2 = false
		elseif Flag2.Owner == Multi2 or Flag2.Owner == Multi3 then
			Team2ownsFlag2 = true
			Team1ownsFlag2 = false
		end
		if Flag3.Owner == Multi0 or Flag3.Owner == Multi1 then
			Team1ownsFlag3 = true
			Team2ownsFlag3 = false
		elseif Flag3.Owner == Multi2 or Flag3.Owner == Multi3 then
			Team2ownsFlag3 = true
			Team1ownsFlag3 = false
		end
		if Flag4.Owner == Multi0 or Flag4.Owner == Multi1 then
			Team1ownsFlag4 = true
			Team2ownsFlag4 = false
		elseif Flag4.Owner == Multi2 or Flag4.Owner == Multi3 then
			Team2ownsFlag4 = true
			Team1ownsFlag4 = false
		end
		if Team1ownsFlag1 and Team1ownsFlag2 and Team1ownsFlag3 and Team1ownsFlag4 then
			Team1ownsallFlags = true
		else
			Team1ownsallFlags = false
		end
		if Team2ownsFlag1 and Team2ownsFlag2 and Team2ownsFlag3 and Team2ownsFlag4 then
			Team2ownsallFlags = true
		else
			Team2ownsallFlags = false
		end
	end
end

Numbers = { 1, 2 }
MakeBattleGround = function()
	Groundnumber = Utils.Random(Numbers)
	BattleFloor()
	newactor = Actor.Create("maptile3", true, { Location = CPos.New(24,0), Owner = France })
	newactor = Actor.Create("maptile3", true, { Location = CPos.New(28,0), Owner = France })
	newactor = Actor.Create("maptile3", true, { Location = CPos.New(24,52), Owner = France })
	newactor = Actor.Create("maptile3", true, { Location = CPos.New(28,52), Owner = France })

	newactor = Actor.Create("maptile18", true, { Location = CPos.New(0,0), Owner = France })
	newactor = Actor.Create("maptile17", true, { Location = CPos.New(48,0), Owner = France })
	newactor = Actor.Create("maptile16", true, { Location = CPos.New(48,48), Owner = France })
	newactor = Actor.Create("maptile15", true, { Location = CPos.New(0,48), Owner = France })

	newactor = Actor.Create("maptile24", true, { Location = CPos.New(20,0), Owner = France })
	newactor = Actor.Create("maptile25", true, { Location = CPos.New(32,0), Owner = France })
	newactor = Actor.Create("maptile5", true, { Location = CPos.New(20,48), Owner = France })
	newactor = Actor.Create("maptile6", true, { Location = CPos.New(32,48), Owner = France })

	newactor = Actor.Create("maptile27", true, { Location = CPos.New(0,12), Owner = France })
	newactor = Actor.Create("maptile28", true, { Location = CPos.New(0,36), Owner = France })
	newactor = Actor.Create("maptile26", true, { Location = CPos.New(52,12), Owner = France })
	newactor = Actor.Create("maptile29", true, { Location = CPos.New(52,36), Owner = France })

	newactor = Actor.Create("maptile9", true, { Location = CPos.New(0,8), Owner = France })
	newactor = Actor.Create("maptile9", true, { Location = CPos.New(0,44), Owner = France })
	newactor = Actor.Create("maptile10", true, { Location = CPos.New(52,8), Owner = France })
	newactor = Actor.Create("maptile10", true, { Location = CPos.New(52,44), Owner = France })

	for i,v in pairs(Positions.maptile_4) do
		Actor.Create('maptile4', true, {
			Owner = France,
			Location = v
		})
	end
	for i,v in pairs(Positions.maptile_7) do
		Actor.Create('maptile7', true, {
			Owner = France,
			Location = v
		})
	end

	for i,v in pairs(Positions.maptile_8) do
		Actor.Create('maptile8', true, {
			Owner = France,
			Location = v
		})
	end
	if Round == 1 and Groundnumber == 1 then
		mid1 = "maptile21"
		mid2 = "maptile4"
		mid3 = "maptile4"
		mid4 = "maptile28"

		mid5 = "maptile20"
		mid6 = "maptile8"
		mid7 = "maptile24"
		mid8 = "dummyactor"

		mid9 = "maptile7"
		mid10 = "maptile7"
		mid11 = "dummyactor"
		mid12 = "maptile19"

		mid13 = "maptile1"
		mid14 = "maptile7"
		mid15 = "maptile7"
		mid16 = "maptile7"

		mid17 = "maptile7"
		mid18 = "maptile7"
		mid19 = "maptile7"
		mid20 = "maptile2"

		mid21 = "maptile21"
		mid22 = "maptile6"
		mid23 = "maptile7"
		mid24 = "maptile7"

		mid25 = "maptile26"
		mid26 = "dummyactor"
		mid27 = "maptile4"
		mid28 = "maptile22"

		mid29 = "dummyactor"
		mid30 = "maptile8"
		mid31 = "maptile8"
		mid32 = "maptile19"
	elseif Round == 1 and Groundnumber == 2 then
		mid1 = "maptile21"
		mid2 = "maptile22"
		mid3 = "maptile1"
		mid4 = "maptile13"

		mid5 = "maptile20"
		mid6 = "maptile19"
		mid7 = "maptile13"
		mid8 = "maptile13"

		mid9 = "maptile7"
		mid10 = "maptile7"
		mid11 = "maptile13"
		mid12 = "maptile13"

		mid13 = "maptile13"
		mid14 = "maptile7"
		mid15 = "maptile2"
		mid16 = "maptile13"

		mid17 = "maptile13"
		mid18 = "maptile2"
		mid19 = "maptile7"
		mid20 = "maptile13"

		mid21 = "maptile13"
		mid22 = "maptile13"
		mid23 = "maptile7"
		mid24 = "maptile7"

		mid25 = "maptile13"
		mid26 = "maptile13"
		mid27 = "maptile21"
		mid28 = "maptile22"

		mid29 = "maptile13"
		mid30 = "maptile1"
		mid31 = "maptile20"
		mid32 = "maptile19"
	elseif Round == 2 and Groundnumber == 1 then
		mid1 = "maptile13"
		mid2 = "maptile13"
		mid3 = "maptile13"
		mid4 = "maptile13"

		mid5 = "maptile1"
		mid6 = "maptile7"
		mid7 = "maptile7"
		mid8 = "maptile2"

		mid9 = "maptile7"
		mid10 = "maptile29"
		mid11 = "maptile28"
		mid12 = "maptile7"

		mid13 = "maptile7"
		mid14 = "dummyactor"
		mid15 = "dummyactor"
		mid16 = "maptile7"

		mid17 = "maptile7"
		mid18 = "maptile26"
		mid19 = "maptile27"
		mid20 = "maptile7"

		mid21 = "maptile7"
		mid22 = "dummyactor"
		mid23 = "dummyactor"
		mid24 = "maptile7"

		mid25 = "maptile2"
		mid26 = "maptile7"
		mid27 = "maptile7"
		mid28 = "maptile1"

		mid29 = "maptile13"
		mid30 = "maptile13"
		mid31 = "maptile13"
		mid32 = "maptile13"
	elseif Round == 2 and Groundnumber == 2 then
		mid1 = "maptile7"
		mid2 = "maptile21"
		mid3 = "maptile28"
		mid4 = "maptile7"

		mid5 = "maptile7"
		mid6 = "maptile26"
		mid7 = "dummyactor"
		mid8 = "maptile7"

		mid9 = "maptile7"
		mid10 = "dummyactor"
		mid11 = "maptile19"
		mid12 = "maptile7"

		mid13 = "maptile7"
		mid14 = "maptile7"
		mid15 = "maptile2"
		mid16 = "maptile7"

		mid17 = "maptile7"
		mid18 = "maptile1"
		mid19 = "maptile7"
		mid20 = "maptile7"

		mid21 = "maptile7"
		mid22 = "maptile21"
		mid23 = "maptile28"
		mid24 = "maptile7"

		mid25 = "maptile7"
		mid26 = "maptile26"
		mid27 = "dummyactor"
		mid28 = "maptile7"

		mid29 = "maptile7"
		mid30 = "dummyactor"
		mid31 = "maptile19"
		mid32 = "maptile7"
	elseif Round == 3 and Groundnumber == 1 then
		mid1 = "maptile1"
		mid2 = "maptile13"
		mid3 = "maptile13"
		mid4 = "maptile2"

		mid5 = "maptile13"
		mid6 = "maptile13"
		mid7 = "maptile13"
		mid8 = "maptile13"

		mid9 = "maptile7"
		mid10 = "maptile7"
		mid11 = "maptile7"
		mid12 = "maptile7"

		mid13 = "maptile7"
		mid14 = "maptile21"
		mid15 = "maptile22"
		mid16 = "maptile7"

		mid17 = "maptile7"
		mid18 = "maptile20"
		mid19 = "maptile19"
		mid20 = "maptile7"

		mid21 = "maptile7"
		mid22 = "maptile7"
		mid23 = "maptile7"
		mid24 = "maptile7"

		mid25 = "maptile13"
		mid26 = "maptile13"
		mid27 = "maptile13"
		mid28 = "maptile13"

		mid29 = "maptile2"
		mid30 = "maptile13"
		mid31 = "maptile13"
		mid32 = "maptile1"
	elseif Round == 3 and Groundnumber == 2 then
		mid1 = "maptile1"
		mid2 = "maptile7"
		mid3 = "maptile7"
		mid4 = "maptile2"

		mid5 = "maptile13"
		mid6 = "maptile13"
		mid7 = "maptile13"
		mid8 = "maptile13"

		mid9 = "maptile13"
		mid10 = "maptile13"
		mid11 = "maptile13"
		mid12 = "maptile13"

		mid13 = "maptile2"
		mid14 = "maptile13"
		mid15 = "maptile13"
		mid16 = "maptile1"

		mid17 = "maptile1"
		mid18 = "maptile13"
		mid19 = "maptile13"
		mid20 = "maptile2"

		mid21 = "maptile13"
		mid22 = "maptile13"
		mid23 = "maptile13"
		mid24 = "maptile13"

		mid25 = "maptile13"
		mid26 = "maptile13"
		mid27 = "maptile13"
		mid28 = "maptile13"

		mid29 = "maptile2"
		mid30 = "maptile7"
		mid31 = "maptile7"
		mid32 = "maptile1"
	end
	Flag1 = Actor.Create("ctflag", true, { Location = CPos.New(10,17), Owner = Multi0 })
	Flag2 = Actor.Create("ctflag", true, { Location = CPos.New(10,38), Owner = Multi1 })
	Flag3 = Actor.Create("ctflag", true, { Location = CPos.New(45,17), Owner = Multi2 })
	Flag4 = Actor.Create("ctflag", true, { Location = CPos.New(45,38), Owner = Multi3 })

	newactor = Actor.Create(mid1, true, { Location = CPos.New(20,12), Owner = France })
	newactor = Actor.Create(mid2, true, { Location = CPos.New(24,12), Owner = France })
	newactor = Actor.Create(mid3, true, { Location = CPos.New(28,12), Owner = France })
	newactor = Actor.Create(mid4, true, { Location = CPos.New(32,12), Owner = France })

	newactor = Actor.Create(mid5, true, { Location = CPos.New(20,16), Owner = France })
	newactor = Actor.Create(mid6, true, { Location = CPos.New(24,16), Owner = France })
	newactor = Actor.Create(mid7, true, { Location = CPos.New(28,16), Owner = France })
	newactor = Actor.Create(mid8, true, { Location = CPos.New(32,16), Owner = France })

	newactor = Actor.Create(mid9, true, { Location = CPos.New(20,20), Owner = France })
	newactor = Actor.Create(mid10, true, { Location = CPos.New(24,20), Owner = France })
	newactor = Actor.Create(mid11, true, { Location = CPos.New(28,20), Owner = France })
	newactor = Actor.Create(mid12, true, { Location = CPos.New(32,20), Owner = France })

	newactor = Actor.Create(mid13, true, { Location = CPos.New(20,24), Owner = France })
	newactor = Actor.Create(mid14, true, { Location = CPos.New(24,24), Owner = France })
	newactor = Actor.Create(mid15, true, { Location = CPos.New(28,24), Owner = France })
	newactor = Actor.Create(mid16, true, { Location = CPos.New(32,24), Owner = France })

	newactor = Actor.Create(mid17, true, { Location = CPos.New(20,28), Owner = France })
	newactor = Actor.Create(mid18, true, { Location = CPos.New(24,28), Owner = France })
	newactor = Actor.Create(mid19, true, { Location = CPos.New(28,28), Owner = France })
	newactor = Actor.Create(mid20, true, { Location = CPos.New(32,28), Owner = France })

	newactor = Actor.Create(mid21, true, { Location = CPos.New(20,32), Owner = France })
	newactor = Actor.Create(mid22, true, { Location = CPos.New(24,32), Owner = France })
	newactor = Actor.Create(mid23, true, { Location = CPos.New(28,32), Owner = France })
	newactor = Actor.Create(mid24, true, { Location = CPos.New(32,32), Owner = France })

	newactor = Actor.Create(mid25, true, { Location = CPos.New(20,36), Owner = France })
	newactor = Actor.Create(mid26, true, { Location = CPos.New(24,36), Owner = France })
	newactor = Actor.Create(mid27, true, { Location = CPos.New(28,36), Owner = France })
	newactor = Actor.Create(mid28, true, { Location = CPos.New(32,36), Owner = France })

	newactor = Actor.Create(mid29, true, { Location = CPos.New(20,40), Owner = France })
	newactor = Actor.Create(mid30, true, { Location = CPos.New(24,40), Owner = France })
	newactor = Actor.Create(mid31, true, { Location = CPos.New(28,40), Owner = France })
	newactor = Actor.Create(mid32, true, { Location = CPos.New(32,40), Owner = France })
	GetandsetFlags()
end
CTFFLagtypes = {"ctflag"}

function GetNearFlag (flag)
	Trigger.OnEnteredProximityTrigger(flag.CenterPosition, WDist.FromCells(3), function(a, id)
		local mine = flag.Owner
		local yours = a.Owner
		if mine ~= yours and  mine.IsAlliedWith(yours) ~= true and yours ~= Player.GetPlayer("Creeps") and Actor.CruiseAltitude(a.Type) == 0 and a.Type ~= "1tnk.husk" and a.Type ~= "2tnk.husk" and a.Type ~= "3tnk.husk" and a.Type ~= "4tnk.husk" and a.Type ~= "harv.fullhusk" and a.Type ~= "harv.emptyhusk" and a.Type ~= "mcv.husk" and a.Type ~= "mgg.husk" and a.Type ~= "camera" and a.Type ~= "camera.paradrop" and a.Type ~= "camera.spyplane" and a.Type ~= "stnk" and a.Type ~= "bigsight" and a.Owner ~= France and a.Owner ~= Germany and a.Owner ~= England and a.Owner ~= Russia and a.Owner ~= Ukraine and a.Owner ~= Golden  then
			flag.Owner = yours
		end
	end)	
end
GetandsetFlags = function()
	CTFlags = {}
	Trigger.AfterDelay(DateTime.Seconds(1), function() -- set up Flags
		for i=1,#CTFFLagtypes do
			local T1 = Multi0.GetActorsByType(CTFFLagtypes[i])
			if T1 ~= nil then
				joinMyTables(CTFlags, T1)			
			end
			local T2 = Multi1.GetActorsByType(CTFFLagtypes[i])
			if T2 ~= nil then
				joinMyTables(CTFlags, T2)			
			end
			local T3 = Multi2.GetActorsByType(CTFFLagtypes[i])
			if T3 ~= nil then
				joinMyTables(CTFlags, T3)			
			end
			local T4 = Multi3.GetActorsByType(CTFFLagtypes[i])
			if T4 ~= nil then
				joinMyTables(CTFlags, T4)			
			end
		end
	end)
	
	Trigger.AfterDelay(DateTime.Seconds(2), function()	 -- fuse flags
		for k,v in ipairs(CTFlags) do
			GetNearFlag(v)
		end
		return CTFlags
	end)
end
num = 0
function joinMyTables(t1, t2) -- simple join tables
	for k,v in ipairs(t2) do
		table.insert(t1, v)
		num = num + 1
	end 
	return t1
end

MakeChooseGround = function()
	if countH6 < 20 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,1) + CVec.New(countH6, 0), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,55) + CVec.New(countH6, 0), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(36,1) + CVec.New(countH6, 0), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(36,55) + CVec.New(countH6, 0), Owner = France })
		countH6 = countH6 + 1
	end
	if countV6 < 11 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,1) + CVec.New(0, countV6), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,45) + CVec.New(0, countV6), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(55,1) + CVec.New(0, countV6), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(55,45) + CVec.New(0, countV6), Owner = France })
		countV6 = countV6 + 1
	end
	if countH1 < 55 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(1,12) + CVec.New(countH1, 0), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(1,27) + CVec.New(countH1, 0), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(1,42) + CVec.New(countH1, 0), Owner = France })
		countH1 = countH1 + 3
	end
	if countH2 < 55 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,18) + CVec.New(countH2, 0), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,23) + CVec.New(countH2, 0), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,33) + CVec.New(countH2, 0), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,38) + CVec.New(countH2, 0), Owner = France })
		countH2 = countH2 + 2
	end
	if countV3 < 4 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(4,15) + CVec.New(countH3, countV3), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(4,23) + CVec.New(countH3, countV3), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(4,30) + CVec.New(countH3, countV3), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(4,38) + CVec.New(countH3, countV3), Owner = France })
		countV3 = countV3 + 1
		MakeChooseGround()
	elseif countH3 < 50 then
		countV3 = 0
		countH3 = countH3 + 4
		MakeChooseGround()
	end
	if countV4 < 11 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(21,1) + CVec.New(countH4, countV4), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(21,44) + CVec.New(countH4, countV4), Owner = France })

		countV4 = countV4 + 3
	elseif countH4 < 11 then
		countV4 = 0
		countH4 = countH4 + 3
	end
	newactor = Actor.Create("nix03", true, { Location = CPos.New(27,18), Owner = France })
	newactor = Actor.Create("nix03", true, { Location = CPos.New(27,21), Owner = France })
	newactor = Actor.Create("nix03", true, { Location = CPos.New(27,33), Owner = France })
	newactor = Actor.Create("nix03", true, { Location = CPos.New(27,36), Owner = France })
	if Round < 2 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(11,18), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(11,21), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(11,33), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(11,36), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(43,18), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(43,21), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(43,33), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(43,36), Owner = France })
	end
	if Round < 3 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(19,18), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(19,21), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(19,33), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(19,36), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(35,18), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(35,21), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(35,33), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(35,36), Owner = France })
	end
end



StartUnitChooser = function()
	T1TruckMove1 = 8
	T2TruckMove1 = 48
	T1TruckMove2 = 6
	T2TruckMove2 = 50
	T1TruckMove3 = 4
	T2TruckMove3 = 52
	T1TruckMove4 = 4
	T2TruckMove4 = 52
	RandomPlayer =  Utils.Random(AllPlayers)
	LandingPartySign = Actor.Create( "landingpartysign", true, { Location = CPos.New(24,1), Owner = RandomPlayer })
	LandingPartySign = Actor.Create( "landingpartysign", true, { Location = CPos.New(24,53), Owner = RandomPlayer })
	MakemidCover()
	MakeChooseGround()
	if not TriggersSet then
		TriggersSet = true
		SetTriggers()
	end
	TriggerUnits()
	Trigger.AfterDelay(63, function()
		turnOn()
		AllPlayerReady = false
		chooseTime = true
	end)
	newactor = Actor.Create("dummyactor", true, { Location = CPos.New(21,11), Owner = Multi0 })
	newactor = Actor.Create("dummyactor", true, { Location = CPos.New(21,44), Owner = Multi1 })
	newactor = Actor.Create("dummyactor", true, { Location = CPos.New(33,11), Owner = Multi2 })
	newactor = Actor.Create("dummyactor", true, { Location = CPos.New(33,44), Owner = Multi3 })
	if Round == 1 then
		WinRound1P1 = Multi0.AddSecondaryObjective("Win Round 1")
		WinRound1P2 = Multi1.AddSecondaryObjective("Win Round 1")
		WinRound1P3 = Multi2.AddSecondaryObjective("Win Round 1")
		WinRound1P4 = Multi3.AddSecondaryObjective("Win Round 1")
	end
	if M0IsAllies then
		CreateM0Allies1()
	elseif M0IsSoviet then
		CreateM0Soviet1()
	end
	if M1IsAllies then
		CreateM1Allies1()
	elseif M1IsSoviet then
		CreateM1Soviet1()
	end
	if M2IsAllies then
		CreateM2Allies1()
	elseif M2IsSoviet then
		CreateM2Soviet1()
	end
	if M3IsAllies then
		CreateM3Allies1()
	elseif M3IsSoviet then
		CreateM3Soviet1()
	end
	if Round < 3 then

		if M0IsAllies then
			newactor = Actor.Create("alliesflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
		elseif M0IsSoviet then
			newactor = Actor.Create("sovietflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
		end
		if M1IsAllies then
			newactor = Actor.Create("alliesflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
		elseif M1IsSoviet then
			newactor = Actor.Create("sovietflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
		end
		if M2IsAllies then
			newactor = Actor.Create("alliesflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
		elseif M2IsSoviet then
			newactor = Actor.Create("sovietflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
		end
		if M3IsAllies then
			newactor = Actor.Create("alliesflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
		elseif M3IsSoviet then
			newactor = Actor.Create("sovietflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
		end
	end
	if Round > 1 then
		newactor = Actor.Create("much.apwr", true, { Location = CPos.New(21,11), Owner = Multi0 })
		newactor = Actor.Create("much.apwr", true, { Location = CPos.New(21,44), Owner = Multi1 })
		newactor = Actor.Create("much.apwr", true, { Location = CPos.New(33,11), Owner = Multi2 })
		newactor = Actor.Create("much.apwr", true, { Location = CPos.New(33,44), Owner = Multi3 })
		newactor = Actor.Create("noredome", true, { Location = CPos.New(21,2), Owner = Multi0 })
		newactor = Actor.Create("noredome", true, { Location = CPos.New(21,52), Owner = Multi1 })
		newactor = Actor.Create("noredome", true, { Location = CPos.New(34,2), Owner = Multi2 })
		newactor = Actor.Create("noredome", true, { Location = CPos.New(34,52), Owner = Multi3 })

		newactor = Actor.Create("fix", true, { Location = CPos.New(21,5), Owner = Multi0 })
		newactor = Actor.Create("fix", true, { Location = CPos.New(21,49), Owner = Multi1 })
		newactor = Actor.Create("fix", true, { Location = CPos.New(33,5), Owner = Multi2 })
		newactor = Actor.Create("fix", true, { Location = CPos.New(33,49), Owner = Multi3 })
	end
	if Round == 2 then
		WinRound2P1 = Multi0.AddSecondaryObjective("Win Round 2")
		WinRound2P2 = Multi1.AddSecondaryObjective("Win Round 2")
		WinRound2P3 = Multi2.AddSecondaryObjective("Win Round 2")
		WinRound2P4 = Multi3.AddSecondaryObjective("Win Round 2")
		T1TruckMove1 = 16
		T2TruckMove1 = 40
		T1TruckMove2 = 12
		T2TruckMove2 = 44
		T1TruckMove3 = 8
		T2TruckMove3 = 48
	end
	if Round > 1 then
		if M0IsAllies then
			CreateM0Allies2()
		elseif M0IsSoviet then
			CreateM0Soviet2()
		end
		if M1IsAllies then
			CreateM1Allies2()
		elseif M1IsSoviet then
			CreateM1Soviet2()
		end
		if M2IsAllies then
			CreateM2Allies2()
		elseif M2IsSoviet then
			CreateM2Soviet2()
		end
		if M3IsAllies then
			CreateM3Allies2()
		elseif M3IsSoviet then
			CreateM3Soviet2()
		end
	end
	if Round == 3 then
		WinRound3P1 = Multi0.AddSecondaryObjective("Win Round 3")
		WinRound3P2 = Multi1.AddSecondaryObjective("Win Round 3")
		WinRound3P3 = Multi2.AddSecondaryObjective("Win Round 3")
		WinRound3P4 = Multi3.AddSecondaryObjective("Win Round 3")
		T1TruckMove1 = 24
		T2TruckMove1 = 32
		T1TruckMove2 = 18
		T2TruckMove2 = 38
		T1TruckMove3 = 12
		T2TruckMove3 = 44
		T1TruckMove4 = 7
		T2TruckMove4 = 49
		if M0IsAllies then
			newactor = Actor.Create("noreatek", true, { Location = CPos.New(21,8), Owner = Multi0 })
		elseif M0IsSoviet then
			newactor = Actor.Create("norestek", true, { Location = CPos.New(21,8), Owner = Multi0 })
		end
		if M0IsGerman then
			newactor = Actor.Create("germanyflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
			CreateM0German()
		elseif M0IsFrance then
			newactor = Actor.Create("franceflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
			CreateM0France()
		elseif M0IsEngland then
			newactor = Actor.Create("englandflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
			CreateM0England()
		elseif M0IsRussia then
			newactor = Actor.Create("russiaflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
			CreateM0Russia()
		elseif M0IsUkraine then
			newactor = Actor.Create("ukraineflag", true, { Location = CPos.New(11,8), Owner = Multi0 })
			CreateM0Ukraine()
		end
		if M1IsAllies then
			newactor = Actor.Create("noreatek", true, { Location = CPos.New(21,47), Owner = Multi1 })
		elseif M1IsSoviet then
			newactor = Actor.Create("norestek", true, { Location = CPos.New(21,47), Owner = Multi1 })
		end
		if M1IsGerman then
			newactor = Actor.Create("germanyflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
			CreateM1German()
		elseif M1IsFrance then
			newactor = Actor.Create("franceflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
			CreateM1France()
		elseif M1IsEngland then
			newactor = Actor.Create("englandflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
			CreateM1England()
		elseif M1IsRussia then
			newactor = Actor.Create("russiaflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
			CreateM1Russia()
		elseif M1IsUkraine then
			newactor = Actor.Create("ukraineflag", true, { Location = CPos.New(11,50), Owner = Multi1 })
			CreateM1Ukraine()
		end
		if M2IsAllies then
			newactor = Actor.Create("noreatek", true, { Location = CPos.New(34,8), Owner = Multi2 })
		elseif M2IsSoviet then
			newactor = Actor.Create("norestek", true, { Location = CPos.New(33,8), Owner = Multi2 })
		end
		if M2IsGerman then
			newactor = Actor.Create("germanyflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
			CreateM2German()
		elseif M2IsFrance then
			newactor = Actor.Create("franceflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
			CreateM2France()
		elseif M2IsEngland then
			newactor = Actor.Create("englandflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
			CreateM2England()
		elseif M2IsRussia then
			newactor = Actor.Create("russiaflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
			CreateM2Russia()
		elseif M2IsUkraine then
			newactor = Actor.Create("ukraineflag", true, { Location = CPos.New(45,8), Owner = Multi2 })
			CreateM2Ukraine()
		end
		if M3IsAllies then
			newactor = Actor.Create("noreatek", true, { Location = CPos.New(34,47), Owner = Multi3 })
		elseif M3IsSoviet then
			newactor = Actor.Create("norestek", true, { Location = CPos.New(33,47), Owner = Multi3 })
		end
		if M3IsGerman then
			newactor = Actor.Create("germanyflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
			CreateM3German()
		elseif M3IsFrance then
			newactor = Actor.Create("franceflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
			CreateM3France()
		elseif M3IsEngland then
			newactor = Actor.Create("englandflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
			CreateM3England()
		elseif M3IsRussia then
			newactor = Actor.Create("russiaflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
			CreateM3Russia()
		elseif M3IsUkraine then
			newactor = Actor.Create("ukraineflag", true, { Location = CPos.New(45,50), Owner = Multi3 })
			CreateM3Ukraine()
		end
	end
	EnterSupplyTrux()
end

TriggerUnits = function()
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(10,10), Owner = Multi0 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(10,45), Owner = Multi1 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(10,28), Owner = Multi1 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(46,28), Owner = Multi2 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(46,10), Owner = Multi2 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(46,45), Owner = Multi3 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(8,12), Owner = Multi0 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(8,23), Owner = Multi0 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(8,33), Owner = Multi1 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(8,43), Owner = Multi1 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(48,12), Owner = Multi2 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(48,23), Owner = Multi2 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(48,33), Owner = Multi3 })
	newactor = Actor.Create("nix01bs", true, { Location = CPos.New(48,43), Owner = Multi3 })
-- Mulit0
	newactor = Actor.Create("e1trigger", true, { Location = CPos.New(2,15), Owner = Multi0 })
	e1picturem0 = Actor.Create("e1pic", true, { Location = CPos.New(2,16), Owner = Multi0 })
	newactor = Actor.Create("e3trigger", true, { Location = CPos.New(2,28), Owner = Multi0 })
	e3picturem0 = Actor.Create("e3pic", true, { Location = CPos.New(2,25), Owner = Multi0 })
-- Mulit1
	newactor = Actor.Create("e1trigger", true, { Location = CPos.New(2,30), Owner = Multi1 })
	e1picturem1 = Actor.Create("e1pic", true, { Location = CPos.New(2,31), Owner = Multi1 })
	newactor = Actor.Create("e3trigger", true, { Location = CPos.New(2,43), Owner = Multi1 })
	e3picturem1 = Actor.Create("e3pic", true, { Location = CPos.New(2,40), Owner = Multi1 })
	newactor = Actor.Create("e1trigger", true, { Location = CPos.New(54,15), Owner = Multi2 })
	e1picturem2 = Actor.Create("e1pic", true, { Location = CPos.New(54,16), Owner = Multi2 })
	newactor = Actor.Create("e3trigger", true, { Location = CPos.New(54,28), Owner = Multi2 })
	e3picturem2 = Actor.Create("e3pic", true, { Location = CPos.New(54,25), Owner = Multi2 })
	newactor = Actor.Create("e1trigger", true, { Location = CPos.New(54,30), Owner = Multi3 })
	e1picturem3 = Actor.Create("e1pic", true, { Location = CPos.New(54,31), Owner = Multi3 })
	newactor = Actor.Create("e3trigger", true, { Location = CPos.New(54,43), Owner = Multi3 })
	e3picturem3 = Actor.Create("e3pic", true, { Location = CPos.New(54,40), Owner = Multi3 })
end

EnterSupplyTrux = function()
	newactor = Actor.Create("truk", true, { Location = CPos.New(1,20), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove1,20))
	newactor = Actor.Create("truk", true, { Location = CPos.New(1,21), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove1,21))
	newactor = Actor.Create("truk", true, { Location = CPos.New(1,35), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove1,35))
	newactor = Actor.Create("truk", true, { Location = CPos.New(1,36), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove1,36))

	newactor = Actor.Create("truk", true, { Location = CPos.New(55,20), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove1,20))
	newactor = Actor.Create("truk", true, { Location = CPos.New(55,21), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove1,21))
	newactor = Actor.Create("truk", true, { Location = CPos.New(55,35), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove1,35))
	newactor = Actor.Create("truk", true, { Location = CPos.New(55,36), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove1,36))
	Trigger.AfterDelay(DateTime.Seconds(2), function()
		Media.PlaySpeechNotification( allplayers, "ConvoyApproaching")
		RemoveGolden()
		newactor = Actor.Create("truk", true, { Location = CPos.New(1,20), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove2,20))
		newactor = Actor.Create("truk", true, { Location = CPos.New(1,21), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove2,21))
		newactor = Actor.Create("truk", true, { Location = CPos.New(1,35), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove2,35))
		newactor = Actor.Create("truk", true, { Location = CPos.New(1,36), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove2,36))

		newactor = Actor.Create("truk", true, { Location = CPos.New(55,20), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove2,20))
		newactor = Actor.Create("truk", true, { Location = CPos.New(55,21), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove2,21))
		newactor = Actor.Create("truk", true, { Location = CPos.New(55,35), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove2,35))
		newactor = Actor.Create("truk", true, { Location = CPos.New(55,36), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove2,36))
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			newactor = Actor.Create("truk", true, { Location = CPos.New(1,20), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove3,20))
			newactor = Actor.Create("truk", true, { Location = CPos.New(1,35), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove3,35))
			newactor = Actor.Create("truk", true, { Location = CPos.New(55,20), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove3,20))
			newactor = Actor.Create("truk", true, { Location = CPos.New(55,35), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove3,35))
			newactor = Actor.Create("truk", true, { Location = CPos.New(1,21), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove3,21))
			newactor = Actor.Create("truk", true, { Location = CPos.New(1,36), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove3,36))
			newactor = Actor.Create("truk", true, { Location = CPos.New(55,21), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove3,21))
			newactor = Actor.Create("truk", true, { Location = CPos.New(55,36), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove3,36))
			if Round > 1 then
				Trigger.AfterDelay(DateTime.Seconds(2), function()
					RemoveGolden()
					newactor = Actor.Create("truk", true, { Location = CPos.New(1,20), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove4,20))
					newactor = Actor.Create("truk", true, { Location = CPos.New(1,21), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(T1TruckMove4,21))
					newactor = Actor.Create("truk", true, { Location = CPos.New(1,35), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove4,35))
					newactor = Actor.Create("truk", true, { Location = CPos.New(1,36), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(T1TruckMove4,36))

					newactor = Actor.Create("truk", true, { Location = CPos.New(55,20), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove4,20))
					newactor = Actor.Create("truk", true, { Location = CPos.New(55,21), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(T2TruckMove4,21))
					newactor = Actor.Create("truk", true, { Location = CPos.New(55,35), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove4,35))
					newactor = Actor.Create("truk", true, { Location = CPos.New(55,36), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(T2TruckMove4,36))
					if Round > 2 then
						Trigger.AfterDelay(DateTime.Seconds(2), function()
							newactor = Actor.Create("truk", true, { Location = CPos.New(1,20), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(2,20))
							newactor = Actor.Create("truk", true, { Location = CPos.New(1,21), Owner = Multi0 }) newactor.ScriptedMove(CPos.New(2,21))
							newactor = Actor.Create("truk", true, { Location = CPos.New(1,35), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(2,35))
							newactor = Actor.Create("truk", true, { Location = CPos.New(1,36), Owner = Multi1 }) newactor.ScriptedMove(CPos.New(2,36))

							newactor = Actor.Create("truk", true, { Location = CPos.New(55,20), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(54,20))
							newactor = Actor.Create("truk", true, { Location = CPos.New(55,21), Owner = Multi2 }) newactor.ScriptedMove(CPos.New(54,21))
							newactor = Actor.Create("truk", true, { Location = CPos.New(55,35), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(54,35))
							newactor = Actor.Create("truk", true, { Location = CPos.New(55,36), Owner = Multi3 }) newactor.ScriptedMove(CPos.New(54,36))
						end)
					end
				end)
			end
		end)
	end)
end

UnitCounter = { 1, 2, 3, 4, 5, 6 }


m0RandomPosition = { CPos.New(2,18), CPos.New(2,23), CPos.New(6,18), CPos.New(6,23), CPos.New(10,18), CPos.New(10,23) }
m1RandomPosition = { CPos.New(2,33), CPos.New(2,38), CPos.New(6,33), CPos.New(6,38), CPos.New(10,33), CPos.New(10,38) }
m2RandomPosition = { CPos.New(54,18), CPos.New(54,23), CPos.New(50,18), CPos.New(50,23), CPos.New(46,18), CPos.New(46,23) }
m3RandomPosition = { CPos.New(54,33), CPos.New(54,38), CPos.New(50,33), CPos.New(50,38), CPos.New(46,33), CPos.New(46,38) }
ChooserTimeOverRNDUnitset = function()
	if not ChooserBarrierBuild then
		CloseTriggers()
		ChooserBarrierBuild = true
	end
	Barb = Multi0.GetActorsByType("truk")
	for p,fences in pairs(Barb) do
		Position = Utils.Random(m0RandomPosition)
		fences.Stop()
		fences.Teleport(Position)
		Trigger.OnIdle(fences, function()
			Position = Utils.Random(m0RandomPosition)
			fences.Teleport(Position)
		end)
	end
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		Barb = Multi1.GetActorsByType("truk")
		for p,fences in pairs(Barb) do
			Position = Utils.Random(m1RandomPosition)
			fences.Stop()
			fences.Teleport(Position)
			Trigger.OnIdle(fences, function()
				Position = Utils.Random(m1RandomPosition)
				fences.Teleport(Position)
			end)
		end
		Barb = Multi2.GetActorsByType("truk")
		for p,fences in pairs(Barb) do
			Position = Utils.Random(m2RandomPosition)
			fences.Stop()
			fences.Teleport(Position)
			Trigger.OnIdle(fences, function()
				Position = Utils.Random(m2RandomPosition)
				fences.Teleport(Position)
			end)
		end
		Barb = Multi3.GetActorsByType("truk")
		for p,fences in pairs(Barb) do
			Position = Utils.Random(m3RandomPosition)
			fences.Stop()
			fences.Teleport(Position)
			Trigger.OnIdle(fences, function()
				Position = Utils.Random(m3RandomPosition)
				fences.Teleport(Position)
			end)
		end
	end)
end

countH6 = 0
countV6 = 0
CloseTriggers = function()
	if countH6 < 54 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(2,18) + CVec.New(countH6, countV6), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(2,33) + CVec.New(countH6, countV6), Owner = France })
		countH6 = countH6 + 4
		CloseTriggers()
	elseif countV6 < 4 then
		countH6 = 0
		countV6 = countV6 + 5
		CloseTriggers()
	end
end
Alliesfaction = {"germany", "france", "england"}
Sovietfaction = {"ukraine", "russia"}

Factionchecker = function()
	for i=1,4 do
		if Multi0.Faction == Alliesfaction[i] then
			M0IsAllies = true
		elseif Multi0.Faction == Sovietfaction[i] then
			M0IsSoviet = true
		end
		if Multi1.Faction == Alliesfaction[i] then
			M1IsAllies = true
		elseif Multi1.Faction == Sovietfaction[i] then
			M1IsSoviet = true
		end
		if Multi2.Faction == Alliesfaction[i] then
			M2IsAllies = true
		elseif Multi2.Faction == Sovietfaction[i] then
			M2IsSoviet = true
		end
		if Multi3.Faction == Alliesfaction[i] then
			M3IsAllies = true
		elseif Multi3.Faction == Sovietfaction[i] then
			M3IsSoviet = true
		end
	end
	if Multi0.Faction == "france" then
		M0IsFrance = true
	end
	if Multi0.Faction == "germany" then
		M0IsGerman = true
	end
	if Multi0.Faction == "england" then
		M0IsEngland = true
	end
	if Multi0.Faction == "ukraine" then
		M0IsUkraine = true
	end
	if Multi0.Faction == "russia" then
		M0IsRussia = true
	end

	if Multi1.Faction == "france" then
		M1IsFrance = true
	end
	if Multi1.Faction == "germany" then
		M1IsGerman = true
	end
	if Multi1.Faction == "england" then
		M1IsEngland = true
	end
	if Multi1.Faction == "ukraine" then
		M1IsUkraine = true
	end
	if Multi1.Faction == "russia" then
		M1IsRussia = true
	end

	if Multi2.Faction == "france" then
		M2IsFrance = true
	end
	if Multi2.Faction == "germany" then
		M2IsGerman = true
	end
	if Multi2.Faction == "england" then
		M2IsEngland = true
	end
	if Multi2.Faction == "ukraine" then
		M2IsUkraine = true
	end
	if Multi2.Faction == "russia" then
		M2IsRussia = true
	end

	if Multi3.Faction == "france" then
		M3IsFrance = true
	end
	if Multi3.Faction == "germany" then
		M3IsGerman = true
	end
	if Multi3.Faction == "england" then
		M3IsEngland = true
	end
	if Multi3.Faction == "ukraine" then
		M3IsUkraine = true
	end
	if Multi3.Faction == "russia" then
		M3IsRussia = true
	end
end
M0gapV = 0
M1gapV = 0
M2gapV = 0
M3gapV = 0
M0flyV = 0
M1flyV = 0
M2flyV = 0
M3flyV = 0

newM0gappos = CPos.New(14,4) + CVec.New(Utils.RandomInteger(0, 4), M0gapV)
newM0unitspos = CPos.New(11,2) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25))

TeleportChosenUnits = function()
--										Multi0
	allactors = Multi0.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") and v.Type ~= "round1sign" and v.Type ~= "round2sign" and v.Type ~= "round3sign" then
			if v.Type == "gap" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(14,4) + CVec.New(Utils.RandomInteger(0, 4), M0gapV), Owner = Multi0 })
				M0gapV = M0gapV + 5
				v.Destroy()
			elseif v.Type == "much.apwr" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,19), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "noredome" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,21), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "fix" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,16), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "noreafld" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(5,13) + CVec.New(0, M0flyV), Owner = Multi0 })
				if Round == 3 then
					M0flyV = M0flyV - 4
				end
				v.Destroy()
			elseif v.Type == "norehpad" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(5,13) + CVec.New(0, M0flyV), Owner = Multi0 })
				if Round == 3 then
					M0flyV = M0flyV - 4
				end
				v.Destroy()
			elseif v.Type == "noreatek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,24), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "norestek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,24), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "fastiron" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,22), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "fastpdox" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,22), Owner = Multi0 })
				v.Destroy()
			elseif v.Type == "fastmslo" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,25), Owner = Multi0 })
				v.Destroy()
			end
		end
	end
	allactors = Germany.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.HasProperty("GrantCondition") and v.AcceptsCondition("crushingunit") then
				m0actor = Actor.Create( v.Type, true, { Location = CPos.New(12,5) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 18)), Owner = Germany }) m0actor.Scatter()
				v.Destroy()
			elseif v.Type == "hind" or v.Type == "heli" or v.Type == "tran" or v.Type == "yak" or v.Type == "mig" then
				Trigger.AfterDelay(Utils.RandomInteger(45, 60), function()
					v.Teleport(CPos.New(10,5) + CVec.New(0, Utils.RandomInteger(0, 25)))
				end)
			elseif v.Type ~= "dtrk" or v.Type ~= "e7" then
				m0actor = Actor.Create( v.Type, true, { Location = CPos.New(11,5) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Germany }) m0actor.Scatter()
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
					if not m0actor.IsDead then
						m0actor.Scatter()
					end
				end)
			elseif v.Type == "dtrk" then
				m0actor = Actor.Create( v.Type, true, { Location = CPos.New(11,5) + CVec.New(Utils.RandomInteger(6, 7), Utils.RandomInteger(0, 25)), Owner = Germany })
				Beacon.New(Multi0, m0actor.CenterPosition, 500, true)
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
				end)
			end
		end
	end
--										Multi1
	allactors = Multi1.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") and v.Type ~= "round1sign" and v.Type ~= "round2sign" and v.Type ~= "round3sign" then
			if v.Type == "gap" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(14,51) + CVec.New(Utils.RandomInteger(0, 4), M1gapV), Owner = Multi1 })
				M1gapV = M1gapV - 5
				v.Destroy()
			elseif v.Type == "much.apwr" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,34), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "noredome" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,31), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "fix" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,37), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "noreafld" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(5,41) + CVec.New(0, M1flyV), Owner = Multi1 })
				if Round == 3 then
					M1flyV = M1flyV + 4
				end
				v.Destroy()
			elseif v.Type == "norehpad" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(5,41) + CVec.New(0, M1flyV), Owner = Multi1 })
				if Round == 3 then
					M1flyV = M1flyV + 4
				end
				v.Destroy()
			elseif v.Type == "noreatek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,28), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "norestek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(1,28), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "fastiron" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,32), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "fastpdox" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,32), Owner = Multi1 })
				v.Destroy()
			elseif v.Type == "fastmslo" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(4,29), Owner = Multi1 })
				v.Destroy()
			end
		end
	end
	allactors = England.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.HasProperty("GrantCondition") and v.AcceptsCondition("crushingunit") then
				m1actor = Actor.Create( v.Type, true, { Location = CPos.New(11,32) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 18)), Owner = England }) m1actor.Scatter()
				v.Destroy()
			elseif v.Type == "hind" or v.Type == "heli" or v.Type == "tran" or v.Type == "yak" or v.Type == "mig" then
				Trigger.AfterDelay(Utils.RandomInteger(45, 60), function()
					v.Teleport(CPos.New(10,24) + CVec.New(0, Utils.RandomInteger(0, 25)))
				end)
			elseif v.Type ~= "dtrk" or v.Type ~= "e7" then
				m1actor = Actor.Create( v.Type, true, { Location = CPos.New(11,24) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = England }) m1actor.Scatter()
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
					if not m1actor.IsDead then
						m1actor.Scatter()
					end
				end)
			elseif v.Type == "dtrk" then
				m1actor = Actor.Create( v.Type, true, { Location = CPos.New(11,24) + CVec.New(Utils.RandomInteger(6, 7), Utils.RandomInteger(0, 25)), Owner = England })
				Beacon.New(Multi1, m1actor.CenterPosition, 500, true)
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
				end)
			end
		end
	end
--										Multi2
	allactors = Multi2.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") and v.Type ~= "round1sign" and v.Type ~= "round2sign" and v.Type ~= "round3sign" then
			if v.Type == "gap" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(38,4) + CVec.New(Utils.RandomInteger(0, 4), M2gapV), Owner = Multi2 })
				M2gapV = M2gapV + 5
				v.Destroy()
			elseif v.Type == "much.apwr" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(53,19), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "noredome" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(54,21), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "fix" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(49,16), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "noreafld" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(49,13) + CVec.New(0, M2flyV), Owner = Multi2 })
				if Round == 3 then
					M2flyV = M2flyV - 4
				end
				v.Destroy()
			elseif v.Type == "norehpad" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(49,13) + CVec.New(0, M2flyV), Owner = Multi2 })
				if Round == 3 then
					M2flyV = M2flyV - 4
				end
				v.Destroy()
			elseif v.Type == "noreatek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(54,24), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "norestek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(54,24), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "fastiron" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(51,22), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "fastpdox" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(51,22), Owner = Multi2 })
				v.Destroy()
			elseif v.Type == "fastmslo" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(51,25), Owner = Multi2 })
				v.Destroy()
			end
		end
	end
	allactors = Russia.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.HasProperty("GrantCondition") and v.AcceptsCondition("crushingunit") then
				m2actor = Actor.Create( v.Type, true, { Location = CPos.New(38,5) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 18)), Owner = Russia }) m2actor.Scatter()
				v.Destroy()
			elseif v.Type == "hind" or v.Type == "heli" or v.Type == "tran" or v.Type == "yak" or v.Type == "mig" then
				Trigger.AfterDelay(Utils.RandomInteger(45, 60), function()
					v.Teleport(CPos.New(46,5) + CVec.New(0, Utils.RandomInteger(0, 25)))
				end)
			elseif v.Type ~= "dtrk" or v.Type ~= "e7" then
				m2actor = Actor.Create( v.Type, true, { Location = CPos.New(38,5) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Russia }) m2actor.Scatter()
				v.Destroy()
				v.Stop()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
					if not m2actor.IsDead then
						m2actor.Scatter()
					end
				end)
			elseif v.Type == "dtrk" then
				m2actor = Actor.Create( v.Type, true, { Location = CPos.New(38,5) + CVec.New(Utils.RandomInteger(0, 1), Utils.RandomInteger(0, 25)), Owner = Russia })
				Beacon.New(Multi2, m2actor.CenterPosition, 500, true)
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
				end)
			elseif v.Type == "e7" then
				v.Destroy()
			end
		end
	end
--										Multi3
	allactors = Multi3.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") and v.Type ~= "round1sign" and v.Type ~= "round2sign" and v.Type ~= "round3sign" then
			if v.Type == "gap" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(38,51) + CVec.New(Utils.RandomInteger(0, 4), M3gapV), Owner = Multi3 })
				M3gapV = M3gapV - 5
				v.Destroy()
			elseif v.Type == "much.apwr" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(53,34), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "noredome" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(54,31), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "fix" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(49,37), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "noreafld" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(49,41) + CVec.New(0, M3flyV), Owner = Multi3 })
				if Round == 3 then
					M3flyV = M3flyV + 4
				end
				v.Destroy()
			elseif v.Type == "norehpad" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(49,41) + CVec.New(0, M3flyV), Owner = Multi3 })
				if Round == 3 then
					M3flyV = M3flyV + 4
				end
				v.Destroy()
			elseif v.Type == "noreatek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(54,28), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "norestek" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(54,28), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "fastiron" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(51,31), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "fastpdox" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(51,31), Owner = Multi3 })
				v.Destroy()
			elseif v.Type == "fastmslo" then
				newactor = Actor.Create( v.Type, true, { Location = CPos.New(51,29), Owner = Multi3 })
				v.Destroy()
			end
		end
	end
	allactors = Ukraine.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.HasProperty("GrantCondition") and v.AcceptsCondition("crushingunit") then
				m3actor = Actor.Create( v.Type, true, { Location = CPos.New(38,32) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 18)), Owner = Ukraine }) m3actor.Scatter()
				v.Destroy()
			elseif v.Type == "hind" or v.Type == "heli" or v.Type == "tran" or v.Type == "yak" or v.Type == "mig" then
				Trigger.AfterDelay(Utils.RandomInteger(45, 60), function()
					v.Teleport(CPos.New(46,24) + CVec.New(0, Utils.RandomInteger(0, 25)))
				end)
			elseif v.Type ~= "dtrk" or v.Type ~= "e7" then
				m3actor = Actor.Create( v.Type, true, { Location = CPos.New(38,24) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Ukraine }) m3actor.Scatter()
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
					if not m3actor.IsDead then
						m3actor.Scatter()
					end
				end)
			elseif v.Type == "dtrk" then
				m3actor = Actor.Create( v.Type, true, { Location = CPos.New(38,24) + CVec.New(Utils.RandomInteger(0, 1), Utils.RandomInteger(0, 25)), Owner = Ukraine })
				Beacon.New(Multi3, m3actor.CenterPosition, 500, true)
				v.Stop()
				v.Destroy()
				Trigger.AfterDelay(5, function()
					if v.IsInWorld then v.Destroy() end
				end)
			elseif v.Type == "e7" then
				v.Destroy()
			end
		end
	end
	Trigger.AfterDelay(35, function()
		m0engie = Actor.Create( "e6", true, { Location = CPos.New(11,5) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Multi0 }) m0engie.Scatter()
		m1engie = Actor.Create( "e6", true, { Location = CPos.New(11,24) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Multi1 }) m1engie.Scatter()
		m2engie = Actor.Create( "e6", true, { Location = CPos.New(38,5) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Multi2 }) m2engie.Scatter()
		m3engie = Actor.Create( "e6", true, { Location = CPos.New(38,24) + CVec.New(Utils.RandomInteger(0, 7), Utils.RandomInteger(0, 25)), Owner = Multi3 }) m3engie.Scatter()
	end)
end

CleanBattleground = function()
	allactors = France.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Destroy()
		end
	end
	allactors = Multi0.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Stop()
			v.Destroy()
		end
	end
	allactors = Multi1.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Stop()
			v.Destroy()
		end
	end
	allactors = Multi2.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Stop()
			v.Destroy()
		end
	end
	allactors = Multi3.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Stop()
			v.Destroy()
		end
	end
	Trigger.AfterDelay(5, function()
		allactors = Multi0.GetActors()
		for i,v in pairs(allactors) do
			if v.HasProperty("Health") then
				v.Owner = Golden
				v.Stop()
				v.Destroy()
				Trigger.OnIdle(v, function()
					v.Destroy()
				end)
			end
		end
		allactors = Multi1.GetActors()
		for i,v in pairs(allactors) do
			if v.HasProperty("Health") then
				v.Owner = Golden
				v.Stop()
				v.Destroy()
				Trigger.OnIdle(v, function()
					v.Destroy()
				end)
			end
		end
		allactors = Multi2.GetActors()
		for i,v in pairs(allactors) do
			if v.HasProperty("Health") then
				v.Owner = Golden
				v.Stop()
				v.Destroy()
				Trigger.OnIdle(v, function()
					v.Destroy()
				end)
			end
		end
		allactors = Multi3.GetActors()
		for i,v in pairs(allactors) do
			if v.HasProperty("Health") then
				v.Owner = Golden
				v.Stop()
				v.Destroy()
				Trigger.OnIdle(v, function()
					v.Destroy()
				end)
			end
		end
	end)
end

RemoveMap = function()
	Barb = France.GetActorsByType("nix01")
	for p,fences in pairs(Barb) do
		fences.Destroy()
	end
	Barb = France.GetActorsByType("nix03")
	for p,fences in pairs(Barb) do
		fences.Destroy()
	end

	allactors = Multi0.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.Type ~= "fastiron" and v.Type ~= "fastpdox" and v.Type ~= "fastmslo" and v.Type ~= "much.apwr" and v.Type ~= "gap"  and v.Type ~= "noredome" and v.Type ~= "fix" and v.Type ~= "noreatek" and v.Type ~= "norestek" and v.Type ~= "norehpad" and v.Type ~= "noreafld" then
				v.Destroy()
			end
		end
	end
	allactors = Multi1.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.Type ~= "fastiron" and v.Type ~= "fastpdox" and v.Type ~= "fastmslo" and v.Type ~= "much.apwr" and v.Type ~= "gap"  and v.Type ~= "noredome" and v.Type ~= "fix" and v.Type ~= "noreatek" and v.Type ~= "norestek" and v.Type ~= "norehpad" and v.Type ~= "noreafld" then
				v.Destroy()
			end
		end
	end
	allactors = Multi2.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.Type ~= "fastiron" and v.Type ~= "fastpdox" and v.Type ~= "fastmslo" and v.Type ~= "much.apwr" and v.Type ~= "gap"  and v.Type ~= "noredome" and v.Type ~= "fix" and v.Type ~= "noreatek" and v.Type ~= "norestek" and v.Type ~= "norehpad" and v.Type ~= "noreafld" then
				v.Destroy()
			end
		end
	end
	allactors = Multi3.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			if v.Type ~= "fastiron" and v.Type ~= "fastpdox" and v.Type ~= "fastmslo" and v.Type ~= "much.apwr" and v.Type ~= "gap"  and v.Type ~= "noredome" and v.Type ~= "fix" and v.Type ~= "noreatek" and v.Type ~= "norestek" and v.Type ~= "norehpad" and v.Type ~= "noreafld" then
				v.Destroy()
			end
		end
	end
	allactors = Golden.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Stop()
			v.Destroy()
			Trigger.OnIdle(v, function()
				v.Destroy()
			end)
		end
	end
end

RemoveGolden = function()
	allactors = Golden.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Stop()
			v.Destroy()
		end
	end
end

Allfactions = { "ukraine", "russia", "germany", "france", "england" }

SetupPlayers = function()
	France = Player.GetPlayer("france")
	Germany = Player.GetPlayer("germany")
	England = Player.GetPlayer("england")
	Russia = Player.GetPlayer("russia")
	Ukraine = Player.GetPlayer("ukraine")
	Golden = Player.GetPlayer("golden")
	Neutral = Player.GetPlayer("Neutral")
	Creeps = Player.GetPlayer("Creeps")
	Multi0 = Player.GetPlayer("Multi0")
	if Multi0 == nil then
		Multi0 = Player.GetPlayer("Multi1")
		if Multi0 == nil then
			Multi0 = Player.GetPlayer("Creeps")
		end
	end
	allactors = Multi0.GetActors()
	for i,v in pairs(allactors) do
		if v.Type == "mcv" then
			v.Destroy()
		end
	end
	Multi1 = Player.GetPlayer("Multi1")
	if Multi1 == nil then
		Multi1 = Player.GetPlayer("Multi0")
		if Multi1 == nil then
			Multi1 = Player.GetPlayer("Creeps")
		end
	end
	allactors = Multi1.GetActors()
	for i,v in pairs(allactors) do
		if v.Type == "mcv" then
			v.Destroy()
		end
	end
	Multi2 = Player.GetPlayer("Multi2")
	if Multi2 == nil then
		Multi2 = Player.GetPlayer("Multi3")
		if Multi2 == nil then
			Multi2 = Player.GetPlayer("Creeps")
		end
	end
	allactors = Multi2.GetActors()
	for i,v in pairs(allactors) do
		if v.Type == "mcv" then
			v.Destroy()
		end
	end
	Multi3 = Player.GetPlayer("Multi3")
	if Multi3 == nil then
		Multi3 = Player.GetPlayer("Multi2")
		if Multi3 == nil then
			Multi3 = Player.GetPlayer("Creeps")
		end
	end
	allactors = Multi3.GetActors()
	for i,v in pairs(allactors) do
		if v.Type == "mcv" then
			v.Destroy()
		end
	end
	AllPlayers = { Multi0, Multi1, Multi2, Multi3 }
end

Light = 0

turnOn = function()
	Lighting.Ambient = Light
	if Light < 1 then
		Light = Light + 0.009
		Trigger.AfterDelay(1, function()
			turnOn()
		end)
	end
end
turnOff = function()
	Lighting.Ambient = Light
	if Light > 0.05 then
		Light = Light - 0.035
		Trigger.AfterDelay(1, function()
			turnOff()
		end)
	else
		Trigger.AfterDelay(23, function()
			ShowFightSign()
		end)
		Trigger.AfterDelay(102, function()
			turnOn()
		end)
	end
end

turnOffAfterBattle = function()
	Lighting.Ambient = Light
	if Light > 0.03 then
		Light = Light - 0.025
		Trigger.AfterDelay(1, function()
			turnOffAfterBattle()
		end)
	else
		CleanBattleground()
		Trigger.AfterDelay(11, function()
			ShowRoundSign()
			Trigger.AfterDelay(122, function()
				turnOn()
			end)
		end)
	end
end
EndGameturnOff = function()
	Lighting.Ambient = Light
	if Light > 0.02 then
		Light = Light - 0.007
		Trigger.AfterDelay(1, function()
			EndGameturnOff()
		end)
	elseif Team1Wins > Team2Wins then
		CleanBattleground()
		Trigger.AfterDelay(35, function()
			Team1WinTheGame()
		end)
	else
		CleanBattleground()
		Trigger.AfterDelay(35, function()
			Team2WinTheGame()
		end)
	end
end
SetCamera = function(Multi)
	local Apower = Multi.GetActorsByType("dummyactor")[1]
	Camera.Position = Apower.CenterPosition
end

ShowFightSign = function()
	sign = Actor.Create( "fightsign", true, { Location = CPos.New(27,27), Owner = Creeps })
	T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi0 })
	T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi2 })
	Camera.Position = sign.CenterPosition
	Trigger.AfterDelay(95, function()
		if Multi0.IsLocalPlayer then
			SetCamera(Multi0)
		elseif Multi1.IsLocalPlayer then
			SetCamera(Multi1)
		elseif Multi2.IsLocalPlayer then
			SetCamera(Multi2)
		elseif Multi3.IsLocalPlayer then
			SetCamera(Multi3)
		end
	end)
	Trigger.AfterDelay(88, function()
		Barb = Multi0.GetActorsByType("smallsight")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then fences.Destroy() end
			fences.Destroy()
		end
		Barb = Multi2.GetActorsByType("smallsight")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then fences.Destroy() end
		end
		Barb = Creeps.GetActorsByType("fightsign")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then fences.Destroy() end
		end
		Trigger.AfterDelay(55, function()
			if Round == 1 then
				nextsign = Actor.Create( "round1sign", true, { Location = CPos.New(25,2), Owner = RandomPlayer })
				nextsign = Actor.Create( "round1sign", true, { Location = CPos.New(25,52), Owner = RandomPlayer })
				Trigger.AfterDelay(105, function()
					Media.DisplayMessage("Units wich cause stalemate situations dont have to be destroyed!\n(except the engie)", "Game-Brain", Red)
					Trigger.AfterDelay(225, function()
						Media.DisplayMessage("You can win by destroying all relevant enemy units\nor capture all 4 flags and hold it for 30 seconds", "Game-Brain", Red)
						Trigger.AfterDelay(351, function()
							Media.DisplayMessage("You can capture the enemys flag by moving a unit close to it!", "Game-Brain", Red)
						end)
					end)
				end)
			elseif Round == 2 then
				nextsign = Actor.Create( "round2sign", true, { Location = CPos.New(25,2), Owner = RandomPlayer })
				nextsign = Actor.Create( "round2sign", true, { Location = CPos.New(25,52), Owner = RandomPlayer })
				Trigger.AfterDelay(125, function()
					Media.DisplayMessage("Buildings dont have to be destroyed to win the game!", "Game-Brain", Red)
				end)
			elseif Round == 3 then
				nextsign = Actor.Create( "round3sign", true, { Location = CPos.New(25,2), Owner = RandomPlayer })
				nextsign = Actor.Create( "round3sign", true, { Location = CPos.New(25,52), Owner = RandomPlayer })
			end
		end)
	end)
end

ShowRoundSign = function()
	RandomPlayer =  Utils.Random(AllPlayers)
	if Round == 1 then
		sign = Actor.Create( "round1sign", true, { Location = CPos.New(27,27), Owner = RandomPlayer })
		T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi0 })
		T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi2 })
		Camera.Position = sign.CenterPosition
		Trigger.AfterDelay(105, function()
			if sign.IsInWorld then sign.Destroy() end
			if T1Sight.IsInWorld then T1Sight.Destroy() end
			if T2Sight.IsInWorld then T2Sight.Destroy() end
			nextsign = Actor.Create( "round1sign", true, { Location = CPos.New(26,3), Owner = RandomPlayer })
			nextsign = Actor.Create( "round1sign", true, { Location = CPos.New(26,51), Owner = RandomPlayer })
			T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,2), Owner = Multi0 })
			T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,2), Owner = Multi2 })
			T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,53), Owner = Multi0 })
			T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,53), Owner = Multi2 })
		end)
	end
	if Round == 2 then
		sign = Actor.Create( "round2sign", true, { Location = CPos.New(27,27), Owner = RandomPlayer })
		T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi0 })
		T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi2 })
		Camera.Position = sign.CenterPosition
		Trigger.AfterDelay(105, function()
			if sign.IsInWorld then sign.Destroy() end
			if T1Sight.IsInWorld then T1Sight.Destroy() end
			if T2Sight.IsInWorld then T2Sight.Destroy() end
			nextsign = Actor.Create( "round2sign", true, { Location = CPos.New(26,3), Owner = RandomPlayer })
			nextsign = Actor.Create( "round2sign", true, { Location = CPos.New(26,51), Owner = RandomPlayer })
			T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,2), Owner = Multi0 })
			T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,2), Owner = Multi2 })
			T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,53), Owner = Multi0 })
			T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,53), Owner = Multi2 })
		end)
	end
	if Round == 3 then
		sign = Actor.Create( "round3sign", true, { Location = CPos.New(27,27), Owner = RandomPlayer })
		T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi0 })
		T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,27), Owner = Multi2 })
		Camera.Position = sign.CenterPosition
		Trigger.AfterDelay(105, function()
			if sign.IsInWorld then sign.Destroy() end
			if T1Sight.IsInWorld then T1Sight.Destroy() end
			if T2Sight.IsInWorld then T2Sight.Destroy() end
			nextsign = Actor.Create( "round3sign", true, { Location = CPos.New(26,3), Owner = RandomPlayer })
			nextsign = Actor.Create( "round3sign", true, { Location = CPos.New(26,51), Owner = RandomPlayer })
			T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,2), Owner = Multi0 })
			T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,2), Owner = Multi2 })
			T1Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,53), Owner = Multi0 })
			T2Sight = Actor.Create( "smallsight", true, { Location = CPos.New(28,53), Owner = Multi2 })
		end)
	end
	Trigger.AfterDelay(95, function()
		if Multi0.IsLocalPlayer then
			SetCamera(Multi0)
		elseif Multi1.IsLocalPlayer then
			SetCamera(Multi1)
		elseif Multi2.IsLocalPlayer then
			SetCamera(Multi2)
		elseif Multi3.IsLocalPlayer then
			SetCamera(Multi3)
		end
	end)
end


unitswap = function()
	allactors = Germany.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Owner = Multi0
--			if v.HasProperty("Mobile") then
		end
	end

	allactors = England.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Owner = Multi1
		end
	end

	allactors = Russia.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Owner = Multi2
		end
	end

	allactors = Ukraine.GetActors()
	for i,v in pairs(allactors) do
		if v.HasProperty("Health") then
			v.Owner = Multi3
		end
	end

end

PlayerReadyChecker = function()
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi0.HasNoRequiredUnits() and not multi0choseUnits then
		multi0choseUnits = true
		Media.DisplayMessage("".. Multi0.Name .. " is ready!", "Game-Brain", Red)
	end
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi1.HasNoRequiredUnits() and not multi1choseUnits then
		multi1choseUnits = true
		Media.DisplayMessage("".. Multi1.Name .. " is ready!", "Game-Brain", Red)
	end
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi2.HasNoRequiredUnits() and not multi2choseUnits then
		multi2choseUnits = true
		Media.DisplayMessage("".. Multi2.Name .. " is ready!", "Game-Brain", Red)
	end
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi3.HasNoRequiredUnits() and not multi3choseUnits then
		multi3choseUnits = true
		Media.DisplayMessage("".. Multi3.Name .. " is ready!", "Game-Brain", Red)
	end
	if multi0choseUnits == true and multi1choseUnits == true and multi2choseUnits == true and multi3choseUnits == true then
		Media.DisplayMessage("All Players are ready, lets start the ...", "Game-Brain", Red)
		AllPlayerReady = true
		chooseTime = false
		Trigger.AfterDelay(25, function()
			Gamestarter()
			turnOff()
		end)
	end
end

Team1Wins = 0
Team2Wins = 0

PlayerDeadChecker = function()
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi0.HasNoRequiredUnits() and not multi0LostRound then
		multi0LostRound = true
		Media.DisplayMessage("".. Multi0.Name .. " has no more relevant units!", "Game-Brain", Red)
	end
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi1.HasNoRequiredUnits() and not multi1LostRound then
		multi1LostRound = true
		Media.DisplayMessage("".. Multi1.Name .. " has no more relevant units!", "Game-Brain", Red)
	end
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi2.HasNoRequiredUnits() and not multi2LostRound then
		multi2LostRound = true
		Media.DisplayMessage("".. Multi2.Name .. " has no more relevant units!", "Game-Brain", Red)
	end
	if DateTime.GameTime > DateTime.Seconds(10) and  Multi3.HasNoRequiredUnits() and not multi3LostRound then
		multi3LostRound = true
		Media.DisplayMessage("".. Multi3.Name .. " has no more relevant units!", "Game-Brain", Red)
	end
	if multi0LostRound == true and multi1LostRound == true then
		if Round == 1 then
			Multi2.MarkCompletedObjective(WinRound1P3) 
			Multi3.MarkCompletedObjective(WinRound1P4)
			Multi0.MarkFailedObjective(WinRound1P1)
			Multi1.MarkFailedObjective(WinRound1P2)
		elseif Round == 2 then
			Multi2.MarkCompletedObjective(WinRound2P3) 
			Multi3.MarkCompletedObjective(WinRound2P4)
			Multi0.MarkFailedObjective(WinRound2P1)
			Multi1.MarkFailedObjective(WinRound2P2)
		elseif Round == 3 then
			Multi2.MarkCompletedObjective(WinRound3P3) 
			Multi3.MarkCompletedObjective(WinRound3P4)
			Multi0.MarkFailedObjective(WinRound3P1)
			Multi1.MarkFailedObjective(WinRound3P2)
		end
		Team2Wins = Team2Wins + 1
		Media.PlaySoundNotification( allplayers, "AlertBuzzer")
		Media.DisplayMessage(" " .. Multi2.Name .. " and " .. Multi3.Name .. " win round " .. Round .. " !", "Game-Brain", Red)
		EndRound()
	end
	if multi2LostRound == true and multi3LostRound == true then
		if Round == 1 then
			Multi0.MarkCompletedObjective(WinRound1P1) 
			Multi1.MarkCompletedObjective(WinRound1P2)
			Multi2.MarkFailedObjective(WinRound1P3)
			Multi3.MarkFailedObjective(WinRound1P4)
		elseif Round == 2 then
			Multi0.MarkCompletedObjective(WinRound2P1) 
			Multi1.MarkCompletedObjective(WinRound2P2)
			Multi2.MarkFailedObjective(WinRound2P3)
			Multi3.MarkFailedObjective(WinRound2P4)
		elseif Round == 3 then
			Multi0.MarkCompletedObjective(WinRound3P1) 
			Multi1.MarkCompletedObjective(WinRound3P2)
			Multi2.MarkFailedObjective(WinRound3P3)
			Multi3.MarkFailedObjective(WinRound3P4)
		end
		Team1Wins = Team1Wins + 1
		Media.PlaySoundNotification( allplayers, "AlertBuzzer")
		Media.DisplayMessage(" " .. Multi0.Name .. " and " .. Multi1.Name .. " win round " .. Round .. " !", "Game-Brain", Red)
		EndRound()
	end
end

EndRound = function()
	NoBattle = true
	if Round < 3 then
		StartnextRound()
	elseif Round == 3 then
		Media.PlaySpeechNotification( allplayers, "ThirdObjectiveMet")
		EndGameturnOff()
		Trigger.AfterDelay(DateTime.Seconds(4), function()
			PlayAnySpeech()
		end)
	end
end

Speeches = { "AlliedForcesApproaching", "AlliedForcesFallen", "AlliedForcesSelected", "AlliedReinforcementsArrived", "AlliedReinforcementsEast", "AlliedReinforcementsNorth", "AlliedReinforcementsSouth", "AlliedReinforcementsWest", "ChronosphereTestSuccessful", "CommandCenterAttack", "CommandoFreed", "CommandoRescued", "ControlCenterDeactivated", "ConvoyUnitLost", "EnemyUnitsApproaching", "EnemyDetected", "ExplosiveChargePlaced", "HarvesterAttack", "KosyginFreed", "KosyginRescued", "MercenaryFreed", "MercenaryRescued", "SignalFlare", "SignalFlareEast", "SignalFlareNorth", "SignalFlareSouth", "SignalFlareWest", "SovietEmpireFallen", "SovietEmpireSelected", "SovietForcesApproaching", "SovietForcesFallen", "SovietReinforcementsArrived", "GameSaved", "TanyaFreed", "TanyaRescued", "TargetFreed", "TargetRescued", "UnitArmorUpgraded", "UnitFirepowerUpgraded", "UnitFull", "UnitSpeedUpgraded", "MissionTimerInitialised" }

PlayAnySpeech = function()
	AnySpeech = Utils.Random(Speeches)
	Media.PlaySpeechNotification( allplayers, AnySpeech)
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(4, 5)), function()
		PlayAnySpeech()
	end)
end

Team1WinTheGame = function()
	Media.PlaySoundNotification( allplayers, "AlertBleep")
	Media.PlaySoundNotification( allplayers, "Beacon")
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(27,27), Owner = Multi1 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(27,27), Owner = Multi2 })
	Media.DisplayMessage("Well done " .. Multi0.Name .. " and " .. Multi1.Name .. "", "Game-Brain", Red)
	congratactor = Actor.Create( "flycongrat", true, { Location = CPos.New(27,20), Owner = Multi3 })
	Camera.Position = congratactor.CenterPosition
	newactor1 = Actor.Create( "flyname", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi0 }) 
	newactor1.AttackMove(CPos.New(27,24))
	Trigger.OnIdle(newactor1, function()
		newactor1.AttackMove(CPos.New(27,24))
	end)
	newactor2 = Actor.Create( "flyand", true, { Location = CPos.New(1,55) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi0 }) 
	newactor2.AttackMove(CPos.New(27,27))
	Trigger.OnIdle(newactor2, function()
		newactor2.AttackMove(CPos.New(27,27))
	end)
	newactor3 = Actor.Create( "flyname", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi1 }) 
	newactor3.AttackMove(CPos.New(27,32))
	Trigger.OnIdle(newactor3, function()
		newactor3.AttackMove(CPos.New(27,32))
	end)
	newactor4 = Actor.Create( "flywin", true, { Location = CPos.New(1,55) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi1 }) 
	newactor4.AttackMove(CPos.New(27,36))
	Trigger.OnIdle(newactor4, function()
		newactor4.AttackMove(CPos.New(27,36))
	end)
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,20) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi2 })
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,20) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi2 })
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,20) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi3 })
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,20) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi3 })
	Trigger.AfterDelay(DateTime.Seconds(22), function()
		Multi0.MarkCompletedObjective(WinGameP1) 
		Multi1.MarkCompletedObjective(WinGameP2)
		Multi2.MarkFailedObjective(WinGameP3)
		Multi3.MarkFailedObjective(WinGameP4)
	end)
end
Team2WinTheGame = function()
	Media.PlaySoundNotification( allplayers, "AlertBleep")
	Media.PlaySoundNotification( allplayers, "Beacon")
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(27,27), Owner = Multi1 })
	newactor = Actor.Create("bigsight", true, { Location = CPos.New(27,27), Owner = Multi2 })
	Media.DisplayMessage("Well done " .. Multi2.Name .. " and " .. Multi3.Name .. "", "Game-Brain", Red)
	congratactor = Actor.Create( "flycongrat", true, { Location = CPos.New(27,20), Owner = Multi1 })
	Camera.Position = congratactor.CenterPosition
	newactor1 = Actor.Create( "flyname", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi2 }) 
	newactor1.AttackMove(CPos.New(27,24))
	Trigger.OnIdle(newactor1, function()
		newactor1.AttackMove(CPos.New(27,24))
	end)
	newactor2 = Actor.Create( "flyand", true, { Location = CPos.New(1,55) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi2 }) 
	newactor2.AttackMove(CPos.New(27,28))
	Trigger.OnIdle(newactor2, function()
		newactor2.AttackMove(CPos.New(27,28))
	end)
	newactor3 = Actor.Create( "flyname", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi3 }) 
	newactor3.AttackMove(CPos.New(27,32))
	Trigger.OnIdle(newactor3, function()
		newactor3.AttackMove(CPos.New(27,32))
	end)
	newactor4 = Actor.Create( "flywin", true, { Location = CPos.New(1,55) + CVec.New(Utils.RandomInteger(0, 54), 0), Owner = Multi3 }) 
	newactor4.AttackMove(CPos.New(27,36))
	Trigger.OnIdle(newactor4, function()
		newactor4.AttackMove(CPos.New(27,36))
	end)
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,22) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi0 })
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,22) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi0 })
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,22) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi1 })
	newactor = Actor.Create( "e6", true, { Location = CPos.New(27,22) + CVec.New(0, Utils.RandomInteger(0, 12)), Owner = Multi1 })
	Trigger.AfterDelay(DateTime.Seconds(22), function()
		Multi2.MarkCompletedObjective(WinGameP3) 
		Multi3.MarkCompletedObjective(WinGameP4)
		Multi0.MarkFailedObjective(WinGameP1)
		Multi1.MarkFailedObjective(WinGameP2)
	end)
end

StartnextRound = function()
	Round = Round + 1
	countH1 = 0
	countH2 = 0
	countH3 = 0
	countH4 = 0
	countH5 = 0
	countH6 = 0
	countV3 = 0
	countV4 = 0
	countV5 = 0
	countV6 = 0
	countVF1 = 0
	countHF1 = 0
	countVF2 = 0
	countHF2 = 0
	M0hpad1 = false
	M1hpad1 = false
	M2hpad1 = false
	M3hpad1 = false
	M0afld1 = false
	M1afld1 = false
	M2afld1 = false
	M3afld1 = false
	multi0choseUnits = false
	multi1choseUnits = false
	multi2choseUnits = false
	multi3choseUnits = false
	ChooserBarrierBuild = false
	Team1warning = false
	Team2warning = false
	turnOffAfterBattle()



	Trigger.AfterDelay(100, function()
		StartUnitChooser()
		Trigger.AfterDelay(5, function()
			AllPlayerReady = false
			multi0LostRound = false
			multi1LostRound = false
			multi2LostRound = false
			multi3LostRound = false
		end)
	end)
	if Round == 2 then
		Media.PlaySpeechNotification( allplayers, "FirstObjectiveMet")
		ChoosingTime = DateTime.Seconds(75)
		M0e1Counter = 0
		M0Maxe1 = 5
		M0e3Counter =0
		M0Maxe3 = 5
		M0civCounter = 0
		M0Maxciv = 3
		M0mediCounter =0
		M0Maxmedi = 3
		M01tnkCounter = 0
		M0Max1tnk = 4
		M0jeepCounter =0
		M0Maxjeep = 4
		M0e2Counter = 0
		M0Maxe2 = 4
		M0dogCounter =0
		M0Maxdog = 4
		M0apcCounter = 0
		M0Maxapc = 2
		M0ftrkCounter =0
		M0Maxftrk = 4
		M0e4Counter =0

		M1e1Counter = 0
		M1Maxe1 = 5
		M1e3Counter =0
		M1Maxe3 = 5
		M1civCounter = 0
		M1Maxciv = 3
		M1mediCounter =0
		M1Maxmedi = 3
		M11tnkCounter = 0
		M1Max1tnk = 4
		M1jeepCounter =0
		M1Maxjeep = 4
		M1e2Counter = 0
		M1Maxe2 = 4
		M1dogCounter =0
		M1Maxdog = 4
		M1apcCounter = 0
		M1Maxapc = 2
		M1ftrkCounter =0
		M1Maxftrk = 4
		M1e4Counter =0

		M2e1Counter = 0
		M2Maxe1 = 5
		M2e3Counter =0
		M2Maxe3 = 5
		M2civCounter = 0
		M2Maxciv = 3
		M2mediCounter =0
		M2Maxmedi = 3
		M21tnkCounter = 0
		M2Max1tnk = 4
		M2jeepCounter =0
		M2Maxjeep = 4
		M2e2Counter = 0
		M2Maxe2 = 4
		M2dogCounter =0
		M2Maxdog = 4
		M2apcCounter = 0
		M2Maxapc = 2
		M2ftrkCounter =0
		M2Maxftrk = 4
		M2e4Counter =0

		M3e1Counter = 0
		M3Maxe1 = 5
		M3e3Counter =0
		M3Maxe3 = 5
		M3civCounter = 0
		M3Maxciv = 3
		M3mediCounter =0
		M3Maxmedi = 3
		M31tnkCounter = 0
		M3Max1tnk = 4
		M3jeepCounter =0
		M3Maxjeep = 4
		M3e2Counter = 0
		M3Maxe2 = 4
		M3dogCounter =0
		M3Maxdog = 4
		M3apcCounter = 0
		M3Maxapc = 2
		M3ftrkCounter =0
		M3Maxftrk = 4
		M3e4Counter =0
	end
	if Round == 3 then
		Media.PlaySpeechNotification( allplayers, "SecondObjectiveMet")
		ChoosingTime = DateTime.Seconds(90)
		M0e1Counter = 0
		M0Maxe1 = 8
		M0e3Counter =0
		M0Maxe3 = 8
		M0civCounter = 0
		M0Maxciv = 5
		M0mediCounter =0
		M0Maxmedi = 5
		M01tnkCounter = 0
		M0Max1tnk = 7
		M0jeepCounter =0
		M0Maxjeep = 7
		M0e2Counter = 0
		M0Maxe2 = 7
		M0dogCounter =0
		M0Maxdog = 6
		M0apcCounter = 0
		M0Maxapc = 7
		M0ftrkCounter =0
		M0Maxftrk = 8
		M0e4Counter =0
		M0Maxe4 = 7

		M1e1Counter = 0
		M1Maxe1 = 8
		M1e3Counter =0
		M1Maxe3 = 8
		M1civCounter = 0
		M1Maxciv = 5
		M1mediCounter =0
		M1Maxmedi = 5
		M11tnkCounter = 0
		M1Max1tnk = 7
		M1jeepCounter =0
		M1Maxjeep = 7
		M1e2Counter = 0
		M1Maxe2 = 7
		M1dogCounter =0
		M1Maxdog = 6
		M1apcCounter = 0
		M1Maxapc = 7
		M1ftrkCounter =0
		M1Maxftrk = 8
		M1e4Counter =0
		M1Maxe4 = 7

		M2e1Counter = 0
		M2Maxe1 = 8
		M2e3Counter =0
		M2Maxe3 = 8
		M2civCounter = 0
		M2Maxciv = 5
		M2mediCounter =0
		M2Maxmedi = 5
		M21tnkCounter = 0
		M2Max1tnk = 7
		M2jeepCounter =0
		M2Maxjeep = 7
		M2e2Counter = 0
		M2Maxe2 = 7
		M2dogCounter =0
		M2Maxdog = 6
		M2apcCounter = 0
		M2Maxapc = 7
		M2ftrkCounter =0
		M2Maxftrk = 8
		M2e4Counter =0
		M2Maxe4 = 7

		M3e1Counter = 0
		M3Maxe1 = 8
		M3e3Counter =0
		M3Maxe3 = 8
		M3civCounter = 0
		M3Maxciv = 5
		M3mediCounter =0
		M3Maxmedi = 5
		M31tnkCounter = 0
		M3Max1tnk = 7
		M3jeepCounter =0
		M3Maxjeep = 7
		M3e2Counter = 0
		M3Maxe2 = 7
		M3dogCounter =0
		M3Maxdog = 6
		M3apcCounter = 0
		M3Maxapc = 7
		M3ftrkCounter =0
		M3Maxftrk = 8
		M3e4Counter =0
		M3Maxe4 = 7


		M02tnkCounter =0
		M0Max2tnk = 8
		M0artyCounter = 0
		M0Maxarty = 8
		M0mechCounter =0
		M0Maxmech = 7
		M0hindCounter =0
		M0Maxhind = 5

		M12tnkCounter =0
		M1Max2tnk = 8
		M1artyCounter = 0
		M1Maxarty = 8
		M1mechCounter =0
		M1Maxmech = 7
		M1hindCounter =0
		M1Maxhind = 5

		M22tnkCounter =0
		M2Max2tnk = 8
		M2artyCounter = 0
		M2Maxarty = 8
		M2mechCounter =0
		M2Maxmech = 7
		M2hindCounter =0
		M2Maxhind = 5

		M32tnkCounter =0
		M3Max2tnk = 8
		M3artyCounter = 0
		M3Maxarty = 8
		M3mechCounter =0
		M3Maxmech = 7
		M3hindCounter =0
		M3Maxhind = 5

		M03tnkCounter =0
		M0Max3tnk = 7
		M0v2rlCounter = 0
		M0Maxv2rl = 8
		M0yakCounter =0
		M0Maxyak = 5

		M13tnkCounter =0
		M1Max3tnk = 7
		M1v2rlCounter = 0
		M1Maxv2rl = 8
		M1yakCounter =0
		M1Maxyak = 5

		M23tnkCounter =0
		M2Max3tnk = 7
		M2v2rlCounter = 0
		M2Maxv2rl = 8
		M2yakCounter =0
		M2Maxyak = 5

		M33tnkCounter =0
		M3Max3tnk = 7
		M3v2rlCounter = 0
		M3Maxv2rl = 8
		M3yakCounter =0
		M3Maxyak = 5
	end
end

Gamestarter = function()
	Trigger.AfterDelay(DateTime.Seconds(2), function()
		RemoveMap()
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			TeleportChosenUnits()
			Trigger.AfterDelay(5, function()
				MakeBattleGround()
				Trigger.AfterDelay(DateTime.Seconds(1), function()
					unitswap()
					Trigger.AfterDelay(DateTime.Seconds(1), function()
						Media.PlaySpeechNotification( allplayers, "StartGame")
						Team1WinTime = DateTime.Seconds(30)
						Team2WinTime = DateTime.Seconds(30)
						GpsMaker()
						NoBattle = false
						CheckFlagOwners()
					end)
				end)
			end)
		end)
	end)
end
NoBattle = true
ChoosingTime = DateTime.Seconds(60)
chooseTime = false
AllPlayerReady = true
Red = HSLColor.Red
TimerColor = HSLColor.White
Team1WinTime = DateTime.Seconds(30)
Team2WinTime = DateTime.Seconds(30)
Tick = function()
	if not AllPlayerReady then
		PlayerReadyChecker()
	end
	if not NoBattle then
		PlayerDeadChecker()
	end
	if chooseTime then
		if ChoosingTime > DateTime.Seconds(10) then
			TimerColor = HSLColor.White
		else TimerColor = Red end

		if ChoosingTime >= 0 then
			UserInterface.SetMissionText("ChooseTime: " .. Utils.FormatTime(ChoosingTime) .. " Seconds", TimerColor)
			ChoosingTime = ChoosingTime - 1
		else
			UserInterface.SetMissionText(" ", TimerColor)
			chooseTime = false
			ChooserTimeOverRNDUnitset()
		end
	elseif not NoBattle and Team1ownsallFlags and Team1WinTime >= 0 then
		UserInterface.SetMissionText("All flags captured Team 1 win Round ".. Round .. " in: " .. Utils.FormatTime(Team1WinTime) .. " Seconds", Red)
		Team1WinTime = Team1WinTime - 1
		if not Team2warning then
			Media.DisplayMessage("" .. Multi2.Name .. " and " .. Multi3.Name .. " move a unit close to a flag to recapture it!" , "Game-Brain", Red)
			Media.PlaySoundNotification( allplayers, "AlertBuzzer")
			Team2warning = true
		end
		if Team1WinTime == 0 then
			Team1Wins = Team1Wins + 1
			if Round == 1 then
				Multi0.MarkCompletedObjective(WinRound1P1) 
				Multi1.MarkCompletedObjective(WinRound1P2)
				Multi2.MarkFailedObjective(WinRound1P3)
				Multi3.MarkFailedObjective(WinRound1P4)
			elseif Round == 2 then
				Multi0.MarkCompletedObjective(WinRound2P1) 
				Multi1.MarkCompletedObjective(WinRound2P2)
				Multi2.MarkFailedObjective(WinRound2P3)
				Multi3.MarkFailedObjective(WinRound2P4)
			elseif Round == 3 then
				Multi0.MarkCompletedObjective(WinRound3P1) 
				Multi1.MarkCompletedObjective(WinRound3P2)
				Multi2.MarkFailedObjective(WinRound3P3)
				Multi3.MarkFailedObjective(WinRound3P4)
			end
			Media.DisplayMessage(" " .. Multi0.Name .. " and " .. Multi1.Name .. " owned all flags for 30 seconds, they win round " .. Round .. " !", "Game-Brain", Red)
			EndRound()
		end
	elseif not NoBattle and Team2ownsallFlags and Team2WinTime >= 0 then
		UserInterface.SetMissionText("All flags captured Team 2 win Round ".. Round .. " in: " .. Utils.FormatTime(Team2WinTime) .. " Seconds", Red)
		Team2WinTime = Team2WinTime - 1
		if not Team1warning then
			Media.DisplayMessage("" .. Multi0.Name .. " and " .. Multi1.Name .. " move a unit close to a flag to recapture it!" , "Game-Brain", Red)
			Media.PlaySoundNotification( allplayers, "AlertBuzzer")
			Team1warning = true
		end
		if Team2WinTime == 0 then
			Team2Wins = Team2Wins + 1
			if Round == 1 then
				Multi2.MarkCompletedObjective(WinRound1P3) 
				Multi3.MarkCompletedObjective(WinRound1P4)
				Multi0.MarkFailedObjective(WinRound1P1)
				Multi1.MarkFailedObjective(WinRound1P2)
			elseif Round == 2 then
				Multi2.MarkCompletedObjective(WinRound2P3) 
				Multi3.MarkCompletedObjective(WinRound2P4)
				Multi0.MarkFailedObjective(WinRound2P1)
				Multi1.MarkFailedObjective(WinRound2P2)
			elseif Round == 3 then
				Multi2.MarkCompletedObjective(WinRound3P3) 
				Multi3.MarkCompletedObjective(WinRound3P4)
				Multi0.MarkFailedObjective(WinRound3P1)
				Multi1.MarkFailedObjective(WinRound3P2)
			end
			Media.DisplayMessage(" " .. Multi2.Name .. " and " .. Multi3.Name .. " owned all flags for 30 seconds, they win round " .. Round .. " !", "Game-Brain", Red)
			EndRound()
		end
	else
		UserInterface.SetMissionText(" ", TimerColor)
	end
end
