countH1 = 0
countH2 = 0
countH3 = 0
countH4 = 0
countH5 = 0
countH6 = 0

countV1 = 0
countV2 = 0
countV3 = 0
countV4 = 0
countV5 = 0

MakeStartingGround = function()

	if countV1 < 55 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,1) + CVec.New(0, countV1), Owner = France })
		newactor = Actor.Create("nix01", true, { Location = CPos.New(55,1) + CVec.New(0, countV1), Owner = France })
		countV1 = countV1 + 1
	end
	if countH1 < 17 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(20,55) + CVec.New(countH1, 0), Owner = France })
	end
	if countH1 < 55 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(1,1) + CVec.New(countH1, 0), Owner = France })

		countH1 = countH1 + 1
	end
	if countV2 < 52 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(20,2) + CVec.New(0, countV2), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(26,1) + CVec.New(0, countV2), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(28,1) + CVec.New(0, countV2), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(34,1) + CVec.New(0, countV2), Owner = France })
		countV2 = countV2 + 3
	end
	if countH2 < 16 then
		newactor = Actor.Create("q1d13s", true, { Location = CPos.New(2,2) + CVec.New(countH2, 0), Owner = Leftowner })
		newactor = Actor.Create("q1d13s", true, { Location = CPos.New(37,2) + CVec.New(countH2, 0), Owner = Rightowner })
		newactor = Actor.Create("q1d13", true, { Location = CPos.New(2,2) + CVec.New(countH2, 0), Owner = Leftowner })
		newactor = Actor.Create("q1d13", true, { Location = CPos.New(37,2) + CVec.New(countH2, 0), Owner = Rightowner })
		countH2 = countH2 + 5
	end
	if countH3 < 5 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(23,2) + CVec.New(0, countH3), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(31,2) + CVec.New(0, countH3), Owner = France })
		countH3 = countH3 + 3
	end
	if countV3 < 40 then
		newactor = Actor.Create("nix03l", true, { Location = CPos.New(23,8) + CVec.New(0, countV3), Owner = France })
		newactor = Actor.Create("nix03r", true, { Location = CPos.New(31,8) + CVec.New(0, countV3), Owner = France })
		countV3 = countV3 + 4
	elseif countV3 < 48 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(23,8) + CVec.New(0, countV3), Owner = France })
		newactor = Actor.Create("nix03", true, { Location = CPos.New(31,8) + CVec.New(0, countV3), Owner = France })
		countV3 = countV3 + 4
	end
	if countH4 < 17 then
		newactor = Actor.Create("nix02", true, { Location = CPos.New(5,2) + CVec.New(countH4, 0), Owner = France })
		newactor = Actor.Create("nix02", true, { Location = CPos.New(5,4) + CVec.New(countH4, 0), Owner = France })
		newactor = Actor.Create("nix02", true, { Location = CPos.New(40,2) + CVec.New(countH4, 0), Owner = France })
		newactor = Actor.Create("nix02", true, { Location = CPos.New(40,4) + CVec.New(countH4, 0), Owner = France })
		countH4 = countH4 + 5
	end
	if countH5 < 53 then
		newactor = Actor.Create("nix01", true, { Location = CPos.New(2,11) + CVec.New(countH5, countV4), Owner = France })
		countH5 = countH5 + 1
		MakeStartingGround()
	elseif countV4 < 35 then
		countH5 = 0
		countV4 = countV4 + 4
		MakeStartingGround()
	end
	if countH6 < 18 then
		newactor = Actor.Create("nix03l", true, { Location = CPos.New(2,11) + CVec.New(countH6, countV5), Owner = France })
		newactor = Actor.Create("nix03r", true, { Location = CPos.New(37,11) + CVec.New(countH6, countV5), Owner = France })
		countH6 = countH6 + 3

	elseif countV5 < 40 then
		countH6 = 0
		countV5 = countV5 + 3

	end

end
MakeActors = function()


	newactor = Actor.Create("nix01mm", true, { Location = CPos.New(25,1), Owner = France })

	newactor = Actor.Create("nix01", true, { Location = CPos.New(2,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(4,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(7,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(9,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(12,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(14,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(17,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(19,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(37,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(39,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(42,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(44,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(47,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(49,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(52,5), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(54,5), Owner = France })

	newactor = Actor.Create("nix01", true, { Location = CPos.New(2,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(4,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(7,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(9,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(12,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(14,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(17,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(19,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(37,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(39,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(42,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(44,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(47,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(49,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(52,51), Owner = France })
	newactor = Actor.Create("nix01", true, { Location = CPos.New(54,51), Owner = France })

	newactor = Actor.Create("nix03", true, { Location = CPos.New(23,51), Owner = France })
	newactor = Actor.Create("nix03", true, { Location = CPos.New(31,51), Owner = France })

	LeftCam1 = Actor.Create("nix01cam", true, { Location = CPos.New(5,4), Owner = Leftowner })
	RightCam1 = Actor.Create("nix01cam", true, { Location = CPos.New(40,4), Owner = Rightowner })
	LeftCam2 = Actor.Create("nix01cam", true, { Location = CPos.New(10,30), Owner = Leftplayer })
	RightCam2 = Actor.Create("nix01cam", true, { Location = CPos.New(40,30), Owner = Rightplayer })
	LeftGap = Actor.Create("nix01s", true, { Location = CPos.New(10,11), Owner = Leftowner })
	RightGap = Actor.Create("nix01s", true, { Location = CPos.New(45,11), Owner = Rightowner })

	LeftPW = Actor.Create("nix01PW", true, { Location = CPos.New(10,27), Owner = Leftplayer })
	RightPW = Actor.Create("nix01PW", true, { Location = CPos.New(40,27), Owner = Rightplayer })
	Trigger.AfterDelay(50, function()
		LeftNameStart = Actor.Create("nix01pname", true, { Location = CPos.New(11,30), Owner = Leftowner })
		RightNameStart = Actor.Create("nix01pname", true, { Location = CPos.New(41,30), Owner = Rightowner })
		Trigger.AfterDelay(50, function()
			LeftIsChoosing = Actor.Create("nix01ictc", true, { Location = CPos.New(10,31), Owner = Leftplayer })
			RightIsChoosing = Actor.Create("nix01ictc", true, { Location = CPos.New(40,31), Owner = Rightplayer })
		end)
	end)
end

MoveseBox1 = { CPos.New(3, 4) }
MoveseBox2 = { CPos.New(8, 4) }
MoveseBox3 = { CPos.New(13, 4) }
MoveseBox4 = { CPos.New(18, 4) }

MoveseBox5 = { CPos.New(38, 4) }
MoveseBox6 = { CPos.New(43, 4) }
MoveseBox7 = { CPos.New(48, 4) }
MoveseBox8 = { CPos.New(53, 4) }

ChooseBox1 = { CPos.New(3, 3) }
ChooseBox2 = { CPos.New(8, 3) }
ChooseBox3 = { CPos.New(13, 3) }
ChooseBox4 = { CPos.New(18, 3) }

ChooseBox5 = { CPos.New(38, 3) }
ChooseBox6 = { CPos.New(43, 3) }
ChooseBox7 = { CPos.New(48, 3) }
ChooseBox8 = { CPos.New(53, 3) }

LeftCounter = 0
RightCounter = 0

SetTriggers = function()

-- Box1

	Trigger.OnEnteredFootprint(MoveseBox1, function(a, id) 
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(3, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(3,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(3, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox1, function(a, id) 

		a.Stop()

		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(3,3), Owner = Leftowner })
				a.Destroy()
				Box1lt = true
				Lltnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(3,3), Owner = Leftowner })
				a.Destroy()
				Box1met = true
				Lmedtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(3,3), Owner = Leftowner })
				a.Destroy()
				Box1ht = true
				Lheatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(3,3), Owner = Leftowner })
				a.Destroy()
				Box1mat = true
				Lmamtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(3,3), Owner = Leftowner })
				a.Destroy()
				Box1tt = true
				Ltslatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(3,3), Owner = Leftowner })
				a.Destroy()
				Box1ct = true
				Lchtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box1Chosen = true
			if LeftCounter == 4 then
				LeftChooserReady()
			end
		end)
	end)

--Box2

	Trigger.OnEnteredFootprint(MoveseBox2, function(a, id)
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(8, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(8,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(8, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox2, function(a, id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(8,3), Owner = Leftowner })
				Box2lt = true
				Lltnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(8,3), Owner = Leftowner })
				Box2met = true
				Lmedtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(8,3), Owner = Leftowner })
				Box2ht = true
				Lheatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(8,3), Owner = Leftowner })
				Box2mat = true
				Lmamtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(8,3), Owner = Leftowner })
				Box2tt = true
				Ltslatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(8,3), Owner = Leftowner })
				Box2ct = true
				Lchtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box2Chosen = true
			if LeftCounter == 4 then
				LeftChooserReady()
			end
		end)
	end)

--Box3

	Trigger.OnEnteredFootprint(MoveseBox3, function(a, id) 
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(13, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(13,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(13, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox3, function(a, id) 
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(13,3), Owner = Leftowner })
				Box3lt = true
				Lltnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(13,3), Owner = Leftowner })
				Box3met = true
				Lmedtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(13,3), Owner = Leftowner })
				Box3ht = true
				Lheatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(13,3), Owner = Leftowner })
				Box3mat = true
				Lmamtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(13,3), Owner = Leftowner })
				Box3tt = true
				Ltslatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(13,3), Owner = Leftowner })
				Box3ct = true
				Lchtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box3Chosen = true
			if LeftCounter == 4 then
				LeftChooserReady()
			end
		end)
	end)

--Box4

	Trigger.OnEnteredFootprint(MoveseBox4, function(a, id)
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(18, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(18,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(18, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox4, function(a, id) 
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(18,3), Owner = Leftowner })
				Box4lt = true
				Lltnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(18,3), Owner = Leftowner })
				Box4met = true
				Lmedtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(18,3), Owner = Leftowner })
				Box4ht = true
				Lheatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(18,3), Owner = Leftowner })
				Box4mat = true
				Lmamtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(18,3), Owner = Leftowner })
				Box4tt = true
				Ltslatnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(18,3), Owner = Leftowner })
				Box4ct = true
				Lchtnk = true
				LeftCounter = LeftCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box4Chosen = true
			if LeftCounter == 4 then
				LeftChooserReady()
			end
		end)
	end)

--Box5

	Trigger.OnEnteredFootprint(MoveseBox5, function(a, id) 
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(38, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(38,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(38, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox5, function(a, id) 
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(38,3), Owner = Rightowner })
				Box5lt = true
				Rltnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(38,3), Owner = Rightowner })
				Box5met = true
				Rmedtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(38,3), Owner = Rightowner })
				Box5ht = true
				Rheatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(38,3), Owner = Rightowner })
				Box5mat = true
				Rmamtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(38,3), Owner = Rightowner })
				Box5tt = true
				Rtslatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(38,3), Owner = Rightowner })
				Box5ct = true
				Rchtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box5Chosen = true
			if RightCounter == 4 then
				RightChooserReady()
			end
		end)
	end)

--Box6

	Trigger.OnEnteredFootprint(MoveseBox6, function(a, id) 
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(43, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(43,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(43, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox6, function(a, id) 
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(43,3), Owner = Rightowner })
				Box6lt = true
				Rltnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(43,3), Owner = Rightowner })
				Box6met = true
				Rmedtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(43,3), Owner = Rightowner })
				Box6ht = true
				Rheatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(43,3), Owner = Rightowner })
				Box6mat = true
				Rmamtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(43,3), Owner = Rightowner })
				Box6tt = true
				Rtslatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(43,3), Owner = Rightowner })
				Box6ct = true
				Rchtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box6Chosen = true
			if RightCounter == 4 then
				RightChooserReady()
			end
		end)
	end)

