
PlayMusic = function()
	if GettingDark then
		Media.PlaySound("SilentNight.aud")
	else
		Media.PlaySound("JingleBells.aud")
	end
end

SetObjectiveandMakeTrees = function()
	if Player.GetPlayer("Multi0") ~= nil then
		BurnTree1 = Multi0.AddPrimaryObjective("Burn down the enemys Xmass-Tree")
	end
	if Player.GetPlayer("Multi1") ~= nil then
		BurnTree1 = Multi1.AddPrimaryObjective("Burn down the enemys Xmass-Tree")
	end
	if Player.GetPlayer("Multi2") ~= nil then
		BurnTree1 = Multi2.AddPrimaryObjective("Burn down the enemys Xmass-Tree")
	end
	if Player.GetPlayer("Multi3") ~= nil then
		BurnTree2 = Multi3.AddPrimaryObjective("Burn down the enemys Xmass-Tree")
	end
	if Player.GetPlayer("Multi4") ~= nil then
		BurnTree2 = Multi4.AddPrimaryObjective("Burn down the enemys Xmass-Tree")
	end
	if Player.GetPlayer("Multi5") ~= nil then
		BurnTree2 = Multi5.AddPrimaryObjective("Burn down the enemys Xmass-Tree")
	end
	Bottomtree = Actor.Create("ctree", true, { Location = CPos.New(8,87), Owner = Multi3 })
	Toptree = Actor.Create("ctree", true, { Location = CPos.New(54,11), Owner = Multi0 })
	Trigger.OnDamaged(Toptree, function(tree, attacker)
		if not ColorisRed then
			attackingplayer = attacker.Owner
			CounterColor = attackingplayer.Color
			Trigger.AfterDelay(DateTime.Seconds(1), function()
				if not ColorisRed then
					CounterColor = HSLColor.White
				end
			end)
		end
		TopTreeDamaged()
	end)
	Trigger.OnDamaged(Bottomtree, function(tree, attacker)
		if not ColorisRed then
			attackingplayer = attacker.Owner
			CounterColor = attackingplayer.Color
			Trigger.AfterDelay(DateTime.Seconds(1), function()
				if not ColorisRed then
					CounterColor = HSLColor.White
				end
			end)
		end
		BottomTreeDamaged()
	end)
	Trigger.OnKilled(Toptree, Team2Won)
	Trigger.OnKilled(Bottomtree, Team1Won)
end

TopTreeDamaged = function()
	if not TopTreeWasDamaged then
		TopTreeWasDamaged = true
		Media.DisplayMessage("" .. Multi0.Name .. ", " .. Multi1.Name .. " and " .. Multi2.Name .. " your christmastree is under fire take care you will loose the game if he gets destroyed!", "Santa Clause", White)
		Camera.Position = Toptree.CenterPosition
		Beacon.New(Multi0, Toptree.CenterPosition, 500, true)
	end
	if TopTreehealth < 50 and not toptrigger50 then
		toptrigger50 = true
		Media.DisplayMessage("The northern christmastree is under heavy fire!", "Santa Clause", White)
	end
end

BottomTreeDamaged = function()
	if not BottomTreeWasDamaged then
		BottomTreeWasDamaged = true
		Media.DisplayMessage("" .. Multi3.Name .. ", " .. Multi4.Name .. " and " .. Multi5.Name .. " your christmastree is under fire take care you will loose the game if he gets destroyed!", "Santa Clause", White)
		Camera.Position = Bottomtree.CenterPosition
		Beacon.New(Multi3, Bottomtree.CenterPosition, 500, true)
	end
	if BottomTreehealth < 50 and not bottomtrigger50 then
		bottomtrigger50 = true
		Media.DisplayMessage("The southern christmastree is under heavy fire!", "Santa Clause", White)
	end
end

Team1Won = function()
	Team1WonTheGame= true
	if not Team2WonTheGame then
		Cam1 = Actor.Create("merry", true, { Location = (CPos.New(39,46)), Owner = Neutral })
		Cam2 = Actor.Create("xmass", true, { Location = (CPos.New(39,53)), Owner = Neutral })
		Cam1 = Actor.Create("camera", true, { Location = (CPos.New(39,50)), Owner = Multi0 })
		Cam2 = Actor.Create("camera", true, { Location = (CPos.New(39,50)), Owner = Multi3 })
		Camera.Position = Cam1.CenterPosition
		Media.DisplayMessage("Congratulations\n" .. Multi0.Name .. ", " .. Multi1.Name .. " and " .. Multi2.Name .. "\nBurned the enemys christmastree!", "Santa Clause", White)
		Trigger.AfterDelay(DateTime.Seconds(5), function()
			if Player.GetPlayer("Multi0") ~= nil then
				Multi0.MarkCompletedObjective(BurnTree1)
			end
			if Player.GetPlayer("Multi1") ~= nil then
				Multi1.MarkCompletedObjective(BurnTree1)
			end
			if Player.GetPlayer("Multi2") ~= nil then
				Multi2.MarkCompletedObjective(BurnTree1)
			end
			if Player.GetPlayer("Multi3") ~= nil then
				Multi3.MarkFailedObjective(BurnTree2)
			end
			if Player.GetPlayer("Multi4") ~= nil then
				Multi4.MarkFailedObjective(BurnTree2)
			end
			if Player.GetPlayer("Multi5") ~= nil then
				Multi5.MarkFailedObjective(BurnTree2)
			end
		end)
	end
