Пример #1
0
		public Race(Race copyFrom)
		{
			Checkpoints = copyFrom.Checkpoints;
			SpawnPoints = copyFrom.SpawnPoints;
			AvailableVehicles = copyFrom.AvailableVehicles;
			LapsAvailable = copyFrom.LapsAvailable;
			DecorativeProps = copyFrom.DecorativeProps;
			Trigger = copyFrom.Trigger;

			Name = copyFrom.Name;
			Description = copyFrom.Description;
		}
Пример #2
0
		public void BuildMenu(Race race)
		{
			GUI.MainMenu.Clear();
			GUI.MainMenu.SetBannerType(new UIResRectangle());
			_raceSettings.Clear();

			_raceSettings["TOD"] = "Current";
			_raceSettings["Weather"] = "Current";
			_raceSettings["Wanted"] = false;
			_raceSettings["Opponents"] = "Random";
			_raceSettings["Traffic"] = true;
			_raceSettings["Laps"] = 1;

			_previewVehicle = World.CreateVehicle(Helpers.RequestModel((int)race.AvailableVehicles[0]), race.Trigger);
			_previewVehicle.IsPersistent = false;

			List<dynamic> timeList = new List<dynamic> { "Current", "Sunrise", "Day", "Sunset", "Night" };
			var timeItem = new UIMenuListItem("Time of Day", timeList, 0);
			timeItem.OnListChanged += (item, index) =>
			{
				_raceSettings["TOD"] = item.IndexToItem(index);
			};

			var weatherList = new List<dynamic> { "Current" };
			Enum.GetNames(typeof(Weather)).ToList().ForEach(w => weatherList.Add(w));
			var weatherItem = new UIMenuListItem("Weather", weatherList, 0);
			weatherItem.OnListChanged += (item, index) =>
			{
				_raceSettings["Weather"] = item.IndexToItem(index);
			};

			var copItem = new UIMenuCheckboxItem("Wanted Levels", false);
			copItem.CheckboxEvent += (i, checkd) =>
			{
				_raceSettings["Wanted"] = checkd;
			};

			var opponentsList = new List<dynamic> { "Random" };
			Enumerable.Range(1, race.SpawnPoints.Length - 1).ToList().ForEach(n => opponentsList.Add(n));
			var opponentsItem = new UIMenuListItem("Number of Opponents", opponentsList, 0);
			opponentsItem.OnListChanged += (item, index) =>
			{
				_raceSettings["Opponents"] = item.IndexToItem(index);
			};

			var trafficItem = new UIMenuCheckboxItem("Traffic", true);
			trafficItem.CheckboxEvent += (i, checkd) =>
			{
				_raceSettings["Traffic"] = checkd;
			};

			List<dynamic> tmpList = new List<dynamic>();
			race.AvailableVehicles.ToList().ForEach(x => tmpList.Add(x));
			var carItem = new UIMenuListItem("Vehicle", tmpList, 0);
			carItem.OnListChanged += (item, index) =>
			{
				VehicleHash outHash;
				Enum.TryParse(item.IndexToItem(index).ToString(), out outHash);
				var oldC = _previewVehicle.PrimaryColor;
				_previewVehicle?.Delete();
				_previewVehicle = World.CreateVehicle(Helpers.RequestModel((int) outHash), race.Trigger);
				if(_previewVehicle == null) return;
				_previewVehicle.PrimaryColor = oldC;
				_previewVehicle.SecondaryColor = oldC;
				_previewVehicle.IsPersistent = false;
			};
			
			List<dynamic> colors = new List<dynamic>
			{
				VehicleColor.MatteYellow,
                VehicleColor.Orange,
                VehicleColor.MatteRed,
                VehicleColor.HotPink,
                VehicleColor.MattePurple,
                VehicleColor.MatteDarkBlue,
                VehicleColor.Blue,
                VehicleColor.EpsilonBlue,
                VehicleColor.MatteLimeGreen,
                VehicleColor.Green,
            };
			var colorItem = new UIMenuListItem("Color", colors, 0);
			colorItem.OnListChanged += (ite, index) =>
			{
				VehicleColor outHash;
				Enum.TryParse(ite.IndexToItem(index).ToString(), out outHash);
				_previewVehicle.PrimaryColor = outHash;
				_previewVehicle.SecondaryColor = outHash;
			};

			var confimItem = new UIMenuItem("Start Race");
			confimItem.Activated += (item, index) =>
			{
				GUI.MainMenu.Visible = false;
				GUI.IsInMenu = false;
				Game.Player.CanControlCharacter = true;
				World.RenderingCamera = null;
				StartRace(race);
			};

			GUI.MainMenu.OnMenuClose += menu =>
			{
				World.RenderingCamera = null;
				GUI.IsInMenu = false;
				Game.Player.CanControlCharacter = true;
				_previewVehicle?.Delete();
			};

			GUI.MainMenu.AddItem(timeItem);
			GUI.MainMenu.AddItem(weatherItem);
			GUI.MainMenu.AddItem(copItem);
			GUI.MainMenu.AddItem(carItem);
			GUI.MainMenu.AddItem(colorItem);
			GUI.MainMenu.AddItem(opponentsItem);
			GUI.MainMenu.AddItem(trafficItem);
			if (race.LapsAvailable)
			{
				var lapList = new List<dynamic>();
				Enumerable.Range(1, 20).ToList().ForEach(n => lapList.Add(n));
				var lapItem = new UIMenuListItem("Laps", lapList, 0);
				lapItem.OnListChanged += (item, index) =>
				{
					_raceSettings["Laps"] = item.IndexToItem(index);
				};
				GUI.MainMenu.AddItem(lapItem);
			}
			GUI.MainMenu.AddItem(confimItem);
			GUI.MainMenu.RefreshIndex();
		}
