Skip to content

Commit

Permalink
Add bet option
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed May 21, 2023
1 parent 1e568fa commit d1304ae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
24 changes: 19 additions & 5 deletions CommunityRaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -544,7 +547,7 @@ public void OnTick(object sender, EventArgs e)
for (int i = 0; i < _rivalCheckpointStatus.Count; i++)
{
Tuple<Rival, int> 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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -773,6 +776,16 @@ public void BuildMenu(Race race)
Config.Opponents = item.Items[index].ToString();
};

List<dynamic> betList = new List<dynamic>();
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) =>
{
Expand Down Expand Up @@ -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<dynamic>();
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions CommunityRaces.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PRIMARYCOLOR = Random
SECONDARYCOLOR = Random
RADIO = Random
OPPONENTS = Random
BET = 0
LAPS = 1
CAYOPERICOLOADER = True
RACESBLIPS = True
Expand Down
13 changes: 13 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Race.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d1304ae

Please sign in to comment.