end
Team2Won = function()
	Team2WonTheGame= true
	if not Team1WonTheGame then
		Cam1 = Actor.Create("merry", true, { Location = (CPos.New(39,46)), Owner = Neutral })
		Cam2 = Actor.Create("xmass", true, { Location = (CPos.New(39,53)), Owner = Neutral })
		Cam1 = Actor.Create("camera", true, { Location = (CPos.New(39,50)), Owner = Multi0 })
		Cam2 = Actor.Create("camera", true, { Location = (CPos.New(39,50)), Owner = Multi3 })
		Camera.Position = Cam1.CenterPosition
		Media.DisplayMessage("Congratulations\n" .. Multi3.Name .. ", " .. Multi4.Name .. " and " .. Multi5.Name .. "\nBurned the enemys christmastree!", "Santa Clause", White)
		Trigger.AfterDelay(DateTime.Seconds(5), function()
			if Player.GetPlayer("Multi5") ~= nil then
				Multi5.MarkCompletedObjective(BurnTree2)
			end
			if Player.GetPlayer("Multi4") ~= nil then
				Multi4.MarkCompletedObjective(BurnTree2)
			end
			if Player.GetPlayer("Multi3") ~= nil then
				Multi3.MarkCompletedObjective(BurnTree2)
			end
			if Player.GetPlayer("Multi2") ~= nil then
				Multi2.MarkFailedObjective(BurnTree1)
			end
			if Player.GetPlayer("Multi1") ~= nil then
				Multi1.MarkFailedObjective(BurnTree1)
			end
			if Player.GetPlayer("Multi0") ~= nil then
				Multi0.MarkFailedObjective(BurnTree1)
			end
		end)
	end
end

SetupPlayers = function()
	Neutral = Player.GetPlayer("Neutral")
	Creeps = Player.GetPlayer("Creeps")
	Multi0 = Player.GetPlayer("Multi0")
	if Multi0 == nil then
		Multi0 = Player.GetPlayer("Multi1")
		if Multi0 == nil then
			Multi0 = Player.GetPlayer("Multi2")
			if Multi0 == nil then
				Multi0 = Player.GetPlayer("Neutral")
			end
		end
	end
	Multi1 = Player.GetPlayer("Multi1")
	if Multi1 == nil then
		Multi1 = Player.GetPlayer("Multi0")
		if Multi1 == nil then
			Multi1 = Player.GetPlayer("Multi2")
			if Multi1 == nil then
				Multi1 = Player.GetPlayer("Neutral")
			end
		end
	end
	Multi2 = Player.GetPlayer("Multi2")
	if Multi2 == nil then
		Multi2 = Player.GetPlayer("Multi0")
		if Multi2 == nil then
			Multi2 = Player.GetPlayer("Multi1")
			if Multi2 == nil then
				Multi2 = Player.GetPlayer("Neutral")
			end
		end
	end
	Multi3  = Player.GetPlayer("Multi3")
	if Multi3  == nil then
		Multi3  = Player.GetPlayer("Multi4")
		if Multi3  == nil then
			Multi3  = Player.GetPlayer("Multi5")
			if Multi3  == nil then
				Multi3  = Player.GetPlayer("Neutral")
			end
		end
	end
	Multi4  = Player.GetPlayer("Multi4")
	if Multi4  == nil then
		Multi4  = Player.GetPlayer("Multi3")
		if Multi4  == nil then
			Multi4  = Player.GetPlayer("Multi5")
			if Multi4  == nil then
				Multi4  = Player.GetPlayer("Neutral")
			end
		end
	end
	Multi5 = Player.GetPlayer("Multi5")
	if Multi5 == nil then
		Multi5 = Player.GetPlayer("Multi3")
		if Multi5 == nil then
			Multi5 = Player.GetPlayer("Multi4 ")
			if Multi5 == nil then
				Multi5 = Player.GetPlayer("Neutral")
			end
		end
	end
	Humans = { Multi0, Multi1, Multi2, Multi3, Multi4, Multi5, Multi6, Multi7, Multi8, Multi9 }
end

FirstFlagMessage = { "'s first flag has been captured he has still 2 more!", " lost the first of his 3 flags all fine for now!", " one of yor flags has been captured but you still got 2 remaining flags now!", " better take care of your flags 2 more captured and you will die!", " do you see what he's doing with your flag? Better make something", " its all fine you still got 2 more flags ...", " better dont be so sloppy one of your flags is lost!", " 1/3 flags are destroyed!", " 1/3 has been captured!", " 1/3 flags has been captured!", " 1 of 3 flags is lost!", " 1/3 flags are destroyed!", " 1/3 has been captured!", " 1/3 flags has been captured!", " 1 of 3 flags is lost!", " 1/3 flags are destroyed!", " 1/3 has been captured!", " 1/3 flags has been captured!", " 1 of 3 flags is lost!" }
SecondFlagMessage = { " The RED ALERT is for you, only 1 flag left!", " what are you doing? dont let them steal your flags only 1 remaining flag now!", " dont get frighten but you only have 1 flag over now!", " you seem to be a bit lame today or why do you let the other player steal your flags?", " 2 of 3 flags burned!", " 2/3 flags captured!", " has only 1 remaining flag!", " let them steal one more flag and you loose!", " 2 of 3 flags burned!", " 2/3 flags captured!", " has only 1 remaining flag!", " let them steal one more flag and you loose!", " do you smell the death?", " 2 of 3 flags burned!", " 2/3 flags got captured!", " has only 1 remaining flag!", " better you dont let them steal your last flag!", " 2 of 3 flags burned!", " 2/3 flags captured!", " has only 1 remaining flag!" }
Year = 2020
Cratesmode = Map.LobbyOption("crates")
Antz = Map.LobbyOption("ants")
Mode = Map.LobbyOption("ctf")
Season = Map.LobbyOption("season")
White = HSLColor.Red
RedLight = 1
BlueLight = 1
GreenLight = 1
AlertStarts = false
AlreadyAlert = false
RedCounter = 0
Warningalert = function()
	Lighting.Blue = BlueLight
	Lighting.Green = GreenLight
	if not AlertStarts then
		GettingRed = true
		Media.PlaySoundNotification( allplayers, "AlertBuzzer")
	end
	if BlueLight >= 0.35 and GettingRed then
		AlertStarts = true
		BlueLight = BlueLight - 0.05
		GreenLight = GreenLight - 0.05
		RedCounter = RedCounter + 1
		Trigger.AfterDelay(1, function()
			Warningalert()
		end)
	elseif RedCounter >= 1 then
		BlueLight = BlueLight + 0.05
		GreenLight = GreenLight + 0.05
		GettingRed = false
		RedCounter = RedCounter - 1
		Trigger.AfterDelay(1, function()
			Warningalert()
		end)
	end
