
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")
Red = 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!", "Ursula von der Leyen", Red)
						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 .. "", "Ursula von der Leyen", Red)
										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 .. "", "Ursula von der Leyen", Red)
										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" 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()
	Media.DisplayMessage("Welcome this is the Commission President of the Eropean Union,\nFollow our rules and we will be friends!", "Ursula von der Leyen", Red)
	if Mode ~= "noctf" then
			GetandsetFlagsRepeater()
			StartingUnitsCheck()
	end
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		if Mode ~= "noctf" then
			GetandsetFlagsRepeater()
			StartingUnitsCheck()
		end
		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.", "Ursula von der Leyen", Red)

			elseif Mode ~= "noctf" then
				Media.DisplayMessage("Capture the enemys flag with any vehicle and bring it to your own flag to defeat him!", "Ursula von der Leyen", Red)
			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.", "Ursula von der Leyen", Red)
				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!", "Ursula von der Leyen", Red)
				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!", "Ursula von der Leyen", Red) 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.", "Ursula von der Leyen", Red)
						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.", "Ursula von der Leyen", Red)
						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.", "Ursula von der Leyen", Red)
						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(40), function()
			Media.DisplayMessage("Biolabs are activated\nYou can build some new Ants just click on the biolab to produce them there!", "Ursula von der Leyen", Red)
		end)
	end
	if Antz == "anthills" or Antz == "noants" then
		ahill = Creeps.GetActorsByType("anthill")
		for p,anthills in pairs(ahill) do
			anthills.Destroy()
		end
		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
	else
		Trigger.AfterDelay(DateTime.Seconds(66), function()
			Media.DisplayMessage("Beware . . .\nsome strange things are going on out there!", "Ursula von der Leyen", Red)
			Trigger.AfterDelay(DateTime.Seconds(4), function()
				Media.DisplayMessage("Sounds like some creepy crawling ... Things?!", "Ursula von der Leyen", Red)
			end)
		end)
	end
	if Antz == "bothon" or Antz == "biolabs" then
		Trigger.AfterDelay(DateTime.Minutes(1), function()
			AntConditions()
		end)
	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

EnemyAntIncome = function()
	if not Actor567.IsDead then
		AttackpathN = { CPos.New(165,146) + CVec.New(Utils.RandomInteger(0, 3), Utils.RandomInteger(0, 3)), CPos.New(198,13) + CVec.New(Utils.RandomInteger(0, 3), Utils.RandomInteger(0, 3)), CPos.New(13,130) + CVec.New(Utils.RandomInteger(0, 3), Utils.RandomInteger(0, 3)) }
		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("Okay guys it seems like the special crates will be dropped soon!", "Ursula von der Leyen", Red)
		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 supercrates!!", "Superman", 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.ActivateParatroopers(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.ActivateParatroopers(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.ActivateParatroopers(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
		StartingWinter()
		Month = 12
		Light = 0.88
		RedLight = 1.03
		GreenLight = 1.07
		BlueLight = 1.08
	end
	ColorChangeSpeed = 28
	MonthConditions()
	ColorChanger()
	if Month > 7 then
		turnOff()
	else
		turnOn()
	end
end
Season = Map.LobbyOption("season")
RateOfIncrease = 0.001

AllTrees = {"t03", "t10", "t11", "t12", "t13", "t14", "t15", "t17", "tc02", "tc05"}
AllNeedleTrees = {"t01", "t02", "t05", "t06", "t07", "t08", "t16", "tc01", "tc03", "tc04"}
AllBuildings = {"v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18"}
AllTNumbers = {"01", "02", "03", "04", "05", "06", "07", "08", "10", "11", "12", "13", "14", "15", "16", "17", "18"}
AllTCNumbers = {"01", "02", "03", "04", "05"}
AllVNumbers = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18"}
AllWinterStufft = {"t01winter", "t02winter", "t03winter", "t05winter", "t06winter", "t07winter", "t08winter", "t10winter", "t11winter", "t12winter", "t13winter", "t14winter", "t15winter", "t16winter", "t17winter"}
AllWinterStufftc = {"tc01winter", "tc02winter", "tc03winter", "tc04winter", "tc05winter"}
AllWinterStuffv = {"v01winter", "v02winter", "v03winter", "v04winter", "v05winter", "v06winter", "v07winter", "v08winter", "v09winter", "v10winter", "v11winter", "v12winter", "v13winter", "v14winter", "v15winter", "v16winter", "v17winter", "v18winter"}