Пример #3
0
	    public void SaveMap(Map map, string filename)
	    {
		    if (!filename.EndsWith(".xml"))
			    filename += ".xml";
		    Race tmpRace = new Race
		    {
			    AvailableVehicles =
				    map.Objects.Where(obj => obj.Type == ObjectTypes.Vehicle)
					    .Select(obj => (VehicleHash) obj.Hash)
					    .Distinct()
					    .ToArray(),
			    Checkpoints = map.Markers.Select(mar => mar.Position).ToArray()
		    };
		    var props = map.Objects.Where(obj => obj.Type == ObjectTypes.Prop).ToArray();
			SavedProp[] tmpProps = new SavedProp[props.Length];
		    for (int i = 0; i < props.Length; i++)
		    {
			    tmpProps[i] = new SavedProp()
			    {
				    Dynamic = props[i].Dynamic,
					Hash = props[i].Hash,
					Position = props[i].Position,
					Rotation = props[i].Rotation,
			    };
		    }
		    tmpRace.DecorativeProps = tmpProps;
		    tmpRace.Trigger = map.Objects.First(obj => obj.Type == ObjectTypes.Ped).Position - new Vector3(0f, 0f, 1f);
		    tmpRace.SpawnPoints = map.Objects.Where(obj => obj.Type == ObjectTypes.Vehicle).Select(obj =>new SpawnPoint() {Position = obj.Position, Heading = obj.Rotation.Z}).ToArray();
		    tmpRace.Name = "Nameless Map";
		    tmpRace.Description = "Cool race!";

			XmlSerializer serializer = new XmlSerializer(typeof(Race));
		    if (!Directory.Exists("scripts\\Races"))
			    Directory.CreateDirectory("scripts\\Races");
			StreamWriter writer = new StreamWriter("scripts\\Races\\" + filename);
			serializer.Serialize(writer, tmpRace);
			writer.Close();
		    UI.Notify("~b~~h~Community Races~h~~n~~w~Race saved as ~h~" + filename + "~h~!");
		    UI.Notify("Don't forget to include your name and the map description in the file!");
	    }