end

--																 Flagfunctions

GetandsetFlagsRepeater = function()
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		FuseFlag1Cell()
		FuseFlag2Cells()
		if Mode ~= "temprasphere" then
			FuseFlag7Cells()
		end
		GetandsetFlagsRepeater()
	end)
end

FuseFlag1Cell = function()
	Utils.Do(Humans, function(player)
		local flagactors = player.GetActorsByType("ctflag")
		for p,flag in pairs(flagactors) do
			if not flag.HasTag("isfused1") then
				flag.AddTag("isfused1")
				Trigger.OnEnteredProximityTrigger(flag.CenterPosition, WDist.FromCells(1), function(a, id)
					local mine = flag.Owner
					local yours = a.Owner
					if a.HasTag("flagholdingunit") and mine == yours then
						a.Stop()
						a.Kill()
					elseif mine ~= yours and a.Type == "tflag" and mine.IsAlliedWith(yours) == true then
						NewPositionFlag = Actor.Create("ctflag", true, { Location = a.Location + CVec.New(Utils.RandomInteger(-1, 2), 1), Owner = yours })
						a.Destroy()
					elseif mine ~= yours and a.Type ~= "mcv" and a.Type ~= "truk" and a.Type ~= "ctfmcv" and a.Type ~= "dpctflag" and a.HasProperty("GrantCondition") and a.AcceptsCondition("flagholder") and not a.HasTag("flagholdingunit") then
						if Mode ~= "temprasphere" and mine.IsAlliedWith(yours) == true then
							return
						else
							Trigger.RemoveProximityTrigger(id)
							if mine.IsLocalPlayer then
								SetCamera(mine)
							end
							Beacon.New(mine, a.CenterPosition, 100, true)
							a.AddTag("flagholdingunit")
							a.GrantCondition("flagholder", 0)
							a.GrantCondition("hold" .. mine.InternalName .. "flag", 0)
							if Mode ~= "hawkie" then
								if DateTime.GameTime < DateTime.Minutes(5) then
									a.GrantCondition("snailspeed", 0)
								elseif DateTime.GameTime < DateTime.Minutes(7) then
									a.GrantCondition("turtlespeed", 0)
								else
									a.GrantCondition("frogspeed", 0)
								end
							end
							flag.Destroy()
							Trigger.OnKilled(a, function()
								Flag = Actor.Create("tflag", true, { Location = a.Location, Owner = mine })
							end)
						end
					end
				end)
			end
		end
	end)
end

FuseFlag2Cells = function()
	Utils.Do(Humans, function(player)
		local flagactors = player.GetActorsByType("ctflag")
		for p,flag in pairs(flagactors) do
			if not flag.HasTag("isfused2") then
				flag.AddTag("isfused2")
				Trigger.OnEnteredProximityTrigger(flag.CenterPosition, WDist.FromCells(2), function(a, id)
					local mine = flag.Owner
					local yours = a.Owner
					if flag.IsDead then
						Trigger.RemoveProximityTrigger(id)
						return
					end
					if Mode ~= "temprasphere" then
						if a.Type == "sbag" or a.Type == "fenc" then
							yours.Cash = yours.Cash + 10
							Media.FloatingText("10 $", a.CenterPosition, 40, yours.Color)
							a.Destroy()
						end
					end
					if a.Type == "tflag" and mine.IsAlliedWith(yours) ~= true then
						if Mode ~= "hawkie" then
							Media.DisplayMessage("" .. mine.Name .. " captured " .. yours.Name .. "s flag!", "Santa Clause", White)
						end
						DeadplayersFlag = Actor.Create("dpctflag", true, { Location = a.Location + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(0, 2)), Owner = yours })
						Media.FloatingText("+ " .. (mine.Experience/2) .. " Exp Bonus", flag.CenterPosition, 85, mine.Color)
						mine.Experience = mine.Experience + mine.Experience/2
						a.Destroy()
						Trigger.AfterDelay(DateTime.Seconds(1), function()
							if Mode == "hawkie" then
								Lives = yours.GetActorsByTypes({"live1", "live2"})
								for i,v in pairs(Lives) do
									if v.Type == "live1" then
										RandomMessage = Utils.Random(FirstFlagMessage)
										Newflag = Actor.Create("ctflag", true, { Location = v.Location + CVec.New(1, 3), Owner = yours })
										Media.DisplayMessage("" .. yours.Name .. "" .. RandomMessage .. "", "Santa Clause", White)
										v.Destroy()
										return
									elseif v.Type == "live2" then
										RandomMessage = Utils.Random(SecondFlagMessage)
										Newflag = Actor.Create("ctflag", true, { Location = v.Location + CVec.New(-1, 3), Owner = yours })
										Media.DisplayMessage("" .. yours.Name .. "" .. RandomMessage .. "", "Santa Clause", White)
										v.Destroy()
										if not AlreadyAlert then
											AlreadyAlert = true
											Warningalert()
										end
										Trigger.AfterDelay(DateTime.Seconds(5), function()
											AlreadyAlert = false
											AlertStarts = false
										end)
										return
									end
								end
							end
							allactors = yours.GetActors()
							for i,v in pairs(allactors) do
								if v.HasProperty("Health") and v.Type ~= "dpctflag" and v.Type ~= "ctree" then
									v.Stop()
									v.Kill()
								end
							end
						end)
					end
				end)
			end
		end
	end)