--Box7

	Trigger.OnEnteredFootprint(MoveseBox7, function(a, id) 
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(48, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(48,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(48, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox7, function(a, id) 
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(48,3), Owner = Rightowner })
				Box7lt = true
				Rltnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(48,3), Owner = Rightowner })
				Box7met = true
				Rmedtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(48,3), Owner = Rightowner })
				Box7ht = true
				Rheatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(48,3), Owner = Rightowner })
				Box7mat = true
				Rmamtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(48,3), Owner = Rightowner })
				Box7tt = true
				Rtslatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(48,3), Owner = Rightowner })
				Box7ct = true
				Rchtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box7Chosen = true
			if RightCounter == 4 then
				RightChooserReady()
			end
		end)
	end)

--Box8

	Trigger.OnEnteredFootprint(MoveseBox8, function(a, id) 
--		a.Owner = Neutral
		a.Stop()
		a.ScriptedMove(CPos.New(53, 3))
		newactor = Actor.Create("nix01", true, { Location = CPos.New(53,5), Owner = Neutral })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(53, 3))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox8, function(a, id) 
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				a.Destroy()
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(53,3), Owner = Rightowner })
				Box8lt = true
				Rltnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "2tnkn" then
				a.Destroy()
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(53,3), Owner = Rightowner })
				Box8met = true
				Rmedtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "3tnkn" then
				a.Destroy()
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(53,3), Owner = Rightowner })
				Box8ht = true
				Rheatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "4tnkn" then
				a.Destroy()
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(53,3), Owner = Rightowner })
				Box8mat = true
				Rmamtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ttnkn" then
				a.Destroy()
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(53,3), Owner = Rightowner })
				Box8tt = true
				Rtslatnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			if a.Type == "ctnkn" then
				a.Destroy()
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(53,3), Owner = Rightowner })
				Box8ct = true
				Rchtnk = true
				RightCounter = RightCounter + 1
				Trigger.RemoveFootprintTrigger(id)
			end
			Box8Chosen = true
			if RightCounter == 4 then
				RightChooserReady()
			end
		end)
	end)
end


countmidright = 0

LeftChooserReady = function()
	if LChooseUnit1.IsInWorld then
		LChooseUnit1.Stop()
		LChooseUnit1.Destroy()
	end
	if LChooseUnit2.IsInWorld then
		LChooseUnit2.Stop()
		LChooseUnit2.Destroy()
	end
	if LChooseUnit3.IsInWorld then
		LChooseUnit3.Stop()
		LChooseUnit3.Destroy()
	end
	if LChooseUnit4.IsInWorld then
		LChooseUnit4.Stop()
		LChooseUnit4.Destroy()
	end
	if LChooseUnit5.IsInWorld then
		LChooseUnit5.Stop()
		LChooseUnit5.Destroy()
	end
	if LChooseUnit6.IsInWorld then
		LChooseUnit6.Stop()
		LChooseUnit6.Destroy()
	end
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		Barb = France.GetActorsByType("nix03l")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		LeftSetMap()

		if LChooseUnit1.IsInWorld then
			LChooseUnit1.Destroy()
		end
		if LChooseUnit2.IsInWorld then
			LChooseUnit2.Destroy()
		end
		if LChooseUnit3.IsInWorld then
			LChooseUnit3.Destroy()
		end
		if LChooseUnit4.IsInWorld then
			LChooseUnit4.Destroy()
		end
		if LChooseUnit5.IsInWorld then
			LChooseUnit5.Destroy()
		end
		if LChooseUnit6.IsInWorld then
			LChooseUnit6.Destroy()
		end
		Trigger.AfterDelay(DateTime.Seconds(1), function()
			LeftGap.Destroy()
			LeftChooserisReady = true
			if not PlayerStarts and RightChooserisReady then
				PlayerStarts = true
				turnOff()
				Trigger.AfterDelay(DateTime.Seconds(1), function()
					GameForPlayerStarts()
				end)
			end
		end)
	end)
end

countmidleft = 0
countleft1 = 0
countleftV1 = 0
countleftH1 = 0
countleftV2 = 0
countleftH2 = 0
countleftH3 = 0

LeftSetMap = function()
	if countmidleft < 39 then
		newactor = Actor.Create("q1d12", true, { Location = CPos.New(23,8) + CVec.New(0, countmidleft), Owner = Neutral })
		countmidleft = countmidleft + 4

	end
	if countleft1 < 20 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(2,5) + CVec.New(countleft1, 0), Owner = Neutral })
		countleft1 = countleft1 + 3
	end
	if countleftV1 < 45 then
		newactor = Actor.Create("nix02", true, { Location = CPos.New(5,6) + CVec.New(countleftH1, countleftV1), Owner = Neutral })
		countleftV1 = countleftV1 + 2
		LeftSetMap()
	elseif countleftH1 < 13 then
		countleftV1 = 0
		countleftH1 = countleftH1 + 5
		LeftSetMap()
	end
	if countleftH2 < 20 then
		newactor = Actor.Create("q1d07", true, { Location = CPos.New(2,8) + CVec.New(countleftH2, countleftV2), Owner = Neutral })

		countleftH2 = countleftH2 + 5
	elseif countleftV2 < 35 then
		countleftH2 = 0
		countleftV2 = countleftV2 + 4
	end
	if countleftH3 < 20 then
		newactor = Actor.Create("q1d13n", true, { Location = CPos.New(2,48) + CVec.New(countleftH3, 0), Owner = Neutral })
		countleftH3 = countleftH3 + 5
	end
end

RightChooserReady = function()
	if RChooseUnit1.IsInWorld then
		RChooseUnit1.Stop()
		RChooseUnit1.Destroy()
	end
	if RChooseUnit2.IsInWorld then
		RChooseUnit2.Scatter()
		RChooseUnit2.Destroy()
	end
	if RChooseUnit3.IsInWorld then
		RChooseUnit3.Stop()
		RChooseUnit3.Destroy()
	end
	if RChooseUnit4.IsInWorld then
		RChooseUnit4.Stop()
		RChooseUnit4.Destroy()
	end
	if RChooseUnit5.IsInWorld then
		RChooseUnit5.Stop()
		RChooseUnit5.Destroy()
	end
	if RChooseUnit6.IsInWorld then
		RChooseUnit6.Stop()
		RChooseUnit6.Destroy()
	end
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		Barb = France.GetActorsByType("nix03r")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		RightSetMap()

		if RChooseUnit1.IsInWorld then
			RChooseUnit1.Destroy()
		end
		if RChooseUnit2.IsInWorld then
			RChooseUnit2.Destroy()
		end
		if RChooseUnit3.IsInWorld then
			RChooseUnit3.Destroy()
		end
		if RChooseUnit4.IsInWorld then
			RChooseUnit4.Destroy()
		end
		if RChooseUnit5.IsInWorld then
			RChooseUnit5.Destroy()
		end
		if RChooseUnit6.IsInWorld then
			RChooseUnit6.Destroy()
		end
		Trigger.AfterDelay(DateTime.Seconds(1), function()
			RightGap.Destroy()
			RightChooserisReady = true
			if not PlayerStarts and LeftChooserisReady then
				PlayerStarts = true
				turnOff()
				Trigger.AfterDelay(DateTime.Seconds(1), function()
					GameForPlayerStarts()
				end)
			end
		end)
	end)
end

countmidright = 0
countright1 = 0
countrightV1 = 0
countrightH1 = 0
countrightV2 = 0
countrightH2 = 0
countrightH3 = 0

-- §§

RightSetMap = function()
	if countmidright < 39 then
		newactor = Actor.Create("q1d12", true, { Location = CPos.New(31,8) + CVec.New(0, countmidright), Owner = Neutral })
		countmidright = countmidright + 4
	end
	if countright1 < 20 then
		newactor = Actor.Create("nix03", true, { Location = CPos.New(37,5) + CVec.New(countright1, 0), Owner = Neutral })
		countright1 = countright1 + 3
	end
	if countrightV1 < 45 then
		newactor = Actor.Create("nix02", true, { Location = CPos.New(40,6) + CVec.New(countrightH1, countrightV1), Owner = Neutral })
		countrightV1 = countrightV1 + 2
		RightSetMap()
	elseif countrightH1 < 13 then
		countrightV1 = 0
		countrightH1 = countrightH1 + 5
		RightSetMap()
	end

	if countrightH2 < 20 then
		newactor = Actor.Create("q1d07", true, { Location = CPos.New(37,8) + CVec.New(countrightH2, countrightV2), Owner = Neutral })

		countrightH2 = countrightH2 + 5
	elseif countrightV2 < 35 then
		countrightH2 = 0
		countrightV2 = countrightV2 + 4
	end
	if countrightH3 < 20 then
		newactor = Actor.Create("q1d13n", true, { Location = CPos.New(37,48) + CVec.New(countrightH3, 0), Owner = Neutral })
		countrightH3 = countrightH3 + 5
	end
end

