From d1304ae9c7035d22253b9d9734c153a354e6425a Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Sun, 21 May 2023 09:29:10 -0300 Subject: [PATCH] Add bet option --- CommunityRaces.cs | 24 +++++++++++++++++++----- CommunityRaces.ini | 1 + Config.cs | 13 +++++++++++++ Race.cs | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CommunityRaces.cs b/CommunityRaces.cs index 2721f4e..f44efec 100644 --- a/CommunityRaces.cs +++ b/CommunityRaces.cs @@ -320,6 +320,9 @@ private void StartRace(Race race) if (!_peds) Function.Call(Hash.CLEAR_AREA_OF_PEDS, spawn.Position.X, spawn.Position.Y, spawn.Position.Z, 1000f, 0); + + if (_currentRivals.Count > 0) + Game.Player.Money -= Config.Bet; } private void EndRace(bool reset) @@ -479,7 +482,7 @@ public void OnTick(object sender, EventArgs e) 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)) + if (Game.IsControlJustPressed(0, GTA.Control.VehicleExit) && (Game.Player.Character.IsInVehicle() || Game.Player.Character.Position.DistanceTo(_currentVehicle.Position) > 5f)) { _quitMenu.RefreshIndex(); _quitMenu.Visible = !_quitMenu.Visible; @@ -544,7 +547,7 @@ public void OnTick(object sender, EventArgs e) for (int i = 0; i < _rivalCheckpointStatus.Count; i++) { Tuple tuple = _rivalCheckpointStatus[i]; - if (tuple.Item1.Vehicle.IsInRangeOf(_currentRace.Checkpoints[tuple.Item2], 50f)) + if (tuple.Item1.Vehicle.IsInRangeOf(_currentRace.Checkpoints[tuple.Item2], 20f)) { tuple.Item1.Character.Task.ClearAll(); if (_currentRace.Checkpoints.Length <= tuple.Item2 + 1) @@ -615,9 +618,9 @@ public void OnTick(object sender, EventArgs e) if (peoplecount > 1) { _passed.AddItem("Position", position + "/" + peoplecount, position == 1 ? MissionPassedScreen.TickboxState.Tick : MissionPassedScreen.TickboxState.Empty); - if (position <= 3) + if (position == 1) { - var reward = position == 1 ? 50000 : position == 2 ? 30000 : 10000; + var reward = Config.Bet * peoplecount; _passed.AddItem("Reward", $"${reward}", MissionPassedScreen.TickboxState.None); Game.Player.Money += reward; } @@ -773,6 +776,16 @@ public void BuildMenu(Race race) Config.Opponents = item.Items[index].ToString(); }; + List betList = new List(); + Enumerable.Range(0, 11).ToList().ForEach(n => betList.Add($"${n * 1000}")); + if (!betList.Contains($"${Config.Bet}")) + Config.Bet = 0; + var betItem = new UIMenuListItem("Bet", betList, Config.Bet / 1000); + betItem.OnListChanged += (item, index) => + { + Config.Bet = index * 1000; + }; + var trafficItem = new UIMenuCheckboxItem("Traffic", Config.Traffic); trafficItem.CheckboxEvent += (i, checkd) => { @@ -870,6 +883,7 @@ public void BuildMenu(Race race) GUI.MainMenu.AddItem(secondaryColorItem); GUI.MainMenu.AddItem(radioItem); GUI.MainMenu.AddItem(opponentsItem); + GUI.MainMenu.AddItem(betItem); if (race.LapsAvailable) { var lapList = new List(); @@ -883,7 +897,7 @@ public void BuildMenu(Race race) } GUI.MainMenu.AddItem(confimItem); GUI.MainMenu.RefreshIndex(); - GUI.MainMenu.CurrentSelection = race.LapsAvailable ? 11 : 10; + GUI.MainMenu.CurrentSelection = GUI.MainMenu.MenuItems.Count - 1; } private void SetVehicleColors() diff --git a/CommunityRaces.ini b/CommunityRaces.ini index 4321876..1260681 100644 --- a/CommunityRaces.ini +++ b/CommunityRaces.ini @@ -8,6 +8,7 @@ PRIMARYCOLOR = Random SECONDARYCOLOR = Random RADIO = Random OPPONENTS = Random +BET = 0 LAPS = 1 CAYOPERICOLOADER = True RACESBLIPS = True diff --git a/Config.cs b/Config.cs index 603e546..fef578e 100644 --- a/Config.cs +++ b/Config.cs @@ -130,6 +130,19 @@ public static string Opponents } } + public static int Bet + { + get + { + return _settings.GetValue("Main", "Bet", 0); + } + set + { + _settings.SetValue("Main", "Bet", value); + _settings.Save(); + } + } + public static bool Traffic { get diff --git a/Race.cs b/Race.cs index e28f4dc..c8ee37b 100644 --- a/Race.cs +++ b/Race.cs @@ -38,7 +38,7 @@ public void Add() { var blip = World.CreateBlip(Trigger); blip.IsShortRange = true; - blip.Sprite = BlipSprite.Race; + blip.Sprite = BlipSprite.RaceFinish; blip.Name = "Community Race: " + Name; Blip = blip; }