end

FuseFlag7Cells = function()
	Utils.Do(Humans, function(player)
		local flagactors = player.GetActorsByType("ctflag")
		for p,flag in pairs(flagactors) do
			if not flag.HasTag("isfused3") then
				flag.AddTag("isfused3")
				Trigger.OnEnteredProximityTrigger(flag.CenterPosition, WDist.FromCells(7), function(a, id)
					if flag.IsDead then
						Trigger.RemoveProximityTrigger(id)
						return
					elseif a.Type == "brik" and a.Owner ~= Neutral then
						local yours = a.Owner
						yours.Cash = yours.Cash + 15
						Media.FloatingText("15 $", a.CenterPosition, 40, yours.Color)
						a.Destroy()
					end
				end)
			end
		end
	end)
end
SetCamera = function(Multi)
	local PlayerFlag = Multi.GetActorsByType("ctflag")[1]
	if PlayerFlag ~= nil then
		Camera.Position = PlayerFlag.CenterPosition
	end
end
StartingUnitsCheck = function()
	Utils.Do(Humans, function(player)
		MCV = player.GetActorsByType("mcv")
		for p,mobcon in pairs(MCV) do
			if Mode ~= "hawkie" then
				CTFMCV = Actor.Create("ctfmcv", true, { Location = mobcon.Location, Owner = mobcon.Owner, Facing = 125  })
				CTFMCV.GrantCondition("frogspeed", 0)
			else
				CTFMCV = Actor.Create("ct3fmcv", true, { Location = mobcon.Location, Owner = mobcon.Owner, Facing = 125  })
			end
			CTFMCV.GrantCondition("flagholder", 0)
			CTFMCV.GrantCondition("hold" .. CTFMCV.Owner.InternalName .. "flag", 0)
			if CTFMCV.Owner.IsBot then
				CTFMCV.Deploy()
			end
			mobcon.Destroy()
		end
	end)
end

FlagNotifications = function()

	Trigger.AfterDelay(DateTime.Seconds(3), function()

		Trigger.AfterDelay(DateTime.Seconds(3), function()
			if Mode == "hawkie" then
				Media.DisplayMessage("The 3 flagsmode has been chosen in gamelobby.\nEach player has 3 flags but only 1 can be stolen at a time.", "Santa Clause", White)

			elseif Mode ~= "noctf" then
				Media.DisplayMessage("Capture the enemys flag with any vehicle and bring it to your own flag to defeat him!", "Santa Clause", White)
			end
			Trigger.AfterDelay(DateTime.Seconds(7), function()
				if Mode == "hawkie" then
					Media.DisplayMessage("there are no speedlimitation for the flagholding unit except of chronotanks\n\nMCV and supply trucks cant steal flags.", "Santa Clause", White)
				elseif Mode ~= "noctf" then
					Media.DisplayMessage("The speed of vehicles wich carry the flag will be reduced!\n\nIf it is destroyed it will throw the flag to the ground!", "Santa Clause", White)
				end
				Trigger.AfterDelay(DateTime.Seconds(7), function()
					if Mode ~= "hawkie" and Mode ~= "noctf" then Media.DisplayMessage("Iron curtain and chronosphere doesnt work for the flagholding unit!", "Santa Clause", White) end
					Trigger.AfterDelay(DateTime.Seconds(6), function()
						if Mode == "materia" then
							Media.DisplayMessage("Mode 1 was set in Lobby, that means no concrete walls can be build in the rangecircle around the flag and teammates cant take your flag.", "Santa Clause", White)
						elseif Mode == "temprasphere" then
							Media.DisplayMessage("Mode 2 was set in Lobby, that means there are no buildrestrictions for walls and teammates can carry your flag.", "Santa Clause", White)
						elseif Mode ~= "noctf" then
							Media.DisplayMessage("Concrete walls can not be build around your flag in a 7 cell radius and teammates cant take your flag.", "Santa Clause", White)
						end
					end)
				end)
			end)
		end)
	end)