AprilTrees = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 210)), function()
					if not tree.IsDead and tree.IsInWorld and tree.HasProperty("GrantCondition") and tree.AcceptsCondition("spring2") then
						tree.GrantCondition("spring2", 0)
					end
				end)
			end
		end
	end
end

MaiTrees = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 380)), function()
					if not tree.IsDead and tree.IsInWorld and tree.HasProperty("GrantCondition") and tree.AcceptsCondition("summer") then
						tree.GrantCondition("summer", 0)
					end
				end)
			end
		end
	end
end

SeptemberTrees = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 290)), function()
					if not tree.IsDead and tree.IsInWorld and tree.HasProperty("GrantCondition") and tree.AcceptsCondition("fall") then
						tree.GrantCondition("fall", 0)
					end
				end)
			end
		end
	end
end

OktoberTrees = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 320)), function()
					if not tree.IsDead and tree.IsInWorld and tree.HasProperty("GrantCondition") and tree.AcceptsCondition("fall2") then
						tree.GrantCondition("fall2", 0)
					end
				end)
			end
		end
	end
end

NovemberTrees = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 30)), function()
					if not tree.IsDead and tree.IsInWorld then
						Newtree = Actor.Create(tree.Type .. "winter" , true, { Location = tree.Location, Owner = Neutral })
						tree.Destroy()
					end
				end)
			end
		end
	end
end

StartingWinter = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				Newtree = Actor.Create(tree.Type .. "winter" , true, { Location = tree.Location, Owner = Neutral })
				tree.Destroy()
			end
		end
	end
	for i=1,#AllNeedleTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllNeedleTrees[i])
			for p,tree in pairs(Trees) do
				Newtree = Actor.Create(tree.Type .. "winter" , true, { Location = tree.Location, Owner = Neutral })
				tree.Destroy()
			end
		end
	end
	for i=1,#AllBuildings do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllBuildings[i])
			for p,tree in pairs(Trees) do
				Newtree = Actor.Create(tree.Type .. "winter" , true, { Location = tree.Location, Owner = Neutral })
				tree.Destroy()
			end
		end
	end
end

NeedleTrees = function()
	for i=1,#AllNeedleTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllNeedleTrees[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 30)), function()
					if not tree.IsDead and tree.IsInWorld then
						Newtree = Actor.Create(tree.Type .. "winter" , true, { Location = tree.Location, Owner = Neutral })
						tree.Destroy()
					end
				end)
			end
		end
	end
	for i=1,#AllBuildings do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllBuildings[i])
			for p,tree in pairs(Trees) do
				Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 30)), function()
					if not tree.IsDead and tree.IsInWorld then
						Newtree = Actor.Create(tree.Type .. "winter" , true, { Location = tree.Location, Owner = Neutral })
						tree.Destroy()
					end
				end)
			end
		end
	end
end