Пример #4
0
	    public void OnTick(object sender, EventArgs e)
	    {
		    if (DateTime.Now.Second != _lasttime.Second)
		    {
			    _seconds++;
			    _lasttime = DateTime.Now;
			    if (_isInRace && _countdown > 0)
			    {
				    var screen = UIMenu.GetScreenResolutionMantainRatio();
				    var w = Convert.ToInt32(screen.Width/2);
				    _countdown--;
					if(_countdown > 3) return;
				    _fadeoutSprite = new Sprite("mpinventory", "in_world_circle", new Point(w - 125, 200), new Size(250, 250), 0f, _countdown == 0 ? Color.FromArgb(49, 235, 126) : Color.FromArgb(241, 247, 57));
					Function.Call(Hash.REQUEST_SCRIPT_AUDIO_BANK, "HUD_MINI_GAME_SOUNDSET", true);
					Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET");
					if (_countdown == 0)
				    {
					    _participants.ForEach(car => car.FreezePosition = false);
					    _missionStart = _seconds;
				    }
			    }
				else if (_isInRace && _countdown == 0)
				{
					_countdown = -1;
				}
		    }

			GUI.MainMenu.ProcessControl();
			GUI.MainMenu.ProcessMouse();
			GUI.MainMenu.Draw();

			_quitMenu.ProcessControl();
			_quitMenu.ProcessMouse();
			_quitMenu.Draw();

			GUI.DrawSettings(_previewRace, _previewVehicle);

			_passed?.Draw();

			if (_countdown > -1 && _countdown <= 3)
		    {
				var screen = UIMenu.GetScreenResolutionMantainRatio();
				var w = Convert.ToInt32(screen.Width / 2);
				new UIResText(_countdown == 0 ? "GO" : _countdown.ToString(), new Point(w, 260), 2f, Color.White, Font.Pricedown, UIResText.Alignment.Centered).Draw();
		    }

		    if (_fadeoutSprite?.Color.A > 5)
		    {
			    _fadeoutSprite.Color = Color.FromArgb(_fadeoutSprite.Color.A - 5, _fadeoutSprite.Color.R, _fadeoutSprite.Color.G,
				    _fadeoutSprite.Color.B);
				_fadeoutSprite.Draw();
		    }


            /* COURIER */
            GUICourier.Init();
            GUICourier.MainMenu.ProcessControl();
            GUICourier.MainMenu.ProcessMouse();
            var safe = UIMenu.GetSafezoneBounds();
            var res = UIMenu.GetScreenResolutionMantainRatio();

            new UIResRectangle(new Point(((int)res.Width-200), 0), new Size(200, 400), Color.FromArgb(200,0,0,0)).Draw();

            GUICourier.MainMenu.Draw();

            if (activeDeliveries.Count == 0 || (_seconds - lastSpawn > 60 && activeDeliveries.Count < 3))
            {
                Delivery d = Delivery.CreateDelivery();
                d.activate();
                activeDeliveries.Add(d);
                lastSpawn = _seconds;
                UI.Notify("New delivery available");
            }

            int pick = 0,drop = 0;
            Vector3 me = Game.Player.Character.Position;
            String posStr = String.Format("{0} {1} {2}", me.X.ToString("F02"), me.Y.ToString("F02"), me.Z.ToString("F02"));


            new UIResText("Pickup", new Point(Convert.ToInt32(res.Width) - 190, 20), .45f, Color.White, Font.HouseScript, UIResText.Alignment.Left) { DropShadow = true }.Draw();
            new UIResText("Dropoff", new Point(Convert.ToInt32(res.Width) - 190, 210), .45f, Color.White, Font.HouseScript, UIResText.Alignment.Left) { DropShadow = true }.Draw();
            foreach (Delivery d in activeDeliveries.GetRange(0,activeDeliveries.Count)) {
                d.tick();
                if (d.isActive == false)
                {
                    activeDeliveries.Remove(d);
                    continue;
                }

 
                if (d._isStarted)
                {
                    float dist = me.DistanceTo(d.end);
                    String posStr2 = String.Format("{0} {1} {2}", d.end.X.ToString("F02"), d.end.Y.ToString("F02"), d.end.Z.ToString("F02"));
                    new UIResText(String.Format("{0} {1}", dist.ToString("F02"), d.end_text), new Point(Convert.ToInt32(res.Width) - 190, 20 * (drop + 2) + 210), .35f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { DropShadow = true }.Draw();

                    drop++;
                }
                else {
                    float dist = me.DistanceTo(d.start);
                    String posStr2 = String.Format("{0} {1} {2}", d.start.X.ToString("F02"), d.start.Y.ToString("F02"), d.start.Z.ToString("F02"));
                    new UIResText(String.Format("{0} {1}", dist.ToString("F02"), d.start_text), new Point(Convert.ToInt32(res.Width) - 190, 20 * (pick + 2)), .35f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { DropShadow = true }.Draw();

                    pick++;
                }
                //new UIResText("WORLD", new Point(Convert.ToInt32(res.Width) - 190, 40), .35f, Color.DodgerBlue, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { DropShadow = true }.Draw();

            }
            /* COURIER */

            if (!_isInRace)
		    {
				if(GUI.IsInMenu) return;
			    foreach (var race in _races)
			    {
				    World.DrawMarker(MarkerType.VerticalCylinder, race.Trigger, new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(5f, 5f, 1f), Color.FromArgb(200, 255, 255, 255));
					if(!Game.Player.Character.IsInRangeOf(race.Trigger, 50f)) continue;
				    var tmpSF = new Scaleform(0);
				    tmpSF.Load("PLAYER_NAME_01");
					tmpSF.CallFunction("SET_PLAYER_NAME", race.Name);
				    
					tmpSF.Render3D(race.Trigger + new Vector3(0f, 0f, 2f), new Vector3(0f, 0f, _oldAngle), new Vector3(12, 6, 2));

					var tmpT = new Scaleform(0);
					tmpT.Load("PLAYER_NAME_02");
					tmpT.CallFunction("SET_PLAYER_NAME", "Community Race");

					tmpT.Render3D(race.Trigger + new Vector3(0f, 0f, 1.5f), new Vector3(0f, 0f, _oldAngle), new Vector3(6, 3, 1));

					_oldAngle += 2f;

                    if (!Game.Player.Character.IsInRangeOf(race.Trigger, 5f)) continue;

                    Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
                    Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, "Press ~INPUT_CONTEXT~ to participate in this Community Race.");
                    Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1);

                    if (Game.IsControlJustPressed(0, GTA.Control.Context))
				    {
					    Game.Player.CanControlCharacter = false;
					    Game.Player.Character.Position = race.Trigger + new Vector3(4f, 0f, -1f);
					    _previewRace = race;
						BuildMenu(race);
					    GUI.MainMenu.Visible = true;
					    GUI.IsInMenu = true;
					    break;
				    }
			    }
				
		    }
		    else if(_isInRace)
		    {
				if(!_raceSettings["Wanted"])
					Function.Call(Hash.SET_MAX_WANTED_LEVEL, 0);
				//if(Game.Player.Character.IsInVehicle())
				Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)GTA.Control.VehicleExit);
			    if ((Game.IsControlJustPressed(0, GTA.Control.VehicleExit) && Game.Player.Character.IsInVehicle()) || (!Game.Player.Character.IsInVehicle() && !Game.Player.Character.IsGettingIntoAVehicle && Game.IsControlJustPressed(0, GTA.Control.Enter)))
			    {
					_quitMenu.RefreshIndex();
				    _quitMenu.Visible = !_quitMenu.Visible;
			    }
				
			    if (!Convert.ToBoolean(_raceSettings["Traffic"]))
			    {
				    Vehicle[] close = World.GetNearbyVehicles(Game.Player.Character, 10000f);
				    foreach (Vehicle vehicle in close)
				    {
					    if (_currentRivals.Any(riv => riv.Vehicle.Handle == vehicle.Handle) ||
					        Game.Player.Character.IsInVehicle(vehicle)) continue;
						vehicle.GetPedOnSeat(VehicleSeat.Driver)?.Delete();
						vehicle?.Delete();
				    }
			    }

			//    var res = UIMenu.GetScreenResolutionMantainRatio();
			//    var safe = UIMenu.GetSafezoneBounds();
			    const int interval = 45;
			    if (_countdown <= 0)
			    {
				    new UIResText("TIME",new Point(Convert.ToInt32(res.Width) - safe.X - 180, Convert.ToInt32(res.Height) - safe.Y - (90 + (1*interval))),0.3f, Color.White).Draw();
				    new UIResText(FormatTime((int) unchecked(_seconds - _missionStart)),new Point(Convert.ToInt32(res.Width) - safe.X - 20, Convert.ToInt32(res.Height) - safe.Y - (102 + (1*interval))),0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw();
				    new Sprite("timerbars", "all_black_bg",new Point(Convert.ToInt32(res.Width) - safe.X - 248,Convert.ToInt32(res.Height) - safe.Y - (100 + (1*interval))), new Size(250, 37), 0f, Color.FromArgb(200, 255, 255, 255)).Draw();

					new UIResText("POSITION", new Point(Convert.ToInt32(res.Width) - safe.X - 180, Convert.ToInt32(res.Height) - safe.Y - (90 + (2 * interval))), 0.3f, Color.White).Draw();
					new UIResText((CalculatePlayerPositionInRace() + 1) + "/" + (_currentRivals.Count + 1), new Point(Convert.ToInt32(res.Width) - safe.X - 20, Convert.ToInt32(res.Height) - safe.Y - (102 + (2 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw();
					new Sprite("timerbars", "all_black_bg", new Point(Convert.ToInt32(res.Width) - safe.X - 248, Convert.ToInt32(res.Height) - safe.Y - (100 + (2 * interval))), new Size(250, 37), 0f, Color.FromArgb(200, 255, 255, 255)).Draw();

				    if (_raceSettings["Laps"] > 1)
				    {
						int playerCheckpoint = _currentRace.Checkpoints.Length - _checkpoints.Count;
					    int currentLap = Convert.ToInt32(Math.Floor(playerCheckpoint/(decimal)_totalLaps)) + 1;

						new UIResText("LAP",new Point(Convert.ToInt32(res.Width) - safe.X - 180,Convert.ToInt32(res.Height) - safe.Y - (90 + (3*interval))), 0.3f, Color.White).Draw();
					    new UIResText(currentLap + "/" + _raceSettings["Laps"], new Point(Convert.ToInt32(res.Width) - safe.X - 20,Convert.ToInt32(res.Height) - safe.Y - (102 + (3*interval))), 0.5f, Color.White, Font.ChaletLondon,UIResText.Alignment.Right).Draw();
					    new Sprite("timerbars", "all_black_bg",new Point(Convert.ToInt32(res.Width) - safe.X - 248,Convert.ToInt32(res.Height) - safe.Y - (100 + (3*interval))), new Size(250, 37), 0f,Color.FromArgb(200, 255, 255, 255)).Draw();
				    }
			    }


			    for (int i = 0; i < _rivalCheckpointStatus.Count; i++)
			    {
				    Tuple<Rival, int> tuple = _rivalCheckpointStatus[i];
				    if (tuple.Item1.Vehicle.IsInRangeOf(_currentRace.Checkpoints[tuple.Item2], 10f))
				    {
					    tuple.Item1.Character.Task.ClearAll();
					    if (_currentRace.Checkpoints.Length <= tuple.Item2 + 1)
					    {
						    if (!_finishedParticipants.Contains(tuple.Item1))
							    _finishedParticipants.Add(tuple.Item1);
						    tuple.Item1.Vehicle.HandbrakeOn = true;
						    continue;
					    }
					    _rivalCheckpointStatus[i] = new Tuple<Rival, int>(tuple.Item1,tuple.Item2 + 1);
					    Function.Call(Hash.TASK_VEHICLE_MISSION_COORS_TARGET, tuple.Item1.Character.Handle, tuple.Item1.Vehicle.Handle,
						    _currentRace.Checkpoints[tuple.Item2 + 1].X, _currentRace.Checkpoints[tuple.Item2 + 1].Y,
						    _currentRace.Checkpoints[tuple.Item2 + 1].Z, Mode, 200f, Rival.MainDrivingStyle, 5f, 0f, 0); // TODO: Debuggin // old - 6
				    }
			    }


			    World.DrawMarker(MarkerType.VerticalCylinder, _checkpoints[0], new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(10f, 10f, 2f), Color.FromArgb(100, 241, 247, 57));
			    if (_nextBlip == null)
				    _nextBlip = World.CreateBlip(_checkpoints[0]);
			    if (_checkpoints.Count >= 2)
			    {
				    if (_secondBlip == null)
				    {
					    _secondBlip = World.CreateBlip(_checkpoints[1]);
					    _secondBlip.Scale = 0.5f;
						if(_checkpoints.Count == 2)
							_secondBlip.Sprite = BlipSprite.RaceFinish;
				    }
				    Vector3 dir = _checkpoints[1] - _checkpoints[0];
					dir.Normalize();
					World.DrawMarker(MarkerType.ChevronUpx1, _checkpoints[0] + new Vector3(0f, 0f, 2f), dir, new Vector3(60f, 0f, 0f), new Vector3(4f, 4f, 4f), Color.FromArgb(200, 87, 193, 250));
			    }
			    else
			    {
					Vector3 dir = Game.Player.Character.Position - _checkpoints[0];
					dir.Normalize();
				    World.DrawMarker(MarkerType.CheckeredFlagRect, _checkpoints[0] + new Vector3(0f, 0f, 2f), dir, new Vector3(0f, 0f, 0f), new Vector3(4f, 4f, 4f), Color.FromArgb(200, 87, 193, 250));
					_nextBlip.Sprite = BlipSprite.RaceFinish;
			    }

			    if (Game.Player.Character.IsInVehicle() && Game.Player.Character.IsInRangeOf(_checkpoints[0], 10f))
			    {
					Function.Call(Hash.REQUEST_SCRIPT_AUDIO_BANK, "HUD_MINI_GAME_SOUNDSET", true);
					Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET");
					_checkpoints.RemoveAt(0);
					_nextBlip?.Remove();
					_secondBlip?.Remove();
				    _nextBlip = null;
				    _secondBlip = null;
				    if (_checkpoints.Count == 0)
				    {
					    Game.Player.CanControlCharacter = false;
						Function.Call(Hash._START_SCREEN_EFFECT, "HeistCelebPass", 0, true);
						if(Game.Player.Character.IsInVehicle())
							Game.Player.Character.CurrentVehicle.HandbrakeOn = true;
						World.DestroyAllCameras();
					    World.RenderingCamera = World.CreateCamera(GameplayCamera.Position, GameplayCamera.Rotation, 60f);
						Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "CHECKPOINT_UNDER_THE_BRIDGE", "HUD_MINI_GAME_SOUNDSET");
						int position = _finishedParticipants.Count + 1;
					    int peoplecount = _currentRivals.Count + 1;
					    int score = 100 - ((position - 1)*10);
					    if (score < 0)
						    score = 0;
						_passed = new MissionPassedScreen(_currentRace.Name, score, score > 50 ? score > 90 ? MissionPassedScreen.Medal.Gold : MissionPassedScreen.Medal.Silver : MissionPassedScreen.Medal.Bronze);
						_passed.AddItem("Time Elapsed", FormatTime((int)unchecked(_seconds - _missionStart)), MissionPassedScreen.TickboxState.None);
						_passed.AddItem("Position", position + "/" + peoplecount, position == 1 ? MissionPassedScreen.TickboxState.Tick : MissionPassedScreen.TickboxState.Empty);
					    _passed.OnContinueHit += () =>
					    {
							Game.FadeScreenOut(1000);
							Wait(1000);
							Function.Call(Hash._STOP_SCREEN_EFFECT, "HeistCelebPass");
						    Game.Player.Character.Position = _currentRace.Trigger;
						    Game.Player.CanControlCharacter = true;
						    World.RenderingCamera = null;
							EndRace();
						    _passed = null;
							Game.FadeScreenIn(1500);
					    };
						_passed.Show();
						_isInRace = false;
				    }
			    }
			}
	    }
Пример #5
0
	    private void EndRace()
	    {
		    _isInRace = false;
		    _currentRace = null;

			_secondBlip?.Remove();
			_nextBlip?.Remove();
			_checkpoints.Clear();
		    foreach (Entity entity in _cleanupBag)
		    {
			    entity?.Delete();
		    }
			_cleanupBag.Clear();
			_participants.Clear();
		    _countdown = -1;
		    foreach (Rival rival in _currentRivals)
		    {
			    rival.Clean();
		    }
			_currentRivals.Clear();
			_rivalCheckpointStatus.Clear();
			_finishedParticipants.Clear();
	    }
Пример #6
0
	    private void StartRace(Race race)
	    {
			race = new Race(race);
			Game.FadeScreenOut(500);
			Wait(500);
		    _isInRace = true;
			_currentRace = race;
		    if (_raceSettings["Laps"] > 1)
		    {
			    _totalLaps = race.Checkpoints.Length;
			    List<Vector3> tmpCheckpoints = new List<Vector3>();
			    for (int i = 0; i < _raceSettings["Laps"]; i++)
			    {
				    tmpCheckpoints.AddRange(race.Checkpoints);
			    }
			    _currentRace.Checkpoints = tmpCheckpoints.ToArray();
		    }

		    if (_raceSettings["Weather"] != "Current")
		    {
			    Weather wout;
			    Enum.TryParse(_raceSettings["Weather"], out wout);
			    World.Weather = wout;
		    }

		    
			switch ((string)_raceSettings["TOD"])
			{
				case "Current":
					break;
				case "Sunrise":
					World.CurrentDayTime = new TimeSpan(06, 00, 00);
					break;
				case "Day":
					World.CurrentDayTime = new TimeSpan(16, 00, 00);
					break;
				case "Sunset":
					World.CurrentDayTime = new TimeSpan(20, 00, 00);
					break;
				case "Night":
					World.CurrentDayTime = new TimeSpan(02, 00, 00);
					break;
			}




			List<SpawnPoint> availalbleSpawnPoints = new List<SpawnPoint>(race.SpawnPoints);

		    int spawnId = RandGen.Next(availalbleSpawnPoints.Count);
            var spawn = availalbleSpawnPoints[spawnId];
			availalbleSpawnPoints.RemoveAt(spawnId);


		    var car = _previewVehicle;
		    car.Position = spawn.Position;
		    car.Heading = spawn.Heading;
			Function.Call(Hash.SET_PED_INTO_VEHICLE, Game.Player.Character.Handle, car.Handle, (int)VehicleSeat.Driver);
		    car.IsPersistent = false;
		    car.FreezePosition = true;

		    int spawnlen = _raceSettings["Opponents"].ToString() == "Random" ? RandGen.Next(1, race.SpawnPoints.Length - 1) : Convert.ToInt32(_raceSettings["Opponents"]);

		    for (int i = 0; i < spawnlen; i++)
		    {
			    var spid = RandGen.Next(availalbleSpawnPoints.Count);
			    Model mod = Helpers.RequestModel((int) race.AvailableVehicles[RandGen.Next(race.AvailableVehicles.Length)]);
			    var riv = new Rival(availalbleSpawnPoints[spid].Position, availalbleSpawnPoints[spid].Heading, mod);
				_participants.Add(riv.Vehicle);
				availalbleSpawnPoints.RemoveAt(spid);
				Function.Call(Hash.TASK_VEHICLE_MISSION_COORS_TARGET, riv.Character.Handle, riv.Vehicle.Handle, race.Checkpoints[0].X, race.Checkpoints[0].Y, race.Checkpoints[0].Z, Mode, 200f, Rival.MainDrivingStyle, 5f, 0f, 0);
				_rivalCheckpointStatus.Add(new Tuple<Rival, int>(riv, 0));
			    var tmpblip = riv.Character.AddBlip();
				tmpblip.Color = BlipColor.Blue;
			    tmpblip.IsShortRange = true;
			    tmpblip.Scale = 0.6f;
				_currentRivals.Add(riv);
		    }

		    foreach (SavedProp prop in race.DecorativeProps)
		    {
			    var tmpProp = World.CreateProp(Helpers.RequestModel(prop.Hash), prop.Position, prop.Rotation, false, false);
			    tmpProp.Position = prop.Position;
			    if (prop.Dynamic)
				    tmpProp.FreezePosition = true;
                _cleanupBag.Add(tmpProp);
		    }

		    _checkpoints = race.Checkpoints.ToList();
		    _missionStart = _seconds;
			Game.FadeScreenIn(500);
			Wait(500);
		    _countdown = 5;
			_participants.Add(car);
			_cleanupBag.Add(car);
	    }
Пример #7
0
		public static void DrawSettings(Race settingsForRace, Vehicle previewVehicle)
		{
			if(!IsInMenu) return;

			// CAMERA
			if (MainCamera == null || MainCamera.Position != settingsForRace.Trigger + new Vector3(3f, 3f, 3f))
			{
				World.DestroyAllCameras();
				MainCamera = World.CreateCamera(settingsForRace.Trigger + new Vector3(3f, 3f, 3f), new Vector3(), 60f);
				MainCamera.PointAt(settingsForRace.Trigger);
			}
			World.RenderingCamera = MainCamera;

			// UI DRAWING
			var safe = UIMenu.GetSafezoneBounds();
			var res = UIMenu.GetScreenResolutionMantainRatio();

			new UIResText(settingsForRace.Name, new Point(safe.X, safe.Y), 0.8f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) { Outline = true}.Draw();
			new UIResText(settingsForRace.Description, new Point(safe.X, 50 + safe.Y), 0.4f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) {WordWrap = new Size(Convert.ToInt32(res.Width) - (safe.X*2),0), Outline = true}.Draw();

			new UIResRectangle(new Point(safe.X + 435, safe.Y + 107), new Size(1200, 37), Color.Black).Draw();
			new UIResText("VEHICLE", new Point(safe.X + 1000, safe.Y + 110), 0.35f, Color.White, Font.ChaletLondon, UIResText.Alignment.Centered).Draw();

			string vehClass = "";
			switch (Function.Call<int>(Hash.GET_VEHICLE_CLASS, previewVehicle.Handle))
			{
				case 0:
					vehClass = "Compacts";
					break;
				case 1:
					vehClass = "Sedans";
					break;
				case 2:
					vehClass = "SUVs";
					break;
				case 3:
					vehClass = "Coupes";
					break;
				case 4:
					vehClass = "Muscle";
					break;
				case 5:
					vehClass = "Sports Classics";
					break;
				case 6:
					vehClass = "Sports";
					break;
				case 7:
					vehClass = "Super";
					break;
				case 8:
					vehClass = "Motorcycle";
					break;
				case 9:
					vehClass = "Offroad";
					break;
				case 10:
					vehClass = "Industrial";
					break;
				case 11:
					vehClass = "Utility";
					break;
				case 12:
					vehClass = "Vans";
					break;
				case 13:
					vehClass = "Bicycle";
					break;
				case 14:
					vehClass = "Boats";
					break;
				case 15:
					vehClass = "Helicopter";
					break;
				case 16:
					vehClass = "Airplane";
					break;
				case 17:
					vehClass = "Service";
					break;
				case 18:
					vehClass = "Emergency";
					break;
				case 19:
					vehClass = "Military";
					break;
				case 20:
					vehClass = "Commercial";
					break;
			}

			new UIResText(vehClass, new Point(Convert.ToInt32(res.Width) - 430 - safe.X, 800 - safe.Y), 1.5f, Color.White, Font.ChaletComprimeCologne, UIResText.Alignment.Left) {DropShadow = true}.Draw();
			new UIResText(previewVehicle.FriendlyName, new Point(Convert.ToInt32(res.Width) - 400 - safe.X, 840 - safe.Y), 1.5f, Color.DodgerBlue, Font.HouseScript, UIResText.Alignment.Left) {DropShadow = true}.Draw();

			// MENU CORRECTIONS
			MainMenu.Subtitle.Position = new Point(safe.X + 200, MainMenu.Subtitle.Position.Y);
			MainMenu.Subtitle.TextAlignment = UIResText.Alignment.Centered;
			
		}