end
--																 Antfunctions
Antzcontrol = function()
	if Antz == "biolabs" or Antz == "noants" then
		bios = Neutral.GetActorsByType("bio")
		for p,biolabs in pairs(bios) do
			biolabs.Destroy()
		end
		brik = Neutral.GetActorsByType("brik")
		for p,wall in pairs(brik) do
			wall.Destroy()
		end
	else
		Trigger.AfterDelay(DateTime.Seconds(45), function()
			Media.DisplayMessage("Biolabs are activated\nYou can build some new ants just click on the biolab to produce them there!", "Santa Clause", White)
		end)
	end
	if Antz == "anthills" or Antz == "noants" then
		queens = Creeps.GetActorsByType("queen")
		for p,queen in pairs(queens) do
			queen.Destroy()
		end
		larva1 = Creeps.GetActorsByType("lar1")
		for p,l1 in pairs(larva1) do
			l1.Destroy()
		end
		larva2 = Creeps.GetActorsByType("lar2")
		for p,l2 in pairs(larva2) do
			l2.Destroy()
		end
		toxant = Creeps.GetActorsByType("toxicant")
		for p,tant in pairs(toxant) do
			tant.Destroy()
		end
		scoutant = Creeps.GetActorsByType("scoutant")
		for p,scout in pairs(scoutant) do
			scout.Destroy()
		end
		electricant = Creeps.GetActorsByType("electricant")
		for p,ele in pairs(electricant) do
			ele.Destroy()
		end
		lavaant = Creeps.GetActorsByType("lavaant")
		for p,lava in pairs(lavaant) do
			lava.Destroy()
		end
	else
		Trigger.AfterDelay(DateTime.Seconds(53), function()
			Media.DisplayMessage("Beware there must be a hidden anthill somewhere,\nsome strange things are going on out there!", "Santa Clause", White)
		end)
	end
	if Antz == "bothon" or Antz == "biolabs" then
		AntConditions()
	end
	if Antz ~= "noants" then
		BurningConditioner()
	end
end

AntConditions = function()
	AntDelayTimemin = 44
	AntDelayTimemax = 50
	Trigger.AfterDelay(DateTime.Minutes(1), function()
		EnemyAntUnit = { "ant", "scoutant" }
		EnemyAntIncome()
	end)
	Trigger.AfterDelay(DateTime.Minutes(2), function()
		EnemyAntUnit = { "ant", "scoutant", "warriorant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(3), function()
		AntDelayTimemin = 40
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(4), function()
		AntDelayTimemin = 30
	end)
	Trigger.AfterDelay(DateTime.Minutes(5), function()
		AntDelayTimemin = 20
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant", "toxicant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(6), function()
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant", "toxicant", "electricant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(7), function()
		AntDelayTimemin = 16
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant", "toxicant", "electricant", "fireant", "toxicant", "electricant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(8), function()
		AntDelayTimemin = 13
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant", "toxicant", "electricant", "fireant", "toxicant", "electricant", "lavaant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(9), function()
		AntDelayTimemin = 10
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant", "toxicant", "electricant", "fireant", "toxicant", "electricant", "lavaant", "lavaant" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(10), function()
		AntDelayTimemin = 7
		EnemyAntUnit = { "ant", "scoutant", "warriorant", "fireant", "toxicant", "electricant", "fireant", "toxicant", "toxicant", "electricant", "electricant", "lavaant", "lavaant" }
	end)
end
EnemyAntPath = { CPos.New(150,55), CPos.New(155,5), CPos.New(27,77) }
EnemyAntIncome = function()
	if not Actor567.IsDead then
		RandomAntWalk1 = Utils.Random(EnemyAntPath)
		RandomAntWalk2 = Utils.Random(EnemyAntPath)
		AttackpathN = { CPos.New(100,40) + CVec.New(Utils.RandomInteger(0, 2), Utils.RandomInteger(0, 2)), RandomAntWalk1, RandomAntWalk2 }
		RandomAntUnit = Utils.Random(EnemyAntUnit)
		if RandomAntUnit == "ant" then AntDelayTimemax = 66
		elseif RandomAntUnit == "scoutant" then AntDelayTimemax = 60
		elseif RandomAntUnit == "warriorant" then AntDelayTimemax = 70
		elseif RandomAntUnit == "fireant" then AntDelayTimemax = 72
		elseif RandomAntUnit == "toxicant" then AntDelayTimemax = 76
		elseif RandomAntUnit == "electricant" then AntDelayTimemax = 78
		elseif RandomAntUnit == "lavaant" then AntDelayTimemax = 82 end
		EnemyUnitN = Actor.Create(RandomAntUnit, true, { Location = Actor567.Location + CVec.New(2, 2), Owner = Creeps })
		EnemyN = { EnemyUnitN }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(AntDelayTimemin, AntDelayTimemax)), function()
			EnemyAntIncome()
		end)
	end)
end
BurningConditioner = function()
	fireantz = Creeps.GetActorsByType("fireant")
	for p,fireants in pairs(fireantz) do
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
			if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
		end)
	end
	lavaantz = Creeps.GetActorsByType("lavaant")
	for p,lavaants in pairs(lavaantz) do
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
			if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
		end)
	end
	if Multi0 ~= nil then
		fireantz = Multi0.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi0.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi1 ~= nil then
		fireantz = Multi1.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi1.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi2 ~= nil then
		fireantz = Multi2.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi2.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()

				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi3 ~= nil then
		fireantz = Multi3.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi3.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi4 ~= nil then
		fireantz = Multi4.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi4.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi5 ~= nil then
		fireantz = Multi5.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi5.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi6 ~= nil then
		fireantz = Multi6.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi6.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi7 ~= nil then
		fireantz = Multi7.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi7.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi8 ~= nil then
		fireantz = Multi8.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi8.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	if Multi9 ~= nil then
		fireantz = Multi9.GetActorsByType("fireant")
		for p,fireants in pairs(fireantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if fireants.IsInWorld then fireants.GrantCondition("fireon", Utils.RandomInteger(143, 185)) end
			end)
		end
		lavaantz = Multi9.GetActorsByType("lavaant")
		for p,lavaants in pairs(lavaantz) do
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 15)), function()
				if lavaants.IsInWorld then lavaants.GrantCondition("fireon", Utils.RandomInteger(160, 235)) end
			end)
		end
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(18, 25)), function()
		BurningConditioner()
	end)