ChangeSpringTrees = function()
	for u=1,#AllWinterStufft do
		if u ~= nil then
			local Trees = Neutral.GetActorsByType(AllWinterStufft[u])
			for p,tree in pairs(Trees) do
				for i=1,#AllTNumbers do
					if tree.Type == "t0" .. i .. "winter" then
						Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 25)), function()
							if not tree.IsDead and tree.IsInWorld then
								Newtree = Actor.Create("t0" .. i .. "" , true, { Location = tree.Location, Owner = Neutral })
								if Newtree.HasProperty("GrantCondition") and Newtree.AcceptsCondition("spring") then
									Newtree.GrantCondition("spring", 0)
								end
								tree.Destroy()
							end
						end)
					elseif tree.Type == "t" .. i .. "winter" then
						Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 25)), function()
							if not tree.IsDead and tree.IsInWorld then
								Newtree = Actor.Create("t" .. i .. "" , true, { Location = tree.Location, Owner = Neutral })
								if Newtree.HasProperty("GrantCondition") and Newtree.AcceptsCondition("spring") then
									Newtree.GrantCondition("spring", 0)
								end
								tree.Destroy()
							end
						end)
					end
				end
			end
		end
	end
	for u=1,#AllWinterStufftc do
		if u ~= nil then
			local Trees = Neutral.GetActorsByType(AllWinterStufftc[u])
			for p,tree in pairs(Trees) do
				for i=1,#AllTCNumbers do
					if tree.Type == "tc0" .. i .. "winter" then
						Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 25)), function()
							if not tree.IsDead and tree.IsInWorld then
								Newtree = Actor.Create("tc0" .. i .. "" , true, { Location = tree.Location, Owner = Neutral })
								if Newtree.HasProperty("GrantCondition") and Newtree.AcceptsCondition("spring") then
									Newtree.GrantCondition("spring", 0)
								end
								tree.Destroy()
							end
						end)
					end
				end
			end
		end
	end
	for u=1,#AllWinterStuffv do
		if u ~= nil then
			local Trees = Neutral.GetActorsByType(AllWinterStuffv[u])
			for p,tree in pairs(Trees) do
				for i=1,#AllVNumbers do
					if tree.Type == "v" .. i .. "winter" then
						Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 25)), function()
							if not tree.IsDead and tree.IsInWorld then
								Newtree = Actor.Create("v" .. i .. "" , true, { Location = tree.Location, Owner = Neutral })
								tree.Destroy()
							end
						end)
					elseif tree.Type == "v0" .. i .. "winter" then
						Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1, 25)), function()
							if not tree.IsDead and tree.IsInWorld then
								Newtree = Actor.Create("v0" .. i .. "" , true, { Location = tree.Location, Owner = Neutral })
								tree.Destroy()
							end
						end)
					end
				end
			end
		end
	end
end


StartingSpringTrees = function()
	for i=1,#AllTrees do
		if i ~= nil then
			local Trees = Neutral.GetActorsByType(AllTrees[i])
			for p,tree in pairs(Trees) do
				if not tree.IsDead and tree.IsInWorld and tree.HasProperty("GrantCondition") and tree.AcceptsCondition("spring") then
					tree.GrantCondition("spring", 0)
				end
			end
		end
	end
end

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
		if not Firstyear then
			Firstyear = true
			StartingSpringTrees()
		else
			ChangeSpringTrees()
		end
		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"
		AprilTrees()
		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"
		MaiTrees()
		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"
		SeptemberTrees()
		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"
		OktoberTrees()
		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"
		NovemberTrees()
		ThunderRiskfactor = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
		TimerColor = HSLColor.DarkGray
--								Winter
	elseif Month == 12 then
		BrightnessChangeSpeed = 7
		ColorChangeSpeed = 15
		BrightestLight = 0.92
		DarkestLight = 0.55
		DayDuration = 5000
		NightDuration = 6000
		DesiredRed = 1.15
		DesiredGreen = 0.93
		DesiredBlue = 1.12
		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
		POWER.Destroy()
		Trigger.AfterDelay(100, function()
			Media.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()
			Media.StopMusic()
		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()
			if Month == 12 then
				NeedleTrees()
			end
			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

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

WorldLoaded = function()
	SetupPlayers()
	FlagNotifications()
	Antzcontrol()
	if Cratesmode ~= "nocrates" then
		Cratecontrol()
	end
	if Season == "noweather" then
	else
		InitialiseWeather()
	end
end

Tick = function()
	if Season == "defmode" then
		if SmoothThunderstorm then
			WeatherInfo = "SmoothThunderstorm"
		elseif NormalThunderstorm then
			WeatherInfo = "NormalThunderstorm"
		elseif HardThunderstorm then
			WeatherInfo = "HardThunderstorm"
		else
			WeatherInfo = "NoStorm"
		end
			UserInterface.SetMissionText("" .. MonthName .. " " .. (Year) .. "\nRed:" .. RedLight .. "     Green:" .. GreenLight .. "     Blue:" .. BlueLight .. "\nDesiredRed:" .. DesiredRed .. "     DesiredGreen:" .. DesiredGreen .. "     DesiredBlue:" .. DesiredBlue .. "\nLight:" .. Light .. "\n\n" .. WeatherInfo .. "", TimerColor)
	elseif Season ~= "noweather" then
		UserInterface.SetMissionText("" .. MonthName .. "   " .. (Year) .. "", TimerColor)

	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