ChooserUnits = function()
	LChooseUnit1 = Actor.Create("1tnkn", true, { Location = CPos.New(3,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Leftowner })
	LChooseUnit1.Scatter()
	LChooseUnit2 = Actor.Create("2tnkn", true, { Location = CPos.New(3,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Leftowner })
	LChooseUnit2.Scatter()
	LChooseUnit3 = Actor.Create("3tnkn", true, { Location = CPos.New(3,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Leftowner })
	LChooseUnit3.Scatter()
	LChooseUnit4 = Actor.Create("4tnkn", true, { Location = CPos.New(3,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Leftowner })
	LChooseUnit4.Scatter()
	LChooseUnit5 = Actor.Create("ttnkn", true, { Location = CPos.New(3,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Leftowner })
	LChooseUnit5.Scatter()
	LChooseUnit6 = Actor.Create("ctnkn", true, { Location = CPos.New(3,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Leftowner })
	LChooseUnit6.Scatter()


	RChooseUnit1 = Actor.Create("1tnkn", true, { Location = CPos.New(39,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Rightowner })
	RChooseUnit1.Scatter()
	RChooseUnit2 = Actor.Create("2tnkn", true, { Location = CPos.New(39,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Rightowner })
	RChooseUnit2.Scatter()
	RChooseUnit3 = Actor.Create("3tnkn", true, { Location = CPos.New(39,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Rightowner })
	RChooseUnit3.Scatter()
	RChooseUnit4 = Actor.Create("4tnkn", true, { Location = CPos.New(39,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Rightowner })
	RChooseUnit4.Scatter()
	RChooseUnit5 = Actor.Create("ttnkn", true, { Location = CPos.New(39,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Rightowner })
	RChooseUnit5.Scatter()
	RChooseUnit6 = Actor.Create("ctnkn", true, { Location = CPos.New(39,8) + CVec.New(Utils.RandomInteger(0, 15), Utils.RandomInteger(0, 1)), Owner = Rightowner })
	RChooseUnit6.Scatter()
	Trigger.AfterDelay(1, function()
		Media.PlayMusic("choose")
		Trigger.AfterDelay(75, function()
			ChooseMessage()
		end)
	end)
end


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

ChooserTimeOverRNDUnitset = function()
	RandomUnitCounter = Utils.Random(UnitCounter)
	if LeftCounter < 4 then
		if not Box1Chosen then
			if LChooseUnit1.IsInWorld and not Lltnk and RandomUnitCounter == 1 then
				LChooseUnit1.Stop()
				LChooseUnit1.Teleport(CPos.New(3, 3))
			elseif LChooseUnit2.IsInWorld and not Lmedtnk and RandomUnitCounter == 2 then
				LChooseUnit2.Stop()
				LChooseUnit2.Teleport(CPos.New(3, 3))
			elseif LChooseUnit3.IsInWorld and not Lheatnk and RandomUnitCounter == 3 then
				LChooseUnit3.Stop()
				LChooseUnit3.Teleport(CPos.New(3, 3))
			elseif LChooseUnit4.IsInWorld and not Lmamtnk and RandomUnitCounter == 4 then
				LChooseUnit4.Stop()
				LChooseUnit4.Teleport(CPos.New(3, 3))
			elseif LChooseUnit5.IsInWorld and not Ltslatnk and RandomUnitCounter == 5 then
				LChooseUnit5.Stop()
				LChooseUnit5.Teleport(CPos.New(3, 3))
			elseif LChooseUnit6.IsInWorld and not Lchtnk and RandomUnitCounter == 6 then
				LChooseUnit6.Stop()
				LChooseUnit6.Teleport(CPos.New(3, 3))
			end
		end
	end
	if LeftCounter < 4 then
		if not Box2Chosen then
			if LChooseUnit1.IsInWorld and not Lltnk and RandomUnitCounter == 1 then
				LChooseUnit1.Stop()
				LChooseUnit1.Teleport(CPos.New(8, 3))
			elseif LChooseUnit2.IsInWorld and not Lmedtnk and RandomUnitCounter == 2 then
				LChooseUnit2.Stop()
				LChooseUnit2.Teleport(CPos.New(8, 3))
			elseif LChooseUnit3.IsInWorld and not Lheatnk and RandomUnitCounter == 3 then
				LChooseUnit3.Stop()
				LChooseUnit3.Teleport(CPos.New(8, 3))
			elseif LChooseUnit4.IsInWorld and not Lmamtnk and RandomUnitCounter == 4 then
				LChooseUnit4.Stop()
				LChooseUnit4.Teleport(CPos.New(8, 3))
			elseif LChooseUnit5.IsInWorld and not Ltslatnk and RandomUnitCounter == 5 then
				LChooseUnit5.Stop()
				LChooseUnit5.Teleport(CPos.New(8, 3))
			elseif LChooseUnit6.IsInWorld and not Lchtnk and RandomUnitCounter == 6 then
				LChooseUnit6.Stop()
				LChooseUnit6.Teleport(CPos.New(8, 3))
			end
		end
	end
	if LeftCounter < 4 then
		if not Box3Chosen then
			if LChooseUnit1.IsInWorld and not Lltnk and RandomUnitCounter == 1 then
				LChooseUnit1.Stop()
				LChooseUnit1.Teleport(CPos.New(13, 3))
			elseif LChooseUnit2.IsInWorld and not Lmedtnk and RandomUnitCounter == 2 then
				LChooseUnit2.Stop()
				LChooseUnit2.Teleport(CPos.New(13, 3))
			elseif LChooseUnit3.IsInWorld and not Lheatnk and RandomUnitCounter == 3 then
				LChooseUnit3.Stop()
				LChooseUnit3.Teleport(CPos.New(13, 3))
			elseif LChooseUnit4.IsInWorld and not Lmamtnk and RandomUnitCounter == 4 then
				LChooseUnit4.Stop()
				LChooseUnit4.Teleport(CPos.New(13, 3))
			elseif LChooseUnit5.IsInWorld and not Ltslatnk and RandomUnitCounter == 5 then
				LChooseUnit5.Stop()
				LChooseUnit5.Teleport(CPos.New(13, 3))
			elseif LChooseUnit6.IsInWorld and not Lchtnk and RandomUnitCounter == 6 then
				LChooseUnit6.Stop()
				LChooseUnit6.Teleport(CPos.New(13, 3))
			end
		end
	end
	if LeftCounter < 4 then
		if not Box4Chosen then
			if LChooseUnit1.IsInWorld and not Lltnk and RandomUnitCounter == 1 then
				LChooseUnit1.Stop()
				LChooseUnit1.Teleport(CPos.New(18, 3))
			elseif LChooseUnit2.IsInWorld and not Lmedtnk and RandomUnitCounter == 2 then
				LChooseUnit2.Stop()
				LChooseUnit2.Teleport(CPos.New(18, 3))
			elseif LChooseUnit3.IsInWorld and not Lheatnk and RandomUnitCounter == 3 then
				LChooseUnit3.Stop()
				LChooseUnit3.Teleport(CPos.New(18, 3))
			elseif LChooseUnit4.IsInWorld and not Lmamtnk and RandomUnitCounter == 4 then
				LChooseUnit4.Stop()
				LChooseUnit4.Teleport(CPos.New(18, 3))
			elseif LChooseUnit5.IsInWorld and not Ltslatnk and RandomUnitCounter == 5 then
				LChooseUnit5.Stop()
				LChooseUnit5.Teleport(CPos.New(18, 3))
			elseif LChooseUnit6.IsInWorld and not Lchtnk and RandomUnitCounter == 6 then
				LChooseUnit6.Stop()
				LChooseUnit6.Teleport(CPos.New(18, 3))
			end
	
		end
	end

-- Right side

	RandomUnitCounter2 = Utils.Random(UnitCounter)
	if RightCounter < 4 then
		if not Box5Chosen then
			if RChooseUnit1.IsInWorld and not Rltnk and RandomUnitCounter2 == 1 then
				RChooseUnit1.Stop()
				RChooseUnit1.Teleport(CPos.New(38, 3))
			elseif RChooseUnit2.IsInWorld and not Rmedtnk and RandomUnitCounter2 == 2 then
				RChooseUnit2.Stop()
				RChooseUnit2.Teleport(CPos.New(38, 3))
			elseif RChooseUnit3.IsInWorld and not Rheatnk and RandomUnitCounter2 == 3 then
				RChooseUnit3.Stop()
				RChooseUnit3.Teleport(CPos.New(38, 3))
			elseif RChooseUnit4.IsInWorld and not Rmamtnk and RandomUnitCounter2 == 4 then
				RChooseUnit4.Stop()
				RChooseUnit4.Teleport(CPos.New(38, 3))
			elseif RChooseUnit5.IsInWorld and not Rtslatnk and RandomUnitCounter2 == 5 then
				RChooseUnit5.Stop()
				RChooseUnit5.Teleport(CPos.New(38, 3))
			elseif RChooseUnit6.IsInWorld and not Rchtnk and RandomUnitCounter2 == 6 then
				RChooseUnit6.Stop()
				RChooseUnit6.Teleport(CPos.New(38, 3))
			end
		end
	end
	if RightCounter < 4 then
		if not Box6Chosen then
			if RChooseUnit1.IsInWorld and not Rltnk and RandomUnitCounter2 == 1 then
				RChooseUnit1.Stop()
				RChooseUnit1.Teleport(CPos.New(43, 3))
			elseif RChooseUnit2.IsInWorld and not Rmedtnk and RandomUnitCounter2 == 2 then
				RChooseUnit2.Stop()
				RChooseUnit2.Teleport(CPos.New(43, 3))
			elseif RChooseUnit3.IsInWorld and not Rheatnk and RandomUnitCounter2 == 3 then
				RChooseUnit3.Stop()
				RChooseUnit3.Teleport(CPos.New(43, 3))
			elseif RChooseUnit4.IsInWorld and not Rmamtnk and RandomUnitCounter2 == 4 then
				RChooseUnit4.Stop()
				RChooseUnit4.Teleport(CPos.New(43, 3))
			elseif RChooseUnit5.IsInWorld and not Rtslatnk and RandomUnitCounter2 == 5 then
				RChooseUnit5.Stop()
				RChooseUnit5.Teleport(CPos.New(43, 3))
			elseif RChooseUnit6.IsInWorld and not Rchtnk and RandomUnitCounter2 == 6 then
				RChooseUnit6.Stop()
				RChooseUnit6.Teleport(CPos.New(43, 3))
			end
		end
	end
	if RightCounter < 4 then
		if not Box7Chosen then
			if RChooseUnit1.IsInWorld and not Rltnk and RandomUnitCounter2 == 1 then
				RChooseUnit1.Stop()
				RChooseUnit1.Teleport(CPos.New(48, 3))
			elseif RChooseUnit2.IsInWorld and not Rmedtnk and RandomUnitCounter2 == 2 then
				RChooseUnit2.Stop()
				RChooseUnit2.Teleport(CPos.New(48, 3))
			elseif RChooseUnit3.IsInWorld and not Rheatnk and RandomUnitCounter2 == 3 then
				RChooseUnit3.Stop()
				RChooseUnit3.Teleport(CPos.New(48, 3))
			elseif RChooseUnit4.IsInWorld and not Rmamtnk and RandomUnitCounter2 == 4 then
				RChooseUnit4.Stop()
				RChooseUnit4.Teleport(CPos.New(48, 3))
			elseif RChooseUnit5.IsInWorld and not Rtslatnk and RandomUnitCounter2 == 5 then
				RChooseUnit5.Stop()
				RChooseUnit5.Teleport(CPos.New(48, 3))
			elseif RChooseUnit6.IsInWorld and not Rchtnk and RandomUnitCounter2 == 6 then
				RChooseUnit6.Stop()
				RChooseUnit6.Teleport(CPos.New(48, 3))
			end
		end
	end
	if RightCounter < 4 then
		if not Box8Chosen then
			if RChooseUnit1.IsInWorld and not Rltnk and RandomUnitCounter2 == 1 then
				RChooseUnit1.Stop()
				RChooseUnit1.Teleport(CPos.New(53, 3))
			elseif RChooseUnit2.IsInWorld and not Rmedtnk and RandomUnitCounter2 == 2 then
				RChooseUnit2.Stop()
				RChooseUnit2.Teleport(CPos.New(53, 3))
			elseif RChooseUnit3.IsInWorld and not Rheatnk and RandomUnitCounter2 == 3 then
				RChooseUnit3.Stop()
				RChooseUnit3.Teleport(CPos.New(53, 3))
			elseif RChooseUnit4.IsInWorld and not Rmamtnk and RandomUnitCounter2 == 4 then
				RChooseUnit4.Stop()
				RChooseUnit4.Teleport(CPos.New(53, 3))
			elseif RChooseUnit5.IsInWorld and not Rtslatnk and RandomUnitCounter2 == 5 then
				RChooseUnit5.Stop()
				RChooseUnit5.Teleport(CPos.New(53, 3))
			elseif RChooseUnit6.IsInWorld and not Rchtnk and RandomUnitCounter2 == 6 then
				RChooseUnit6.Stop()
				RChooseUnit6.Teleport(CPos.New(53, 3))
			end
	
		end
	end
	if RightCounter < 4 or LeftCounter < 4 then
		Trigger.AfterDelay(10, function()
			ChooserTimeOverRNDUnitset()
		end)
	elseif not PlayerStarts then
		turnOff()
		PlayerStarts = true
		Trigger.AfterDelay(DateTime.Seconds(1), function()
			GameForPlayerStarts()
		end)
	end
end

GameForPlayerStarts = function()
	if Round2 then
		Media.PlayMusic("main2")
	else
		Media.PlayMusic("main1")
	end
	LeftPW.Destroy()
	RightPW.Destroy()

	LeftNameStart.Destroy()
	RightNameStart.Destroy()

	LeftIsChoosing.Destroy()
	RightIsChoosing.Destroy()

	LeftTry = 0
	RightTry = 0
	LVerticalShift = 0
	RVerticalShift = 0
	LRedPin = 0
	RRedPin = 0
	LWhitePin = 0
	RWhitePin = 0
	LeftCam1.Destroy()
	LeftCam2.Destroy()
	RightCam1.Destroy()
	RightCam2.Destroy()
	LeftName = Actor.Create("nix01pname", true, { Location = CPos.New(23,50), Owner = Leftplayer })
	RightName = Actor.Create("nix01pname", true, { Location = CPos.New(33,50), Owner = Rightplayer })
	VSsign = Actor.Create("nix01vs", true, { Location = CPos.New(28,48), Owner = France })
	LeftBar = Actor.Create("nix01bar", true, { Location = CPos.New(21,44), Owner = Leftplayer })
	RightBar = Actor.Create("nix01bar", true, { Location = CPos.New(35,44), Owner = Rightplayer })

	LeftBigCam1 = Actor.Create("bigcamera", true, { Location = CPos.New(28,40), Owner = Leftowner })
	RightBigCam1 = Actor.Create("bigcamera", true, { Location = CPos.New(28,40), Owner = Rightowner })

	LeftCam1 = Actor.Create("nix01cam", true, { Location = CPos.New(10,50), Owner = Leftowner })
	RightCam1 = Actor.Create("nix01cam", true, { Location = CPos.New(45,50), Owner = Rightowner })
	LeftCam2 = Actor.Create("nix01cam", true, { Location = CPos.New(10,50), Owner = Leftplayer })
	RightCam2 = Actor.Create("nix01cam", true, { Location = CPos.New(45,50), Owner = Rightplayer })
	number1 = Actor.Create("no1", true, { Location = CPos.New(28,44), Owner = Neutral })
	number2 = Actor.Create("no2", true, { Location = CPos.New(28,40), Owner = Neutral })
	number3 = Actor.Create("no3", true, { Location = CPos.New(28,36), Owner = Neutral })
	number4 = Actor.Create("no4", true, { Location = CPos.New(28,32), Owner = Neutral })
	number5 = Actor.Create("no5", true, { Location = CPos.New(28,28), Owner = Neutral })
	number6 = Actor.Create("no6", true, { Location = CPos.New(28,24), Owner = Neutral })
	number7 = Actor.Create("no7", true, { Location = CPos.New(28,20), Owner = Neutral })
	number8 = Actor.Create("no8", true, { Location = CPos.New(28,16), Owner = Neutral })
	number9 = Actor.Create("no9", true, { Location = CPos.New(28,12), Owner = Neutral })
	number0 = Actor.Create("no10", true, { Location = CPos.New(28,8), Owner = Neutral })

	ChoosingTime = DateTime.Seconds(0)

	Barb = Leftowner.GetActorsByType("1tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Leftowner.GetActorsByType("2tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Leftowner.GetActorsByType("3tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Leftowner.GetActorsByType("4tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Leftowner.GetActorsByType("ttnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Leftowner.GetActorsByType("ctnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Rightowner.GetActorsByType("1tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Rightowner.GetActorsByType("2tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Rightowner.GetActorsByType("3tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Rightowner.GetActorsByType("4tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Rightowner.GetActorsByType("ttnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Rightowner.GetActorsByType("ctnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end

	Barb = Neutral.GetActorsByType("1tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Neutral.GetActorsByType("2tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Neutral.GetActorsByType("3tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Neutral.GetActorsByType("4tnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Neutral.GetActorsByType("ttnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = Neutral.GetActorsByType("ctnkn")
	for p,fences in pairs(Barb) do
		if fences.IsInWorld then
			fences.Stop()
			fences.Destroy()
		end
	end
	Barb = France.GetActorsByType("nix01l")
	for p,fences in pairs(Barb) do
		fences.Destroy()
	end
	Barb = France.GetActorsByType("nix01r")
	for p,fences in pairs(Barb) do
		fences.Destroy()
	end
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		LPlayerUnitsIncome()
		RPlayerUnitsIncome()
		PlayerMessages()
		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
		SetPlayerTimer()
		Trigger.AfterDelay(DateTime.Seconds(1), function()
			LeftCounter = 0
			RightCounter = 0
		end)
	end)
end

LPlayerUnitsIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		LPlayerUnit1 = Actor.Create("1tnkn", true, { Location = CPos.New(2,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Leftplayer })
		LPlayerUnit2 = Actor.Create("2tnkn", true, { Location = CPos.New(2,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Leftplayer })
		LPlayerUnit3 = Actor.Create("3tnkn", true, { Location = CPos.New(2,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Leftplayer })
		LPlayerUnit4 = Actor.Create("4tnkn", true, { Location = CPos.New(2,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Leftplayer })
		LPlayerUnit5 = Actor.Create("ttnkn", true, { Location = CPos.New(2,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Leftplayer })
		LPlayerUnit6 = Actor.Create("ctnkn", true, { Location = CPos.New(2,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Leftplayer })
		Trigger.AfterDelay(5, function()
			SetLeftPlayerTriggers()
			LPlayerUnit1.ScriptedMove(CPos.New(3, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			LPlayerUnit2.ScriptedMove(CPos.New(3, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			LPlayerUnit3.ScriptedMove(CPos.New(3, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			LPlayerUnit4.ScriptedMove(CPos.New(3, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			LPlayerUnit5.ScriptedMove(CPos.New(3, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			LPlayerUnit6.ScriptedMove(CPos.New(3, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
		end)
	end)
end


RPlayerUnitsIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		RPlayerUnit1 = Actor.Create("1tnkn", true, { Location = CPos.New(37,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Rightplayer })
		RPlayerUnit2 = Actor.Create("2tnkn", true, { Location = CPos.New(37,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Rightplayer })
		RPlayerUnit3 = Actor.Create("3tnkn", true, { Location = CPos.New(37,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Rightplayer })
		RPlayerUnit4 = Actor.Create("4tnkn", true, { Location = CPos.New(37,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Rightplayer })
		RPlayerUnit5 = Actor.Create("ttnkn", true, { Location = CPos.New(37,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Rightplayer })
		RPlayerUnit6 = Actor.Create("ctnkn", true, { Location = CPos.New(37,55) + CVec.New(Utils.RandomInteger(0, 18), 0), Owner = Rightplayer })
		Trigger.AfterDelay(5, function()
			SetRightPlayerTriggers()
			RPlayerUnit1.ScriptedMove(CPos.New(38, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			RPlayerUnit2.ScriptedMove(CPos.New(38, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			RPlayerUnit3.ScriptedMove(CPos.New(38, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			RPlayerUnit4.ScriptedMove(CPos.New(38, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			RPlayerUnit5.ScriptedMove(CPos.New(38, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
			RPlayerUnit6.ScriptedMove(CPos.New(38, 53) + CVec.New(Utils.RandomInteger(0, 16), Utils.RandomInteger(0, 2)))
		end)
	end)
end


MoveseBox11 = { CPos.New(3, 50) }
MoveseBox12 = { CPos.New(8, 50) }
MoveseBox13 = { CPos.New(13, 50) }
MoveseBox14 = { CPos.New(18, 50) }

MoveseBox15 = { CPos.New(38, 50) }

MoveseBox16 = { CPos.New(43, 50) }
MoveseBox17 = { CPos.New(48, 50) }
MoveseBox18 = { CPos.New(53, 50) }

ChooseBox11 = { CPos.New(3, 49) }
ChooseBox12 = { CPos.New(8, 49) }
ChooseBox13 = { CPos.New(13, 49) }
ChooseBox14 = { CPos.New(18, 49) }

ChooseBox15 = { CPos.New(38, 49) }
ChooseBox16 = { CPos.New(43, 49) }
ChooseBox17 = { CPos.New(48, 49) }
ChooseBox18 = { CPos.New(53, 49) }

-- &&

SetLeftPlayerTriggers = function()

-- Box11

	Trigger.OnEnteredFootprint(MoveseBox11, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(3, 49))
		LeftBlock1 = Actor.Create("nix01l", true, { Location = CPos.New(3,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(3, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox11, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(3,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPltnk = true
				if Box1lt then
					LRedPin = LRedPin + 1
				elseif Lltnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(3,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmedtnk = true
				if Box1met then
					LRedPin = LRedPin + 1
				elseif Lmedtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(3,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPheatnk = true
				if Box1ht then
					LRedPin = LRedPin + 1
				elseif Lheatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(3,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmamtnk = true
				if Box1mat then
					LRedPin = LRedPin + 1
				elseif Lmamtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(3,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPtslatnk = true
				if Box1tt then
					LRedPin = LRedPin + 1
				elseif Ltslatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(3,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPchtnk = true
				if Box1ct then
					LRedPin = LRedPin + 1
				elseif Lchtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			LeftCounter = LeftCounter + 1
			Box11Chosen = true
			if LeftCounter == 4 then
				LeftPlayerReady()
			end
		end)
	end)

--Box12

	Trigger.OnEnteredFootprint(MoveseBox12, function(a, id)
		a.Stop()
		a.ScriptedMove(CPos.New(8, 49))
		LeftBlock2 = Actor.Create("nix01l", true, { Location = CPos.New(8,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(8, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox12, function(a, id)
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(8,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPltnk = true
				if Box2lt then
					LRedPin = LRedPin + 1
				elseif Lltnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(8,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmedtnk = true
				if Box2met then
					LRedPin = LRedPin + 1
				elseif Lmedtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(8,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPheatnk = true
				if Box2ht then
					LRedPin = LRedPin + 1
				elseif Lheatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(8,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmamtnk = true
				if Box2mat then
					LRedPin = LRedPin + 1
				elseif Lmamtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(8,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPtslatnk = true
				if Box2tt then
					LRedPin = LRedPin + 1
				elseif Ltslatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(8,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPchtnk = true
				if Box2ct then
					LRedPin = LRedPin + 1
				elseif Lchtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			LeftCounter = LeftCounter + 1
			Box12Chosen = true
			if LeftCounter == 4 then
				LeftPlayerReady()
			end
		end)
	end)

--Box13

	Trigger.OnEnteredFootprint(MoveseBox13, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(13, 49))
		LeftBlock3 = Actor.Create("nix01l", true, { Location = CPos.New(13,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(13, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox13, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(13,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPltnk = true
				if Box3lt then
					LRedPin = LRedPin + 1
				elseif Lltnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(13,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmedtnk = true
				if Box3met then
					LRedPin = LRedPin + 1
				elseif Lmedtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(13,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPheatnk = true
				if Box3ht then
					LRedPin = LRedPin + 1
				elseif Lheatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(13,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmamtnk = true
				if Box3mat then
					LRedPin = LRedPin + 1
				elseif Lmamtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(13,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPtslatnk = true
				if Box3tt then
					LRedPin = LRedPin + 1
				elseif Ltslatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(13,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPchtnk = true
				if Box3ct then
					LRedPin = LRedPin + 1
				elseif Lchtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			LeftCounter = LeftCounter + 1
			Box13Chosen = true
			if LeftCounter == 4 then
				LeftPlayerReady()
			end
		end)
	end)

--Box14

	Trigger.OnEnteredFootprint(MoveseBox14, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(18, 49))
		LeftBlock4 = Actor.Create("nix01l", true, { Location = CPos.New(18,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(18, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox14, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(18,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPltnk = true
				if Box4lt then
					LRedPin = LRedPin + 1
				elseif Lltnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(18,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmedtnk = true
				if Box4met then
					LRedPin = LRedPin + 1
				elseif Lmedtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(18,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPheatnk = true
				if Box4ht then
					LRedPin = LRedPin + 1
				elseif Lheatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(18,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPmamtnk = true
				if Box4mat then
					LRedPin = LRedPin + 1
				elseif Lmamtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(18,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPtslatnk = true
				if Box4tt then
					LRedPin = LRedPin + 1
				elseif Ltslatnk then
					LWhitePin = LWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(18,45) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
				LPchtnk = true
				if Box4ct then
					LRedPin = LRedPin + 1
				elseif Lchtnk then
					LWhitePin = LWhitePin + 1
				end
			end
			LeftCounter = LeftCounter + 1
			Box14Chosen = true
			if LeftCounter == 4 then
				LeftPlayerReady()
			end
		end)
	end)
end


-- $$

Multi0TimeNeeded = 0
Multi1TimeNeeded = 0
Multi2TimeNeeded = 0
Multi3TimeNeeded = 0


LeftPlayerReady = function()
	LeftPlayerRoundTime = RoundTime - LeftPlayerTime
	if Round2 then
		Multi0TimeNeeded = Multi0TimeNeeded + LeftPlayerRoundTime
	else
		Multi3TimeNeeded = Multi3TimeNeeded + LeftPlayerRoundTime
	end
	if LRedPin == 4 then
		LeftSign = Actor.Create("nix01win", true, { Location = CPos.New(23,51), Owner = Leftplayer })
		LeftPlayerWon = true
		Barb = Leftowner.GetActorsByType("q1d13s")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		if RightPlayerWon or RightPlayerLoose then
			if not Round2 then
				EndRound()
			else
				GameOver()
			end
		end
	end
	LeftTry = LeftTry + 1
	if LeftTry == 10 and not LeftPlayerWon then
		LeftSign = Actor.Create("nix01loose", true, { Location = CPos.New(23,51), Owner = Leftplayer })
		LeftPlayerLoose = true
		Barb = Leftowner.GetActorsByType("q1d13s")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		if RightPlayerWon or RightPlayerLoose then
			if not Round2 then
				EndRound()
			else
				GameOver()
			end
		end
	end
	if not LeftPlayerWon then
		if not LeftPlayerLoose then
			LeftPlayerTime = RoundTime
			LeftTimerExpired = false
		end
	end
	LPltnk = false
	LPmedtnk = false
	LPheatnk = false 
	LPmamtnk = false
	LPtslatnk = false
	LPchtnk = false
	Box11Chosen = false
	Box12Chosen = false
	Box13Chosen = false
	Box14Chosen = false

	HPinCounter = 0
	VPinCounter = 0
	LSetRedPins()
	LeftBar.Destroy()

	if LeftTry < 10 then

		LeftCounter = 0
		Trigger.AfterDelay(DateTime.Seconds(1), function()

			LPlayerUnit1.Stop()
			LPlayerUnit2.Stop()
			LPlayerUnit3.Stop()
			LPlayerUnit4.Stop()
			LPlayerUnit5.Stop()
			LPlayerUnit6.Stop()
			Barb = Leftplayer.GetActorsByType("1tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Leftplayer.GetActorsByType("2tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Leftplayer.GetActorsByType("3tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Leftplayer.GetActorsByType("4tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Leftplayer.GetActorsByType("ttnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Leftplayer.GetActorsByType("ctnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = France.GetActorsByType("nix01l")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Trigger.AfterDelay(DateTime.Seconds(1), function()
				Barb = Leftplayer.GetActorsByType("1tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Leftplayer.GetActorsByType("2tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Leftplayer.GetActorsByType("3tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Leftplayer.GetActorsByType("4tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Leftplayer.GetActorsByType("ttnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Leftplayer.GetActorsByType("ctnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = France.GetActorsByType("nix01l")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				LVerticalShift = LVerticalShift - 4
				
				LRedPin = 0
				LWhitePin = 0
				Trigger.AfterDelay(10, function()
					if not LeftPlayerWon then
						LeftBar = Actor.Create("nix01bar", true, { Location = CPos.New(21,44) + CVec.New(0, LVerticalShift), Owner = Leftplayer })
					end
				end)
				if not LeftPlayerWon or LeftPlayerLoose then
					LPlayerUnitsIncome()
				end
			end)	
		end)
	end	
end

LSetRedPins = function()
	if LRedPin > 0 then
		newactor = Actor.Create("apc", true, { Location = CPos.New(23,44) + CVec.New(0 + HPinCounter, LVerticalShift + VPinCounter), Owner = Chooser })
		LRedPin = LRedPin - 1
		if HPinCounter < 2 then
			HPinCounter = HPinCounter + 2
		elseif VPinCounter < 2 then
			HPinCounter = 0
			VPinCounter = VPinCounter + 2
		end
		LSetRedPins()
	elseif  LWhitePin > 0 then
		LSetWhitePins()
	end
end

LSetWhitePins = function()
	if LWhitePin > 0 then
		newactor = Actor.Create("apc", true, { Location = CPos.New(23,44) + CVec.New(0 + HPinCounter, LVerticalShift + VPinCounter), Owner = Neutral })
		LWhitePin = LWhitePin - 1
		if HPinCounter < 2 then
			HPinCounter = HPinCounter + 2
		elseif VPinCounter < 2 then
			HPinCounter = 0
			VPinCounter = VPinCounter + 2
		end
		LSetWhitePins()
	end
end

-- %%


SetRightPlayerTriggers = function()

--Box15

	Trigger.OnEnteredFootprint(MoveseBox15, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(38, 49))
		newactor = Actor.Create("nix01r", true, { Location = CPos.New(38,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(38, 49))
			end
		end)
	end)


	Trigger.OnEnteredFootprint(ChooseBox15, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(38,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPltnk = true
				if Box5lt then
					RRedPin = RRedPin + 1
				elseif Rltnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(38,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmedtnk = true
				if Box5met then
					RRedPin = RRedPin + 1
				elseif Rmedtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(38,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPheatnk = true
				if Box5ht then
					RRedPin = RRedPin + 1
				elseif Rheatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(38,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmamtnk = true
				if Box5mat then
					RRedPin = RRedPin + 1
				elseif Rmamtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(38,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPtslatnk = true
				if Box5tt then
					RRedPin = RRedPin + 1
				elseif Rtslatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(38,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPchtnk = true
				if Box5ct then
					RRedPin = RRedPin + 1
				elseif Rchtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			RightCounter = RightCounter + 1
			Box15Chosen = true
			if RightCounter == 4 then
				RightPlayerReady()
			end
		end)
	end)

--Box16

	Trigger.OnEnteredFootprint(MoveseBox16, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(43, 49))
		newactor = Actor.Create("nix01r", true, { Location = CPos.New(43,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(43, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox16, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(43,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPltnk = true
				if Box6lt then
					RRedPin = RRedPin + 1
				elseif Rltnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(43,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmedtnk = true
				if Box6met then
					RRedPin = RRedPin + 1
				elseif Rmedtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(43,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPheatnk = true
				if Box6ht then
					RRedPin = RRedPin + 1
				elseif Rheatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(43,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmamtnk = true
				if Box6mat then
					RRedPin = RRedPin + 1
				elseif Rmamtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(43,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPtslatnk = true
				if Box6tt then
					RRedPin = RRedPin + 1
				elseif Rtslatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(43,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPchtnk = true
				if Box6ct then
					RRedPin = RRedPin + 1
				elseif Rchtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			RightCounter = RightCounter + 1
			Box16Chosen = true
			if RightCounter == 4 then
				RightPlayerReady()
			end
		end)
	end)

--Box17

	Trigger.OnEnteredFootprint(MoveseBox17, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(48, 49))
		newactor = Actor.Create("nix01r", true, { Location = CPos.New(48,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(48, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox17, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(48,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPltnk = true
				if Box7lt then
					RRedPin = RRedPin + 1
				elseif Rltnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(48,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmedtnk = true
				if Box7met then
					RRedPin = RRedPin + 1
				elseif Rmedtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(48,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPheatnk = true
				if Box7ht then
					RRedPin = RRedPin + 1
				elseif Rheatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(48,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmamtnk = true
				if Box7mat then
					RRedPin = RRedPin + 1
				elseif Rmamtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(48,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPtslatnk = true
				if Box7tt then
					RRedPin = RRedPin + 1
				elseif Rtslatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(48,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPchtnk = true
				if Box7ct then
					RRedPin = RRedPin + 1
				elseif Rchtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			Box17Chosen = true
			RightCounter = RightCounter + 1
			if RightCounter == 4 then
				RightPlayerReady()
			end
		end)
	end)

--Box18

	Trigger.OnEnteredFootprint(MoveseBox18, function(a, id) 
		a.Stop()
		a.ScriptedMove(CPos.New(53, 49))
		newactor = Actor.Create("nix01r", true, { Location = CPos.New(53,51), Owner = France })
		Trigger.AfterDelay(DateTime.Seconds(2), function()
			if a.IsInWorld then
				a.Stop()
				a.ScriptedMove(CPos.New(53, 49))
			end
		end)
	end)

	Trigger.OnEnteredFootprint(ChooseBox18, function(a, id) 
		Trigger.RemoveFootprintTrigger(id)
		a.Stop()
		Media.PlaySoundNotification( allplayers, "BaseSetup")
		Trigger.OnIdle(a, function()
			Trigger.ClearAll(a)
			if a.Type == "1tnkn" then
				newactor = Actor.Create("1tnkf", true, { Location = CPos.New(53,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPltnk = true
				if Box8lt then
					RRedPin = RRedPin + 1
				elseif Rltnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "2tnkn" then
				newactor = Actor.Create("2tnkf", true, { Location = CPos.New(53,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmedtnk = true
				if Box8met then
					RRedPin = RRedPin + 1
				elseif Rmedtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "3tnkn" then
				newactor = Actor.Create("3tnkf", true, { Location = CPos.New(53,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPheatnk = true
				if Box8ht then
					RRedPin = RRedPin + 1
				elseif Rheatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "4tnkn" then
				newactor = Actor.Create("4tnkf", true, { Location = CPos.New(53,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPmamtnk = true
				if Box8mat then
					RRedPin = RRedPin + 1
				elseif Rmamtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ttnkn" then
				newactor = Actor.Create("ttnkf", true, { Location = CPos.New(53,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPtslatnk = true
				if Box8tt then
					RRedPin = RRedPin + 1
				elseif Rtslatnk then
					RWhitePin = RWhitePin + 1
				end
			end
			if a.Type == "ctnkn" then
				newactor = Actor.Create("ctnkf", true, { Location = CPos.New(53,45) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
				RPchtnk = true
				if Box8ct then
					RRedPin = RRedPin + 1
				elseif Rchtnk then
					RWhitePin = RWhitePin + 1
				end
			end
			RightCounter = RightCounter + 1
			Box18Chosen = true
			if RightCounter == 4 then
				RightPlayerReady()
			end
		end)
	end)
end

-- $$



RightPlayerReady = function()
	RightPlayerRoundTime = RoundTime - RightPlayerTime
	if Round2 then
		Multi2TimeNeeded = Multi2TimeNeeded + RightPlayerRoundTime
	else
		Multi1TimeNeeded = Multi1TimeNeeded + RightPlayerRoundTime
	end
	if RRedPin == 4 then
		RightSign = Actor.Create("nix01win", true, { Location = CPos.New(31,51), Owner = Rightplayer })
		RightPlayerWon = true
		Barb = Rightowner.GetActorsByType("q1d13s")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		if LeftPlayerWon or LeftPlayerLoose then
			if not Round2 then
				EndRound()
			else
				GameOver()
			end
		end
	end
	RightTry = RightTry + 1
	if RightTry == 10 and not RightPlayerWon then
		RightSign = Actor.Create("nix01loose", true, { Location = CPos.New(31,51), Owner = Rightplayer })
		RightPlayerLoose = true
		Barb = Rightowner.GetActorsByType("q1d13s")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		if LeftPlayerWon or LeftPlayerLoose then
			if not Round2 then
				EndRound()
			else
				GameOver()
			end
		end
	end
	if not RightPlayerWon then
		if not RightPlayerLoose then
			RightPlayerTime = RoundTime
			RightTimerExpired = false
		end
	end
	RPltnk = false
	RPmedtnk = false
	RPheatnk = false 
	RPmamtnk = false
	RPtslatnk = false
	RPchtnk = false
	Box15Chosen = false
	Box16Chosen = false
	Box17Chosen = false
	Box18Chosen = false
	HPinCounter2 = 0
	VPinCounter2 = 0
	RSetRedPins()
	RightBar.Destroy()
	if RightTry < 10 then
		RightCounter = 0
		Trigger.AfterDelay(DateTime.Seconds(1), function()
			RPlayerUnit1.Stop()
			RPlayerUnit2.Stop()
			RPlayerUnit3.Stop()
			RPlayerUnit4.Stop()
			RPlayerUnit5.Stop()
			RPlayerUnit6.Stop()
			Barb = Rightplayer.GetActorsByType("1tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Rightplayer.GetActorsByType("2tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Rightplayer.GetActorsByType("3tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Rightplayer.GetActorsByType("4tnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Rightplayer.GetActorsByType("ttnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = Rightplayer.GetActorsByType("ctnkn")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Barb = France.GetActorsByType("nix01r")
			for p,fences in pairs(Barb) do
				fences.Destroy()
			end
			Trigger.AfterDelay(DateTime.Seconds(1), function()
				Barb = Rightplayer.GetActorsByType("1tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Rightplayer.GetActorsByType("2tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Rightplayer.GetActorsByType("3tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Rightplayer.GetActorsByType("4tnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Rightplayer.GetActorsByType("ttnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = Rightplayer.GetActorsByType("ctnkn")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				Barb = France.GetActorsByType("nix01r")
				for p,fences in pairs(Barb) do
					fences.Destroy()
				end
				RVerticalShift = RVerticalShift - 4
				RRedPin = 0
				RWhitePin = 0
				Trigger.AfterDelay(10, function()
					if not RightPlayerWon then
						RightBar = Actor.Create("nix01bar", true, { Location = CPos.New(35,44) + CVec.New(0, RVerticalShift), Owner = Rightplayer })
					end
				end)
				if not RightPlayerWon or RightPlayerLoose then
					RPlayerUnitsIncome()
				end
			end)	
		end)
	end
end

RSetRedPins = function()
	if RRedPin > 0 then
		newactor = Actor.Create("apc", true, { Location = CPos.New(33,44) + CVec.New(0 + HPinCounter2, RVerticalShift + VPinCounter2), Owner = Chooser })
		RRedPin = RRedPin - 1
		if HPinCounter2 == 0 then
			HPinCounter2 = HPinCounter2 - 2
		elseif VPinCounter2 < 2 then
			HPinCounter2 = 0
			VPinCounter2 = VPinCounter2 + 2
		end
		RSetRedPins()
	elseif  RWhitePin > 0 then
		RSetWhitePins()
	end
end

RSetWhitePins = function()
	if RWhitePin > 0 then
		newactor = Actor.Create("apc", true, { Location = CPos.New(33,44) + CVec.New(0 + HPinCounter2, RVerticalShift + VPinCounter2), Owner = Neutral })
		RWhitePin = RWhitePin - 1
		if HPinCounter2 == 0 then
			HPinCounter2 = HPinCounter2 - 2
		elseif VPinCounter2 < 2 then
			HPinCounter2 = 0
			VPinCounter2 = VPinCounter2 + 2
		end
		RSetWhitePins()
	end
end

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

-- &&

LeftPlayerRoundtimeOverRNDUnitSet = function()
	RandomUnitCounter = Utils.Random(UnitCounter)
	if LeftCounter < 4 then
		if not Box11Chosen then
			if LPlayerUnit1.IsInWorld and not LPltnk and not Box1lt and RandomUnitCounter == 1 then
				LPlayerUnit1.Stop()
				LPlayerUnit1.Teleport(CPos.New(3, 49))
			elseif LPlayerUnit2.IsInWorld and not LPmedtnk and not Box1met and RandomUnitCounter == 2 then
				LPlayerUnit2.Stop()
				LPlayerUnit2.Teleport(CPos.New(3, 49))
			elseif LPlayerUnit3.IsInWorld and not LPheatnk and not Box1ht and RandomUnitCounter == 3 then
				LPlayerUnit3.Stop()
				LPlayerUnit3.Teleport(CPos.New(3, 49))
			elseif LPlayerUnit4.IsInWorld and not LPmamtnk and not Box1mat and RandomUnitCounter == 4 then
				LPlayerUnit4.Stop()
				LPlayerUnit4.Teleport(CPos.New(3, 49))
			elseif LPlayerUnit5.IsInWorld and not LPtslatnk and not Box1tt and RandomUnitCounter == 5 then
				LPlayerUnit5.Stop()
				LPlayerUnit5.Teleport(CPos.New(3, 49))
			elseif LPlayerUnit6.IsInWorld and not LPchtnk and not Box1ct  and RandomUnitCounter == 6 then
				LPlayerUnit6.Stop()
				LPlayerUnit6.Teleport(CPos.New(3, 49))
			end
		end
	end
	if LeftCounter < 4 then
		if not Box12Chosen then
			if LPlayerUnit1.IsInWorld and not LPltnk and not Box2lt and RandomUnitCounter == 1 then
				LPlayerUnit1.Stop()
				LPlayerUnit1.Teleport(CPos.New(8, 49))
			elseif LPlayerUnit2.IsInWorld and not LPmedtnk and not Box2met and RandomUnitCounter == 2 then
				LPlayerUnit2.Stop()
				LPlayerUnit2.Teleport(CPos.New(8, 49))
			elseif LPlayerUnit3.IsInWorld and not LPheatnk and not Box2ht and RandomUnitCounter == 3 then
				LPlayerUnit3.Stop()
				LPlayerUnit3.Teleport(CPos.New(8, 49))
			elseif LPlayerUnit4.IsInWorld and not LPmamtnk and not Box2mat and RandomUnitCounter == 4 then
				LPlayerUnit4.Stop()
				LPlayerUnit4.Teleport(CPos.New(8, 49))
			elseif LPlayerUnit5.IsInWorld and not LPtslatnk and not Box2tt and RandomUnitCounter == 5 then
				LPlayerUnit5.Stop()
				LPlayerUnit5.Teleport(CPos.New(8, 49))
			elseif LPlayerUnit6.IsInWorld and not LPchtnk and not Box2ct and RandomUnitCounter == 6 then
				LPlayerUnit6.Stop()
				LPlayerUnit6.Teleport(CPos.New(8, 49))
			end
		end
	end
	if LeftCounter < 4 then
		if not Box13Chosen then
			if LPlayerUnit1.IsInWorld and not LPltnk and not Box3lt and RandomUnitCounter == 1 then
				LPlayerUnit1.Stop()
				LPlayerUnit1.Teleport(CPos.New(13, 49))
			elseif LPlayerUnit2.IsInWorld and not LPmedtnk and not Box3met and RandomUnitCounter == 2 then
				LPlayerUnit2.Stop()
				LPlayerUnit2.Teleport(CPos.New(13, 49))
			elseif LPlayerUnit3.IsInWorld and not LPheatnk and not Box3ht and RandomUnitCounter == 3 then
				LPlayerUnit3.Stop()
				LPlayerUnit3.Teleport(CPos.New(13, 49))
			elseif LPlayerUnit4.IsInWorld and not LPmamtnk and not Box3mat and RandomUnitCounter == 4 then
				LPlayerUnit4.Stop()
				LPlayerUnit4.Teleport(CPos.New(13, 49))
			elseif LPlayerUnit5.IsInWorld and not LPtslatnk and not Box3tt and RandomUnitCounter == 5 then
				LPlayerUnit5.Stop()
				LPlayerUnit5.Teleport(CPos.New(13, 49))
			elseif LPlayerUnit6.IsInWorld and not LPchtnk and not Box3ct and RandomUnitCounter == 6 then
				LPlayerUnit6.Stop()
				LPlayerUnit6.Teleport(CPos.New(13, 49))
			end
		end
	end
	if LeftCounter < 4 then
		if not Box14Chosen then
			if LPlayerUnit1.IsInWorld and not LPltnk and not Box4lt and RandomUnitCounter == 1 then
				LPlayerUnit1.Stop()
				LPlayerUnit1.Teleport(CPos.New(18, 49))
			elseif LPlayerUnit2.IsInWorld and not LPmedtnk and not Box4met and RandomUnitCounter == 2 then
				LPlayerUnit2.Stop()
				LPlayerUnit2.Teleport(CPos.New(18, 49))
			elseif LPlayerUnit3.IsInWorld and not LPheatnk and not Box4ht and RandomUnitCounter == 3 then
				LPlayerUnit3.Stop()
				LPlayerUnit3.Teleport(CPos.New(18, 49))
			elseif LPlayerUnit4.IsInWorld and not LPmamtnk and not Box4mat and RandomUnitCounter == 4 then
				LPlayerUnit4.Stop()
				LPlayerUnit4.Teleport(CPos.New(18, 49))
			elseif LPlayerUnit5.IsInWorld and not LPtslatnk and not Box4tt and RandomUnitCounter == 5 then
				LPlayerUnit5.Stop()
				LPlayerUnit5.Teleport(CPos.New(18, 49))
			elseif LPlayerUnit6.IsInWorld and not LPchtnk and not Box4ct and RandomUnitCounter == 6 then
				LPlayerUnit6.Stop()
				LPlayerUnit6.Teleport(CPos.New(18, 49))
			end
		end
	end
	if LeftCounter < 4 and LeftTimerExpired then
		LeftRNDUnitsSet = true
		Trigger.AfterDelay(10, function()
			LeftPlayerRoundtimeOverRNDUnitSet()
		end)
	end
end



-- Right side
RightPlayerRoundtimeOverRNDUnitSet = function()
	RandomUnitCounter2 = Utils.Random(UnitCounter)
	if RightCounter < 4 then
		if not Box15Chosen then
			if RPlayerUnit1.IsInWorld and not RPltnk and not Box5lt and RandomUnitCounter2 == 1 then
				RPlayerUnit1.Stop()
				RPlayerUnit1.Teleport(CPos.New(38, 49))
			elseif RPlayerUnit2.IsInWorld and not RPmedtnk and not Box5met and RandomUnitCounter2 == 2 then
				RPlayerUnit2.Stop()
				RPlayerUnit2.Teleport(CPos.New(38, 49))
			elseif RPlayerUnit3.IsInWorld and not RPheatnk and not Box5ht and RandomUnitCounter2 == 3 then
				RPlayerUnit3.Stop()
				RPlayerUnit3.Teleport(CPos.New(38, 49))
			elseif RPlayerUnit4.IsInWorld and not RPmamtnk and not Box5mat and RandomUnitCounter2 == 4 then
				RPlayerUnit4.Stop()
				RPlayerUnit4.Teleport(CPos.New(38, 49))
			elseif RPlayerUnit5.IsInWorld and not RPtslatnk and not Box5tt and RandomUnitCounter2 == 5 then
				RPlayerUnit5.Stop()
				RPlayerUnit5.Teleport(CPos.New(38, 49))
			elseif RPlayerUnit6.IsInWorld and not RPchtnk and not Box5ct and RandomUnitCounter2 == 6 then
				RPlayerUnit6.Stop()
				RPlayerUnit6.Teleport(CPos.New(38, 49))
			end
		end
	end
	if RightCounter < 4 then
		if not Box16Chosen then
			if RPlayerUnit1.IsInWorld and not RPltnk and not Box6lt and RandomUnitCounter2 == 1 then
				RPlayerUnit1.Stop()
				RPlayerUnit1.Teleport(CPos.New(43, 49))
			elseif RPlayerUnit2.IsInWorld and not RPmedtnk and not Box6met and RandomUnitCounter2 == 2 then
				RPlayerUnit2.Stop()
				RPlayerUnit2.Teleport(CPos.New(43, 49))
			elseif RPlayerUnit3.IsInWorld and not RPheatnk and not Box6ht and RandomUnitCounter2 == 3 then
				RPlayerUnit3.Stop()
				RPlayerUnit3.Teleport(CPos.New(43, 49))
			elseif RPlayerUnit4.IsInWorld and not RPmamtnk and not Box6mat and RandomUnitCounter2 == 4 then
				RPlayerUnit4.Stop()
				RPlayerUnit4.Teleport(CPos.New(43, 49))
			elseif RPlayerUnit5.IsInWorld and not RPtslatnk and not Box6tt and RandomUnitCounter2 == 5 then
				RPlayerUnit5.Stop()
				RPlayerUnit5.Teleport(CPos.New(43, 49))
			elseif RPlayerUnit6.IsInWorld and not RPchtnk and not Box6ct and RandomUnitCounter2 == 6 then
				RPlayerUnit6.Stop()
				RPlayerUnit6.Teleport(CPos.New(43, 49))
			end
		end
	end
	if RightCounter < 4 then
		if not Box17Chosen then
			if RPlayerUnit1.IsInWorld and not RPltnk and not Box7lt and RandomUnitCounter2 == 1 then
				RPlayerUnit1.Stop()
				RPlayerUnit1.Teleport(CPos.New(48, 49))
			elseif RPlayerUnit2.IsInWorld and not RPmedtnk and not Box7met and RandomUnitCounter2 == 2 then
				RPlayerUnit2.Stop()
				RPlayerUnit2.Teleport(CPos.New(48, 49))
			elseif RPlayerUnit3.IsInWorld and not RPheatnk and not Box7ht and RandomUnitCounter2 == 3 then
				RPlayerUnit3.Stop()
				RPlayerUnit3.Teleport(CPos.New(48, 49))
			elseif RPlayerUnit4.IsInWorld and not RPmamtnk and not Box7mat and RandomUnitCounter2 == 4 then
				RPlayerUnit4.Stop()
				RPlayerUnit4.Teleport(CPos.New(48, 49))
			elseif RPlayerUnit5.IsInWorld and not RPtslatnk and not Box7tt and RandomUnitCounter2 == 5 then
				RPlayerUnit5.Stop()
				RPlayerUnit5.Teleport(CPos.New(48, 49))
			elseif RPlayerUnit6.IsInWorld and not RPchtnk and not Box7ct and RandomUnitCounter2 == 6 then
				RPlayerUnit6.Stop()
				RPlayerUnit6.Teleport(CPos.New(48, 49))
			end
		end
	end
	if RightCounter < 4 then
		if not Box18Chosen then
			if RPlayerUnit1.IsInWorld and not RPltnk and not Box8lt and RandomUnitCounter2 == 1 then
				RPlayerUnit1.Stop()
				RPlayerUnit1.Teleport(CPos.New(53, 49))
			elseif RPlayerUnit2.IsInWorld and not RPmedtnk and not Box8met and RandomUnitCounter2 == 2 then
				RPlayerUnit2.Stop()
				RPlayerUnit2.Teleport(CPos.New(53, 49))
			elseif RPlayerUnit3.IsInWorld and not RPheatnk and not Box8ht and RandomUnitCounter2 == 3 then
				RPlayerUnit3.Stop()
				RPlayerUnit3.Teleport(CPos.New(53, 49))
			elseif RPlayerUnit4.IsInWorld and not RPmamtnk and not Box8mat and RandomUnitCounter2 == 4 then
				RPlayerUnit4.Stop()
				RPlayerUnit4.Teleport(CPos.New(53, 49))
			elseif RPlayerUnit5.IsInWorld and not RPtslatnk and not Box8tt and RandomUnitCounter2 == 5 then
				RPlayerUnit5.Stop()
				RPlayerUnit5.Teleport(CPos.New(53, 49))
			elseif RPlayerUnit6.IsInWorld and not RPchtnk and not Box8ct and RandomUnitCounter2 == 6 then
				RPlayerUnit6.Stop()
				RPlayerUnit6.Teleport(CPos.New(53, 49))
			end
	
		end
	end
	if RightCounter < 4 and RightTimerExpired then
		Trigger.AfterDelay(10, function()
			RightPlayerRoundtimeOverRNDUnitSet()
		end)
	end
end

EndRound = function()

	if not Round2 then
		if LeftPlayerWon then
			Multi3Won = true
		end
		if RightPlayerWon then
			Multi1Won = true
		end
		Multi1Trys = RightTry
		Multi3Trys = LeftTry
		Utils.Do(humans, function(player)
			Player1Name = Multi0.Name
			Player2Name = Multi1.Name
			Player3Name = Multi2.Name
			Player4Name = Multi3.Name
		end)
		Media.DisplayMessage(" "  .. Player2Name .. " needed " .. Utils.FormatTime(Multi1TimeNeeded) .. " and " .. Multi1Trys .. " Tryes.", "Materia", HSLColor.White)
		Media.DisplayMessage(" "  .. Player4Name .. " needed " .. Utils.FormatTime(Multi3TimeNeeded) .. " and " .. Multi3Trys .. " Tryes.", "Materia", HSLColor.White)
	end
	Trigger.AfterDelay(DateTime.Seconds(10), function()
		turnOff()
		PlayTimeCounter = false
		RoundOver = true
		Barb = Leftplayer.GetActorsByType("1tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Leftplayer.GetActorsByType("2tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Leftplayer.GetActorsByType("3tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Leftplayer.GetActorsByType("4tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Leftplayer.GetActorsByType("ttnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Leftplayer.GetActorsByType("ctnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Leftplayer.GetActorsByType("1tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftplayer.GetActorsByType("2tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftplayer.GetActorsByType("3tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftplayer.GetActorsByType("4tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftplayer.GetActorsByType("ttnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftplayer.GetActorsByType("ctnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end

		Barb = Rightplayer.GetActorsByType("1tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Rightplayer.GetActorsByType("2tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Rightplayer.GetActorsByType("3tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Rightplayer.GetActorsByType("4tnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Rightplayer.GetActorsByType("ttnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Rightplayer.GetActorsByType("ctnkn")
		for p,fences in pairs(Barb) do
			if fences.IsInWorld then
				fences.Stop()
				fences.Destroy()
			end
		end
		Barb = Rightplayer.GetActorsByType("1tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightplayer.GetActorsByType("2tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightplayer.GetActorsByType("3tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightplayer.GetActorsByType("4tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightplayer.GetActorsByType("ttnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightplayer.GetActorsByType("ctnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end

		Barb = Rightowner.GetActorsByType("1tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightowner.GetActorsByType("2tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightowner.GetActorsByType("3tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightowner.GetActorsByType("4tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightowner.GetActorsByType("ttnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Rightowner.GetActorsByType("ctnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftowner.GetActorsByType("1tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftowner.GetActorsByType("2tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftowner.GetActorsByType("3tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftowner.GetActorsByType("4tnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftowner.GetActorsByType("ttnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Leftowner.GetActorsByType("ctnkf")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end

		Barb = Chooser.GetActorsByType("apc")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Neutral.GetActorsByType("apc")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Neutral.GetActorsByType("nix01")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end
		Barb = Neutral.GetActorsByType("nix02")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end

		Barb = Neutral.GetActorsByType("nix03")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end

		Barb = Neutral.GetActorsByType("q1d07")
		for p,fences in pairs(Barb) do
			fences.Destroy()
		end

		LeftBigCam1.Destroy()
		RightBigCam1.Destroy()
		LeftName.Destroy()
		RightName.Destroy()
		VSsign.Destroy()
		LeftSign.Destroy()
		RightSign.Destroy()

		LeftCam1.Destroy()
		RightCam1.Destroy()
		LeftCam2.Destroy()
		RightCam2.Destroy()

		Leftowner = Multi3
		Rightowner = Multi1
		Leftplayer = Multi0
		Rightplayer = Multi2
		LeftCam1 = Actor.Create("nix01cam", true, { Location = CPos.New(5,4), Owner = Leftowner })
		RightCam1 = Actor.Create("nix01cam", true, { Location = CPos.New(40,4), Owner = Rightowner })
		LeftCam2 = Actor.Create("nix01cam", true, { Location = CPos.New(10,30), Owner = Leftplayer })
		RightCam2 = Actor.Create("nix01cam", true, { Location = CPos.New(40,30), Owner = Rightplayer })
		CoverMap()
		Box1lt = false
		Box1met = false
		Box1ht = false
		Box1mat = false
		Box1tt = false
		Box1ct = false
		Box1Chosen = false
		Box2lt = false
		Box2met = false
		Box2ht = false
		Box2mat = false
		Box2tt = false
		Box2ct = false
		Box2Chosen = false
		Box3lt = false
		Box3met = false
		Box3ht = false
		Box3mat = false
		Box3tt = false
		Box3ct = false
		Box3Chosen = false
		Box4lt = false
		Box4met = false
		Box4ht = false
		Box4mat = false
		Box4tt = false
		Box4ct = false
		Box4Chosen = false

		Box5lt = false
		Box5met = false
		Box5ht = false
		Box5mat = false
		Box5tt = false
		Box5ct = false
		Box5Chosen = false
		Box6lt = false
		Box6met = false
		Box6ht = false
		Box6mat = false
		Box6tt = false
		Box6ct = false
		Box6Chosen = false
		Box7lt = false
		Box7met = false
		Box7ht = false
		Box7mat = false
		Box7tt = false
		Box7ct = false
		Box7Chosen = false
		Box8lt = false
		Box8met = false
		Box8ht = false
		Box8mat = false
		Box8tt = false
		Box8ct = false
		Box8Chosen = false

		Lchtnk = false
		Ltslatnk = false
		Lmamtnk = false
		Lheatnk = false
		Lmedtnk = false
		Lltnk = false

		Rchtnk = false
		Rtslatnk = false
		Rmamtnk = false
		Rheatnk = false
		Rmedtnk = false
		Rltnk = false
		PlayerStarts = false
		LeftChooserisReady = false
		RightChooserisReady = false
		LeftPlayerWon = false
		LeftPlayerLoose = false
		RightPlayerWon = false
		RightPlayerLoose = false
		RightTimerExpired = false
		LeftTimerExpired = false
		LeftCounter = 0
		RightCounter = 0
--		countmidleft = 0
		countleft1 = 0
		countleftV1 = 0
		countleftH1 = 0
		countleftV2 = 0
		countleftH2 = 0
--		countleftH3 = 0
--		countmidright = 0
		countright1 = 0
		countrightV1 = 0
		countrightH1 = 0
		countrightV2 = 0
		countrightH2 = 0
--		countrightH3 = 0
		ccountH2 = 0
		ccountH6 = 0
		ccountV5 = 0
		ccountV1 = 0
		ccountH1 = 0
		Trigger.AfterDelay(50, 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
			Round2 = true
			ChooserUnits()
			SetTriggers()
			SetChoosingtimer()
			RoundOver = false
			LeftGap = Actor.Create("nix01s", true, { Location = CPos.New(10,11), Owner = Leftowner })
			RightGap = Actor.Create("nix01s", true, { Location = CPos.New(45,11), Owner = Rightowner })
			LeftPW = Actor.Create("nix01PW", true, { Location = CPos.New(10,27), Owner = Leftplayer })
			RightPW = Actor.Create("nix01PW", true, { Location = CPos.New(40,27), Owner = Rightplayer })
			Trigger.AfterDelay(50, function()
				LeftNameStart = Actor.Create("nix01pname", true, { Location = CPos.New(11,30), Owner = Leftowner })
				RightNameStart = Actor.Create("nix01pname", true, { Location = CPos.New(41,30), Owner = Rightowner })
				Trigger.AfterDelay(50, function()
					LeftIsChoosing = Actor.Create("nix01ictc", true, { Location = CPos.New(10,31), Owner = Leftplayer })
					RightIsChoosing = Actor.Create("nix01ictc", true, { Location = CPos.New(40,31), Owner = Rightplayer })
				end)
			end)
		end)
	end)
end
		



ccountH2 = 0
ccountH6 = 0
ccountV5 = 0
ccountV1 = 0
ccountH1 = 0

CoverMap = function()

	if ccountV1 < 4 then
		newactor = Actor.Create("nix02", true, { Location = CPos.New(5,47) + CVec.New(ccountH1, ccountV1), Owner = France })
		newactor = Actor.Create("nix02", true, { Location = CPos.New(40,47) + CVec.New(ccountH1, ccountV1), Owner = France })
		ccountV1 = ccountV1 + 1

	elseif ccountH1 < 13 then
		ccountV1 = 0
		ccountH1 = ccountH1 + 5
	end

	if ccountH2 < 16 then
		newactor = Actor.Create("q1d13s", true, { Location = CPos.New(2,2) + CVec.New(ccountH2, 0), Owner = Leftowner })
		newactor = Actor.Create("q1d13s", true, { Location = CPos.New(37,2) + CVec.New(ccountH2, 0), Owner = Rightowner })
		ccountH2 = ccountH2 + 5
	end
	if ccountH6 < 18 then
		newactor = Actor.Create("nix03l", true, { Location = CPos.New(2,11) + CVec.New(ccountH6, ccountV5), Owner = France })
		newactor = Actor.Create("nix03r", true, { Location = CPos.New(37,11) + CVec.New(ccountH6, ccountV5), Owner = France })
		ccountH6 = ccountH6 + 3
		CoverMap()
	elseif ccountV5 < 32 then
		ccountH6 = 0
		ccountV5 = ccountV5 + 3
		CoverMap()
	end

end
-- §§

GameOver = function()
	if Round2 then
		if LeftPlayerWon then
			Multi0Won = true
		end
		if RightPlayerWon then
			Multi2Won = true
		end
	end
	Multi2Trys = RightTry
	Multi0Trys = LeftTry
	Utils.Do(humans, function(player)
		Player1Name = Multi0.Name
		Player2Name = Multi1.Name
		Player3Name = Multi2.Name
		Player4Name = Multi3.Name
	end)
	if Multi0Won then
		Media.DisplayMessage("Congratulations "  .. Player1Name .. " you needed " .. Utils.FormatTime(Multi0TimeNeeded) .. " minutes and " .. Multi0Trys .. " Tryes to win the game.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi0.MarkCompletedObjective(Win_the_game0)
		end)
	else
		Media.DisplayMessage(" "  .. Player1Name .. " you needed " .. Utils.FormatTime(Multi0TimeNeeded) .. " minutes and " .. Multi0Trys .. " Tryes, maybe next time you win.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi0.MarkFailedObjective(Win_the_game0)
		end)
	end

	if Multi1Won then
		Media.DisplayMessage("Congratulations "  .. Player2Name .. " you needed " .. Utils.FormatTime(Multi1TimeNeeded) .. " minutes and" .. Multi1Trys .. " Tryes to win the game.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi1.MarkCompletedObjective(Win_the_game1)
		end)
	else
		Media.DisplayMessage(" "  .. Player2Name .. " you needed " .. Utils.FormatTime(Multi1TimeNeeded) .. " minutes and " .. Multi1Trys .. " Tryes, maybe next time you win.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi1.MarkFailedObjective(Win_the_game1)
		end)
	end

	if Multi2Won then
		Media.DisplayMessage("Congratulations "  .. Player3Name .. " you needed " .. Utils.FormatTime(Multi2TimeNeeded) .. " minutes and " .. Multi2Trys .. " Tryes to win the game.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi2.MarkCompletedObjective(Win_the_game2)
		end)
	else
		Media.DisplayMessage(" "  .. Player3Name .. " you needed " .. Utils.FormatTime(Multi2TimeNeeded) .. " minutes and " .. Multi2Trys .. " Tryes, maybe next time you win.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi2.MarkFailedObjective(Win_the_game2)
		end)
	end

	if Multi3Won then
		Media.DisplayMessage("Congratulations "  .. Player4Name .. " you needed " .. Utils.FormatTime(Multi3TimeNeeded) .. " minutes and " .. Multi3Trys .. " Tryes to win the game.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi3.MarkCompletedObjective(Win_the_game3)
		end)
	else
		Media.DisplayMessage(" "  .. Player4Name .. " you needed " .. Utils.FormatTime(Multi3TimeNeeded) .. " minutes and " .. Multi3Trys .. " Tryes, maybe next time you win.", "Materia", HSLColor.White)
		Trigger.AfterDelay(DateTime.Seconds(10), function()
			Multi3.MarkFailedObjective(Win_the_game3)
		end)
	end
end

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

SetupPlayers = function()
	Chooser = Player.GetPlayer("Chooser")
	France = Player.GetPlayer("france")
	Neutral = Player.GetPlayer("Neutral")
	Multi0 = Player.GetPlayer("Multi0")
	if Multi0 == nil then
		Multi0 = Player.GetPlayer("Multi1")
		if Multi0 == nil then
			anyplayer = Utils.Random(Allfactions)
			Multi0 = Player.GetPlayer(anyplayer)
		end
	end
	Multi1 = Player.GetPlayer("Multi1")
	if Multi1 == nil then
		Multi1 = Player.GetPlayer("Multi0")
		if Multi1 == nil then
			anyplayer = Utils.Random(Allfactions)
			Multi1 = Player.GetPlayer(anyplayer)
		end
	end
	Multi2 = Player.GetPlayer("Multi2")
	if Multi2 == nil then
		Multi2 = Player.GetPlayer("Multi3")
		if Multi2 == nil then
			anyplayer = Utils.Random(Allfactions)
			Multi2 = Player.GetPlayer(anyplayer)
		end
	end
	Multi3 = Player.GetPlayer("Multi3")
	if Multi3 == nil then
		Multi3 = Player.GetPlayer("Multi2")
		if Multi3 == nil then
			anyplayer = Utils.Random(Allfactions)
			Multi3 = Player.GetPlayer(anyplayer)
		end
	end
	humans = { Multi0, Multi1, Multi2, Multi3 }
	Leftowner = Multi0
	Rightowner = Multi2
	Leftplayer = Multi3
	Rightplayer = Multi1
end

SetCamera = function(Multi)
	local mainbase = Multi.GetActorsByType("nix01cam")[1]
	Camera.Position = mainbase.CenterPosition
end

Light = 0

turnOff = function()
	Lighting.Ambient = Light
	if Light > 0.1 then
		Light = Light - 0.05
		Trigger.AfterDelay(1, function()
			turnOff()
		end)
	else
		Trigger.AfterDelay(50, function()
			turnOn()
		end)
	end
end





turnOn = function()
	Lighting.Ambient = Light
	if Light < 1 then
		Light = Light + 0.01
		Trigger.AfterDelay(1, function()
			turnOn()
		end)
	end
end

ChooseMessage = function()
	Utils.Do(humans, function(player)
		Player1Name = Leftowner.Name
		Player2Name = Rightplayer.Name
		Player3Name = Rightowner.Name
		Player4Name = Leftplayer.Name
	end)

	Media.DisplayMessage(" "  .. Player1Name .. " and " .. Player3Name .. " please choose the tankcodes.\nDrive on the white field to set the code.", "Materia", HSLColor.White)	

end

PlayerMessages = function()
	Utils.Do(humans, function(player)
		Player1Name = Leftowner.Name
		Player2Name = Rightplayer.Name
		Player3Name = Rightowner.Name
		Player4Name = Leftplayer.Name
	end)

	Media.DisplayMessage(" "  .. Player4Name .. " and " .. Player2Name .. " now it's your turn to find out the tankcode\nDrive on the white field to set the code.\nA red APC is placed for each code tank from the guess which is correct in both color and position. A white APC indicates the existence of a correct code tank placed in the wrong position.", "Materia", HSLColor.White)

end

function WorldLoaded()
	SetupPlayers()
	MakeStartingGround()
	MakeActors()
	ChooserUnits()
	turnOn()
	SetTriggers()
	SetChoosingtimer()
	Win_the_game0 = Multi0.AddPrimaryObjective("Win the game")
	Win_the_game1 = Multi1.AddPrimaryObjective("Win the game")
	Win_the_game2 = Multi2.AddPrimaryObjective("Win the game")
	Win_the_game3 = Multi3.AddPrimaryObjective("Win the game")
	if Map.LobbyOption("difficulty") == "30sec" then
		RoundTime = DateTime.Seconds(30)
	end
	if Map.LobbyOption("difficulty") == "60sec" then
		RoundTime = DateTime.Minutes(1)
	end
	if Map.LobbyOption("difficulty") == "150sec" then
		RoundTime = DateTime.Seconds(150)
	end
	Trigger.AfterDelay(1, 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

SetChoosingtimer = function()
	chooseTime = true
	ChoosingTime = DateTime.Seconds(30)
	
end

SetPlayerTimer = function()
	PlayTimeCounter = true
	LeftPlayerTime = RoundTime
	RightPlayerTime = RoundTime
	TimerColor = HSLColor.White
end


Tick = function()
	if chooseTime then
		if ChoosingTime > DateTime.Seconds(5) then
			TimerColor = HSLColor.White
		else TimerColor = HSLColor.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
	end
	if PlayTimeCounter then
		UserInterface.SetMissionText( "       " .. LeftTry .. " / 10 Trys                                                       " .. RightTry .. " / 10 Trys     \nRandomUnit set in                                          RandomUnit set in\n\n           " .. Utils.FormatTime(LeftPlayerTime) .. "                                                                 " .. Utils.FormatTime(RightPlayerTime) .. "     ", TimerColor)
		if LeftPlayerTime > 0 then
			LeftPlayerTime = LeftPlayerTime - 1
		end
		if RightPlayerTime > 0 then
			RightPlayerTime = RightPlayerTime - 1
		end
		if LeftPlayerTime == 0 and not LeftTimerExpired then
			LeftTimerExpired = true
			LeftPlayerRoundtimeOverRNDUnitSet()
		end
		if RightPlayerTime == 0 and not RightTimerExpired then
			RightTimerExpired = true
			RightPlayerRoundtimeOverRNDUnitSet()
		end
	end
	if RoundOver then
		UserInterface.SetMissionText(" ", TimerColor)
	end
end