end
GroupPatrol = function(units, waypoints, delay)
	local i = 1
	local stop = false
	Utils.Do(units, function(unit)
		Trigger.OnIdle(unit, function()
			if stop then
				return
			end
			if unit.Location == waypoints[i] then
				local bool = Utils.All(units, function(actor) return actor.IsIdle end)
				if bool then
					stop = true
					i = i + 1
					if i > #waypoints then
						i = 1
					end
					Trigger.AfterDelay(delay, function() stop = false end)
				end
			else
				unit.AttackMove(waypoints[i])
			end
		end)
	end)
end
--																 Cratefunctions
Cratecontrol = function()
	Trigger.AfterDelay(DateTime.Seconds(210), function()
		Sendnormalcrate()
	end)
	if Cratesmode ~= "normalcrates" then
		Trigger.AfterDelay(DateTime.Seconds(360), function()
			Sendspecialcrate()
			if not AlreadyAlert then
				AlreadyAlert = true
				Warningalert()
			end
			Trigger.AfterDelay(DateTime.Seconds(5), function()
				AlreadyAlert = false
				AlertStarts = false
			end)
			Media.DisplayMessage("More Presents for you!", "Santa Clause", White)
		end)
		if Cratesmode == "supercrates" then
			Trigger.AfterDelay(DateTime.Seconds(600), function()
				Sendsupercrate()
				if not AlreadyAlert then
					AlreadyAlert = true
					Warningalert()
				end
				Trigger.AfterDelay(DateTime.Seconds(5), function()
					AlreadyAlert = false
					AlertStarts = false
				end)
				Media.DisplayMessage("Hold on, someone called for Superpresents!?!", "Santa Clause", HSLColor.Blue)
			end)
		end
	end
end

Sendnormalcrate = function()
	DetonationPoint = Actor.Create("waypoint", true, { Location = Map.RandomCell(), Owner = Neutral })
	ParaProxy = Actor.Create("powerproxy.normalcrate", false, { Owner = Neutral })
	crates = ParaProxy.SendParatroopers(DetonationPoint.CenterPosition)
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(14, 36)), function()
		Sendnormalcrate()
	end)
end

Sendspecialcrate = function()
	DetonationPoint = Actor.Create("waypoint", true, { Location = Map.RandomCell(), Owner = Neutral })
	ParaProxy = Actor.Create("powerproxy.specialcrate", false, { Owner = Neutral })
	crates = ParaProxy.SendParatroopers(DetonationPoint.CenterPosition)
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(15, 50)), function()
		Sendspecialcrate()
	end)
end

Sendsupercrate = function()
	DetonationPoint = Actor.Create("waypoint", true, { Location = Map.RandomCell(), Owner = Neutral })
	ParaProxy = Actor.Create("powerproxy.supercrate", false, { Owner = Neutral })
	crates = ParaProxy.SendParatroopers(DetonationPoint.CenterPosition)
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(20, 50)), function()
		Sendsupercrate()
	end)
end

--																 Weatherfunctions

InitialiseWeather = function()
	if Season == "spring" then
		Month = 3
		Light = 0.91
		RedLight = 0.95
		GreenLight = 1.07
		BlueLight = 1.07
	elseif Season == "summer" then
		Month = 6
		Light = 0.93
		RedLight = 1.09
		GreenLight = 0.94
		BlueLight = 0.97
	elseif Season == "fall" or Season == "defmode" then
		Month = 9
		Light = 0.89
		RedLight = 1.05
		GreenLight = 0.93
		BlueLight = 1.04
	elseif Season == "winter"then
		Month = 12
		Light = 0.92
		RedLight = 1.03
		GreenLight = 1.07
		BlueLight = 1.08
	end
	ColorChangeSpeed = 18
	MonthConditions()
	ColorChanger()
	turnOn()
end
Season = Map.LobbyOption("season")
RateOfIncrease = 0.001


MonthConditions = function()
	if Month == 1 then
		BrightnessChangeSpeed = 7
		ColorChangeSpeed = 16
		BrightestLight = 0.92
		DarkestLight = 0.55
		DayDuration = 5000
		NightDuration = 6000
		DesiredRed = 1
		DesiredGreen = 1
		DesiredBlue = 1
		MonthName = "Januar"
		ThunderRiskfactor = { 1, 2, 3 }
		TimerColor = HSLColor.Cyan
	elseif Month == 2 then
		Firstyear = true
		BrightnessChangeSpeed = 8
		ColorChangeSpeed = 18
		BrightestLight = 0.94
		DarkestLight = 0.58
		DayDuration = 5400
		NightDuration = 5500
		DesiredRed = 1.15
		DesiredGreen = 0.91
		DesiredBlue = 1.18
		MonthName = "Februar"
		ThunderRiskfactor = { 1, 2, 3 }
		TimerColor = HSLColor.Blue
