SetupPlayers = function()
	Neutral = Player.GetPlayer("Neutral")
	Multi0 = Player.GetPlayer("Multi0")
	if Multi0 == nil then
		Multi0 = Player.GetPlayer("Neutral")
	end
	Multi1 = Player.GetPlayer("Multi1")
	if Multi1 == nil then
		Multi1 = Player.GetPlayer("Neutral")
	end
	Multi2 = Player.GetPlayer("Multi2")
	if Multi2 == nil then
		Multi2 = Player.GetPlayer("Neutral")
	end
	Multi3 = Player.GetPlayer("Multi3")
	if Multi3 == nil then
		Multi3 = Player.GetPlayer("Neutral")
	end
end

Cratecontrol = function()
	Trigger.AfterDelay(DateTime.Seconds(55), function()
		Sendnormalcrate()
	end)
	Trigger.AfterDelay(DateTime.Seconds(330), function()
		Sendspecialcrate()
		Warningalert()
		Media.DisplayMessage("Okay guys it seems like the special crates will be dropped soon in mid!", "Materia", HSLColor.Red)
	end)
	Trigger.AfterDelay(DateTime.Seconds(530), function()
		Sendsupercrate()
		AlertStarts = false
		Warningalert()
		Media.DisplayMessage("Let the party begin the super crates get into the arena!", "Materia", HSLColor.Red)
	end)

end
AlertStarts = false
BlueLight = 1
GreenLight = 1

Warningalert = function()
	Lighting.Blue = BlueLight
	Lighting.Green = GreenLight
	if Lighting.Blue >= 1 and not AlertStarts then
		GettingRed = true
		Media.PlaySoundNotification( allplayers, "AlertBuzzer")
	end
	if BlueLight >= 0.2 and GettingRed then
		AlertStarts = true
		BlueLight = BlueLight - 0.05
		GreenLight = GreenLight - 0.05
		Trigger.AfterDelay(1, function()
			Warningalert()
		end)
	elseif BlueLight <= 1 then
		BlueLight = BlueLight + 0.05
		GreenLight = GreenLight + 0.05
		GettingRed = false
		Trigger.AfterDelay(1, function()
			Warningalert()
		end)
	end
end
Sendnormalcrate = function()
	DetonationPoint = Actor.Create("waypoint", true, { Location = CPos.New(43,43), Owner = Neutral })
	ParaProxy = Actor.Create("powerproxy.normalcrate", false, { Owner = Neutral })
	crates = ParaProxy.SendParatroopers(DetonationPoint.CenterPosition)
	Trigger.AfterDelay(DateTime.Seconds(80), function()
		Sendnormalcrate()
	end)
end

Sendspecialcrate = function()
	DetonationPoint = Actor.Create("waypoint", true, { Location = CPos.New(43,43), Owner = Neutral })
	ParaProxy = Actor.Create("powerproxy.specialcrate", false, { Owner = Neutral })
	crates = ParaProxy.SendParatroopers(DetonationPoint.CenterPosition)
	Trigger.AfterDelay(DateTime.Seconds(70), function()
		Sendspecialcrate()
	end)
end

Sendsupercrate = function()
	DetonationPoint = Actor.Create("waypoint", true, { Location = CPos.New(43,43), Owner = Neutral })
	ParaProxy = Actor.Create("powerproxy.supercrate", false, { Owner = Neutral })
	crates = ParaProxy.SendParatroopers(DetonationPoint.CenterPosition)
	Trigger.AfterDelay(DateTime.Seconds(60), function()
		Sendsupercrate()
	end)
end

Setteleporttriggers = function()
-- Topteleporter
	Trigger.OnEnteredFootprint({CPos.New(43,20)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 29) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(43,19)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 29) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(43,21)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 29) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(42,20)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 29) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(41,20)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 29) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
