InsertStarGateWayPoints = function()
	StarGateWaypoint = Actor.Create("waypoint", true, { Owner = clearpoint, Location = CPos.New((MapEdgeOverHorizontical / 2) + 8, (MapEdgeOverVertical / 2) + 8) })
	StarGateChronoWayPoint = Actor.Create("waypoint", true, { Owner = clearpoint, Location = CPos.New((MapEdgeOverHorizontical / 2) + 9, (MapEdgeOverVertical / 2) + 9) })
end
InsertStarGate = function()
	StarGate = Actor.Create("stargate", true, { Owner = creeps, Location = CPos.New((MapEdgeOverHorizontical / 2) + 8, (MapEdgeOverVertical / 2) + 8) })
	Trigger.OnRemovedFromWorld(StarGate, function()
		Trigger.AfterDelay(Utils.RandomInteger(66, 88), InsertStarGate)
	end)
end
StarGateQuests = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(22, 44)), function()
		InsertStarGateScientistTeam()
	end)
	Media.PlaySound("ChronoGateOpenSound.aud")
	Trigger.OnEnteredProximityTrigger(StarGateWaypoint.CenterPosition, WDist.FromCells(Utils.RandomInteger(6.8, 8.6)), function(a, id)
		if (a.Owner == multi0 or a.Owner == multi1 or a.Owner == multi2 or a.Owner == multi3) and not (a.Type == "hind" or not a.Type == "tran" or not a.Type == "heli" or not a.Type == "smalltran" or not a.Type == "smalltran.arm" or not a.Type == "tran.arm" or not a.Type == "tran.reinf" or not a.Type == "badr.civilian" or not a.Type == "badr" or not a.Type == "badr.bomber" or not a.Type == "badr.crate" or not a.Type == "badr.explosivegeneral" or not a.Type == "badr.stealthgeneral" or not a.Type == "badr.chronogeneral" or not a.Type == "badr.lasergeneral" or not a.Type == "badr.flamegeneral" or not a.Type == "badr.toxicgeneral" or not a.Type == "badr.teslageneral" or not a.Type == "badr.nucleargeneral" or not a.Type == "badr.commandercarrier" or not a.Type == "badr.reinf" or not a.Type == "badr.bomber" or not a.Type == "carpet.bomber" or not a.Type == "u2" or a.Type == "commandercarrier" or a.Type == "mcv" or a.Type == "jeep" or a.Type == "jeep.recon" or a.Type == "apc" or a.Type == "apc.tower" or a.Type == "arty" or a.Type == "v2rl" or a.Type == "1tnk" or a.Type == "2tnk" or a.Type == "3tnk" or a.Type == "4tnk" or a.Type == "mechw" or a.Type == "behe" or a.Type == "ijeep" or a.Type == "ijeep.recon" or a.Type == "iapc" or a.Type == "iapc.tower" or a.Type == "iarty" or a.Type == "iv2rl" or a.Type == "imechw" or a.Type == "ibehe") then
			Trigger.RemoveProximityTrigger(id)
			Media.PlaySoundNotification(multi0 or multi1 or multi2 or multi3, "CameraSound")
			Beacon.New(neutral, StarGateWaypoint.CenterPosition, Utils.RandomInteger(999, 1111), Utils.Random({ true, false }), "player")
			Camera.Position = StarGateWaypoint.CenterPosition
			CameraStarGate0 = Actor.Create("camera.mission", true, { Owner = multi0, Location = StarGateWaypoint.Location + CVec.New(1, 0) })
			CameraStarGate1 = Actor.Create("camera.mission", true, { Owner = multi1, Location = StarGateWaypoint.Location + CVec.New(1, 0) })
			CameraStarGate2 = Actor.Create("camera.mission", true, { Owner = multi2, Location = StarGateWaypoint.Location + CVec.New(1, 0) })
			CameraStarGate3 = Actor.Create("camera.mission", true, { Owner = multi3, Location = StarGateWaypoint.Location + CVec.New(1, 0) })
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(1.2, 1.4)), function()
				if multi0.IsBot and multi1.IsBot and multi2.IsBot and multi3.IsBot then
				else
					Media.PlayMovieInRadar("StarGateOpening.vqa", nil)
				end
			end)
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(6.6, 9.9)), function()
				if multi0.IsBot and multi1.IsBot and multi2.IsBot and multi3.IsBot then
					if FieldGeneral0.IsInWorld and FieldGeneral1.IsInWorld and FieldGeneral2.IsInWorld and FieldGeneral3.IsInWorld then
						Utils.Do(FieldGeneral0 or FieldGeneral1 or FieldGeneral2 or FieldGeneral3, function(a) Camera.Position = a.CenterPosition end)
					end
				elseif not multi0.IsBot and multi1.IsBot and multi2.IsBot and multi3.IsBot then
					if FieldGeneralLiveState0 then Utils.Do(FieldGeneral0, function(a) Camera.Position = a.CenterPosition end) end
				elseif multi0.IsBot and not multi1.IsBot and multi2.IsBot and multi3.IsBot then
					if FieldGeneralLiveState1 then Utils.Do(FieldGeneral1, function(a) Camera.Position = a.CenterPosition end) end
				elseif multi0.IsBot and multi1.IsBot and not multi2.IsBot and multi3.IsBot then
					if FieldGeneralLiveState2 then Utils.Do(FieldGeneral2, function(a) Camera.Position = a.CenterPosition end) end
				elseif multi0.IsBot and multi1.IsBot and multi2.IsBot and not multi3.IsBot then
					if FieldGeneralLiveState3 then Utils.Do(FieldGeneral3, function(a) Camera.Position = a.CenterPosition end) end
				else
				end
			end)
		end
	end)
	