--												Spring
	elseif Month == 3 then
		BrightnessChangeSpeed = 9
		ColorChangeSpeed = 20
		BrightestLight = 0.96
		DarkestLight = 0.60
		DayDuration = 5800
		NightDuration = 5000
		DesiredRed = 0.97
		DesiredGreen = 1.10
		DesiredBlue = 1.05
		MonthName = "Maerz"
		ThunderRiskfactor = { 1, 2, 3 }
		TimerColor = HSLColor.LawnGreen
	elseif Month == 4 then
		BrightnessChangeSpeed = 10
		ColorChangeSpeed = 22
		BrightestLight = 0.98
		DarkestLight = 0.62
		DayDuration = 6300
		NightDuration = 4900
		DesiredRed = 0.97
		DesiredGreen = 1.10
		DesiredBlue = 1.05
		MonthName = "April"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 11, 12, 13 }
		TimerColor = HSLColor.Green
	elseif Month == 5 then
		BrightnessChangeSpeed = 11
		ColorChangeSpeed = 25
		BrightestLight = 1.0
		DarkestLight = 0.65
		DayDuration = 6800
		NightDuration = 4300
		DesiredRed = 0.97
		DesiredGreen = 1.10
		DesiredBlue = 1.05
		MonthName = "Mai"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13 }
		TimerColor = HSLColor.LimeGreen
--												Summer
	elseif Month == 6 then
		BrightnessChangeSpeed = 12
		ColorChangeSpeed = 28
		BrightestLight = 1.03
		DarkestLight = 0.68
		DayDuration = 7300
		NightDuration = 3700
		DesiredRed = 1.15
		DesiredGreen = 1.15
		DesiredBlue = 0.95
		MonthName = "Juni"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 12, 13 }
		TimerColor = HSLColor.LightYellow
	elseif Month == 7 then
		BrightnessChangeSpeed = 12
		ColorChangeSpeed = 26
		BrightestLight = 1.03
		DarkestLight = 0.68
		DayDuration = 7300
		NightDuration = 3700
		DesiredRed = 1.17
		DesiredGreen = 1.17
		DesiredBlue = 0.94
		MonthName = "Juli"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 12, 13 }
		TimerColor = HSLColor.Gold
	elseif Month == 8 then
		BrightnessChangeSpeed = 11
		ColorChangeSpeed = 24
		BrightestLight = 1.0
		DarkestLight = 0.65
		DayDuration = 6800
		NightDuration = 4300
		DesiredRed = 1.13
		DesiredGreen = 1.1
		DesiredBlue = 0.93
		MonthName = "August"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13 }
		TimerColor = HSLColor.DarkRed
--												Fall
	elseif Month == 9 then
		BrightnessChangeSpeed = 10
		ColorChangeSpeed = 22
		BrightestLight = 0.98
		DarkestLight = 0.62
		DayDuration = 6300
		NightDuration = 4900
		DesiredRed = 1.08
		DesiredGreen = 1.03
		DesiredBlue = 0.94
		MonthName = "September"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }
		TimerColor = HSLColor.DarkOrange
	elseif Month == 10 then
		BrightnessChangeSpeed = 9
		ColorChangeSpeed = 20
		BrightestLight = 0.96
		DarkestLight = 0.60
		DayDuration = 5800
		NightDuration = 5000
		DesiredRed = 1.13
		DesiredGreen = 1
		DesiredBlue = 0.97
		MonthName = "Oktober"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13 }
		TimerColor = HSLColor.DarkGray
	elseif Month == 11 then
		BrightnessChangeSpeed = 8
		ColorChangeSpeed = 18
		BrightestLight = 0.94
		DarkestLight = 0.58
		DayDuration = 5400
		NightDuration = 5500
		DesiredRed = 1.14
		DesiredGreen = 0.97
		DesiredBlue = 1.04
		MonthName = "November"
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
		TimerColor = HSLColor.DarkGray
--								Winter
	elseif Month == 12 then
		BrightnessChangeSpeed = 8
		ColorChangeSpeed = 12
		BrightestLight = 0.99
		DarkestLight = 0.54
		DayDuration = 5000
		NightDuration = 6000
		DesiredRed = 1.01
		DesiredGreen = 0.98
		DesiredBlue = 1.02
		MonthName = "Dezember"
		ThunderRiskfactor = { 1, 2, 3 }
		TimerColor = HSLColor.White
	end
	Trigger.AfterDelay(5, function()
		Month = Month + 1
		if Month == 13 then
			Month = 1
			Year = Year + 1  -- Happy new year :D
		end
	end)
end

ColorChanger = function()
	if RedLight < DesiredRed then
		RedLight = RedLight + 0.001
	elseif RedLight > DesiredRed then
		RedLight = RedLight - 0.001
	end
	if GreenLight < DesiredGreen then
		GreenLight = GreenLight + 0.001
	elseif GreenLight > DesiredGreen then
		GreenLight = GreenLight - 0.001
	end
	if BlueLight < DesiredBlue then
		BlueLight = BlueLight + 0.001
	elseif BlueLight > DesiredBlue then
		BlueLight = BlueLight - 0.001
	end
	Lighting.Red = RedLight
	Lighting.Green = GreenLight
	Lighting.Blue = BlueLight
	Trigger.AfterDelay(ColorChangeSpeed, function()
		ColorChanger()
	end)
end

turnOn = function()
	Lighting.Ambient = Light
	if Light < 0.794 and Light > 0.793 then
		GettingDark = false
		POWER.Destroy()
		Trigger.AfterDelay(100, function()
			PlayMusic()
		end)
	end
	if Light < BrightestLight then
		Light = Light + RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			turnOn()
		end)

	else
		NoturnOn = true
		Trigger.AfterDelay(DayDuration, function()
			turnOff()
		end)
	end