-- Rightteleporter
	Trigger.OnEnteredFootprint({CPos.New(66,43)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(57, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(65,43)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(57, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(67,43)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(57, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(66,42)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(57, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(66,44)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(57, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
-- Bottomteleporter
	Trigger.OnEnteredFootprint({CPos.New(43,66)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 57) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(43,65)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 57) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(43,67)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 57) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(42,66)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 57) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(41,66)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(43, 57) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
-- Leftteleporter
	Trigger.OnEnteredFootprint({CPos.New(20,43)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(29, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(19,43)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(29, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(21,43)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(29, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(20,42)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(29, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
	Trigger.OnEnteredFootprint({CPos.New(20,41)}, function(a, id)
		if a.Type == "allosaurusegg" or a.Type == "trexegg" or a.Type == "stegosaurusegg" or a.Type == "triceratopsegg" or a.Type == "brachiosaurusegg"or a.Type == "parasaurusegg" or a.Type == "gallimusegg" or a.Type == "biggun" or a.Type == "mcv" or a.Type == "harv" then
			return
		else
			a.Stop()
			a.Teleport(CPos.New(29, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)))
		end
	end)
end

Northmove = { CPos.New(42,28), CPos.New(43,28), CPos.New(44,28), CPos.New(42,29), CPos.New(43,29), CPos.New(44,29), CPos.New(42,30), CPos.New(43,30), CPos.New(44,30) }

Rightmove = { CPos.New(56,42), CPos.New(57,42), CPos.New(58,42), CPos.New(56,43), CPos.New(57,43), CPos.New(58,43), CPos.New(56,44), CPos.New(57,44), CPos.New(58,44) }


Bottommove = { CPos.New(42,56), CPos.New(43,56), CPos.New(44,56), CPos.New(42,57), CPos.New(43,57), CPos.New(44,57), CPos.New(42,58), CPos.New(43,58), CPos.New(44,58) }

Leftmove = { CPos.New(28,42), CPos.New(29,42), CPos.New(30,42), CPos.New(28,43), CPos.New(29,43), CPos.New(30,43), CPos.New(28,44), CPos.New(29,44), CPos.New(30,44) }

Setmovetriggers = function()
-- Topteleporter
	Trigger.OnEnteredFootprint(Northmove, function(a, id)
		if a.HasProperty("Move") then
			a.Move(CPos.New(43, 33) + CVec.New(Utils.RandomInteger(-2, 3), Utils.RandomInteger(-1, 2)))
		end
	end)
-- Rightteleporter
	Trigger.OnEnteredFootprint(Rightmove, function(a, id)
		if a.HasProperty("Move") then
			a.Move(CPos.New(53, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-2, 3)))
		end
	end)
-- Bottomteleporter
	Trigger.OnEnteredFootprint(Bottommove, function(a, id)
		if a.HasProperty("Move") then
			a.Move(CPos.New(43, 53) + CVec.New(Utils.RandomInteger(-2, 3), Utils.RandomInteger(-1, 2)))
		end
	end)
-- Leftteleporter
	Trigger.OnEnteredFootprint(Leftmove, function(a, id)
		if a.HasProperty("Move") then
			a.Move(CPos.New(33, 43) + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-2, 3)))
		end
	end)
end
Notifications = function()
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		Media.DisplayMessage("Hi, there are many new special crates in this map!", "Materia", HSLColor.Red)	
	end)
	Trigger.AfterDelay(DateTime.Seconds(6), function()
		Media.DisplayMessage("The special crates are only dropped in the middle!", "Materia", HSLColor.Red)
	end)
	Trigger.AfterDelay(DateTime.Seconds(11), function()
		Media.DisplayMessage("Step on the round teleporter next to your base to get into middle!", "Materia", HSLColor.Red)
		Media.PlaySoundNotification( allplayers, "Beacon")
		Showarrows()
	end)
	Trigger.AfterDelay(DateTime.Seconds(16), function()
		Media.DisplayMessage("gl hf", "Materia", HSLColor.Red)
	end)
end
Floatcount = 0
Showarrows = function()
	downarrow = Actor.Create("arrowdown", true, { Location = CPos.New(44,17), Owner = Neutral })
	leftarrow = Actor.Create("arrowleft", true, { Location = CPos.New(70,43), Owner = Neutral })
	uparrow = Actor.Create("arrowup", true, { Location = CPos.New(44,69), Owner = Neutral })
	rightarrow = Actor.Create("arrowright", true, { Location = CPos.New(18,43), Owner = Neutral })
	Trigger.AfterDelay(DateTime.Seconds(1), function()
		Floatcount = Floatcount + 1
		downarrow.Destroy()
		leftarrow.Destroy()
		uparrow.Destroy()
		rightarrow.Destroy()
		if Floatcount <= 12 then
			Trigger.AfterDelay(DateTime.Seconds(1), function()
				Showarrows()
			end)
		end
	end)
end

function WorldLoaded()
	SetupPlayers()
	Cratecontrol()
	Setteleporttriggers()
	Setmovetriggers()
	Notifications()
end