end
InsertStarGateScientistTeam = function()
	Reinforcements.ReinforceWithTransport(Utils.Random({ neutral, neutral0, neutral1, neutral2, neutral3, allies, england, france, germany, ussr, russia, ukraine, china, gdi }), Utils.Random({ "tran", "smalltran" }), { Utils.Random({ "chan", "delphi", "e6" }), Utils.Random({ "chan", "delphi", "mech" }), Utils.Random({ "chan", "delphi" }), Utils.Random({ "chan", "delphi" }), Utils.Random({ "chan", "delphi" }), Utils.Random({ "chan", "delphi" }) }, { Map.ClosestEdgeCell(StarGateChronoWayPoint.Location + CVec.New(Utils.RandomInteger(-22, 22), Utils.RandomInteger(-22, 22))), StarGateChronoWayPoint.Location + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(-1, 2)) }, nil,
	function(TransportStarGateScientistTeam, StarGateScientistTeam)
		TransportStarGateScientistTeam.Move(StarGateChronoWayPoint.Location + CVec.New(Utils.RandomInteger(-1, 2), Utils.RandomInteger(3, 5)))
		TransportStarGateScientistTeam.UnloadPassengers()
		TransportStarGateScientistTeam.Wait(Utils.RandomInteger(88, 122))
		TransportStarGateScientistTeam.Move(Map.ClosestEdgeCell(StarGateChronoWayPoint.Location + CVec.New(Utils.RandomInteger(-22, 22), Utils.RandomInteger(-22, 22))))
		TransportStarGateScientistTeam.Destroy()
		Utils.Do(StarGateScientistTeam, function(ScientistTeam)
			if (ScientistTeam.Type == "chan" or ScientistTeam.Type == "delphi" or ScientistTeam.Type == "mech" or ScientistTeam.Type == "e6") then
				Trigger.OnIdle(ScientistTeam, function()
					if ScientistTeam.Location == StarGateChronoWayPoint.Location then
						if not ScientistTeam.IsDead and ScientistTeam.IsInWorld then
							ScientistTeam.Wait(Utils.RandomInteger(222, 333))
							ScientistTeam.Scatter()
							ScientistTeam.Scatter()
							ScientistTeam.Scatter()
						end
					else
						if not ScientistTeam.IsDead and ScientistTeam.IsInWorld then
							ScientistTeam.Wait(Utils.RandomInteger(111, 222))
							ScientistTeam.Move(StarGateChronoWayPoint.Location)
						end
					end
				end)
			end
		end)
		Trigger.OnAllKilled(StarGateScientistTeam, function() 
			Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(44, 66)), function()
				InsertStarGateScientistTeam()
			end) 
		end)
	end)
end