end

turnOff = function()
	if Light < 0.734 and Light > 0.733 then
		DesiredRed = 0.93
		DesiredGreen = 1.07
		DesiredBlue = 1.13
	end
	if Light < 0.734 and Light > 0.733 then
		GettingDark = true
		POWER = Actor.Create("dummypower", true, { Location = CPos.New(0,0), Owner = Neutral })
		Trigger.AfterDelay(350, function()
			PlayMusic()
		end)
	end
	if Light < 0.691 and Light > 0.690 then
		ThunderManager()
	end
	if Light > DarkestLight then
		Light = Light - RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			turnOff()
		end)
	else
		Trigger.AfterDelay(NightDuration, function()
			NoturnOn = false
			Thunderstorm = false
			MonthConditions()
			turnOn()
		end)
	end
	Lighting.Ambient = Light
end

ThunderManager = function()
	ThunderstormRisk = Utils.Random(ThunderRiskfactor)
	if ThunderstormRisk == 11 then
		SmoothThunderstorm = true
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(45, 65)), function()
			SmoothThunderstorm = false
		end)
	elseif ThunderstormRisk == 12 then
		SmoothThunderstorm = true
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(15, 30)), function()
			SmoothThunderstorm = false
			NormalThunderstorm = true
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(30, 60)), function()
				NormalThunderstorm = false
				SmoothThunderstorm = true
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(15, 30)), function()
					SmoothThunderstorm = false
				end)
			end)
		end)
	elseif ThunderstormRisk == 13 then
		SmoothThunderstorm = true
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(15, 30)), function()
			SmoothThunderstorm = false
			NormalThunderstorm = true
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(20, 30)), function()
				NormalThunderstorm = false
				HardThunderstorm = true
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(30, 60)), function()
					HardThunderstorm = false
					NormalThunderstorm = true
					Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(15, 30)), function()
						NormalThunderstorm = false
						SmoothThunderstorm = true
						Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(15, 30)), function()
							SmoothThunderstorm = false
						end)
					end)
				end)
			end)
		end)

	end
end

function WorldLoaded()
	SetupPlayers()
	Media.StopMusic()
	SetObjectiveandMakeTrees()
	if Mode ~= "noctf" then
		GetandsetFlagsRepeater()
		StartingUnitsCheck()
	end
	Trigger.AfterDelay(DateTime.Seconds(5), function()
		Media.DisplayMessage("Ho Ho Ho Merry X-Mass!", "Santa Clause", HSLColor.Red)
	end)
	Trigger.AfterDelay(DateTime.Seconds(10), function()
		Media.DisplayMessage("You can open the presents around your tree with harvesters!", "Santa Clause", HSLColor.Red)
		PlayMusic()
	end)
	Trigger.AfterDelay(DateTime.Seconds(15), function()
		Media.DisplayMessage("Protect the Xmass-Tree on your side, you will loose if he gets burned ! ! !", "Santa Clause", HSLColor.Red)
		FlagNotifications()
	end)

	Antzcontrol()
	if Cratesmode ~= "nocrates" then
		Cratecontrol()
	end
	if Season == "noweather" then
	else
		InitialiseWeather()
	end
end
CounterColor = HSLColor.White

Tick = function()
	if not Team1WonTheGame and not Team2WonTheGame then
		if Toptree.Health < 100000 or Bottomtree.Health < 100000 and not ColorisRed then
			ColorisRed = true
			CounterColor = HSLColor.Red
		end
		TopTreehealth = Toptree.Health / 5000
		BottomTreehealth = Bottomtree.Health / 5000
		UserInterface.SetMissionText("   Top X-masstree health: ".. TopTreehealth .. " %\n\n\nBottom X-masstree health: " .. BottomTreehealth .. " %", CounterColor)
	else
		UserInterface.SetMissionText("", CounterColor)
	end
	if SmoothThunderstorm then
		if (Utils.RandomInteger(1, 300) == 10) then
			local delay = Utils.RandomInteger(1, 10)
			Lighting.Flash("LightningStrike", delay)
			Trigger.AfterDelay(delay, function()
				Media.PlaySound("thunder" .. Utils.RandomInteger(1,10) .. ".aud")
			end)
		end
		if (Utils.RandomInteger(1, 250) == 10) then
			Media.PlaySound("thunder-ambient.aud")
		end
	elseif NormalThunderstorm then
		if (Utils.RandomInteger(1, 250) == 10) then
			local delay = Utils.RandomInteger(1, 10)
			Lighting.Flash("LightningStrike", delay)
			Trigger.AfterDelay(delay, function()
				Media.PlaySound("thunder" .. Utils.RandomInteger(1,10) .. ".aud")
			end)
		end
		if (Utils.RandomInteger(1, 225) == 10) then
			Media.PlaySound("thunder-ambient.aud")
		end
	elseif HardThunderstorm then
		if (Utils.RandomInteger(1, 200) == 10) then
			local delay = Utils.RandomInteger(1, 10)
			Lighting.Flash("LightningStrike", delay)
			Trigger.AfterDelay(delay, function()
				Media.PlaySound("thunder" .. Utils.RandomInteger(1,10) .. ".aud")
			end)
		end
		if (Utils.RandomInteger(1, 200) == 10) then

			Media.PlaySound("thunder-ambient.aud")
		end
	end
end

