Skip to content

Commit

Permalink
Always sync vehicles with synced peds
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Nov 7, 2023
1 parent 4a54851 commit 393a401
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions RageCoop.Client/Networking/Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using RageCoop.Client.Menus;
using RageCoop.Core;
using System;
using System.Linq;
using System.Threading;

namespace RageCoop.Client
Expand Down Expand Up @@ -306,7 +307,7 @@ private static void PedSync(Packets.PedSync packet)
if (c == null)
{
// Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}");
if (EntityPool.allPeds.Length < Main.Settings.GlobalPedSoftLimit || PlayerList.Players.ContainsKey(packet.ID))
if (EntityPool.allPeds.Length < Main.Settings.GlobalPedSoftLimit + PlayerList.Players.Count || PlayerList.Players.ContainsKey(packet.ID))
EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID));
else return;
}
Expand Down Expand Up @@ -356,7 +357,7 @@ private static void VehicleSync(Packets.VehicleSync packet)
SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
if (v == null)
{
if (EntityPool.allVehicles.Length < Main.Settings.GlobalVehicleSoftLimit)
if (EntityPool.allVehicles.Length < Main.Settings.GlobalVehicleSoftLimit || EntityPool.PedsByID.Any(x => x.Value.Position.DistanceTo(packet.Position) < 2f))
EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ID));
else return;
}
Expand Down
4 changes: 2 additions & 2 deletions RageCoop.Client/Sync/EntityPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void Cleanup(bool keepPlayer = true, bool keepMine = true)
PedsByID.Clear();
PedsByHandle.Clear();

foreach (int id in new List<int>(VehiclesByID.Keys))
foreach (int id in VehiclesByID.Keys.ToArray())
{
if (keepMine && (VehiclesByID[id].OwnerID == Main.LocalPlayerID)) { continue; }
RemoveVehicle(id);
Expand Down Expand Up @@ -359,11 +359,11 @@ public static void DoSync()
lock (PedsLock)
{
AddPlayer();
var mainCharacters = new List<PedHash> { PedHash.Michael, PedHash.Franklin, PedHash.Franklin02, PedHash.Trevor };

foreach (Ped p in allPeds)
{
SyncedPed c = GetPedByHandle(p.Handle);
List<PedHash> mainCharacters = new List<PedHash> { PedHash.Michael, PedHash.Franklin, PedHash.Franklin02, PedHash.Trevor };
if (c == null && p != Game.Player.Character && !mainCharacters.Contains((PedHash)p.Model.Hash))
{
if (allPeds.Length > Main.Settings.WorldPedSoftLimit && p.PopulationType == EntityPopulationType.RandomAmbient && !p.IsInVehicle())
Expand Down

0 comments on commit 393a401

Please sign in to comment.