Skip to content

Commit cea089d

Browse files
authored
Update World.cs
1 parent d296980 commit cea089d

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

source/scripting_v3/RDR2/World.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,44 @@ public static T GetClosest<T>(Vector3 position, params T[] spatials) where T : I
198198
/// <summary>
199199
/// This method is not fully tested. It uses a straight import from ScriptHookRDR2.dll, and if it is returning 0, then it is *probably* a SHRDR2 issue.
200200
/// </summary>
201-
public static Ped GetClosestPed(Vector3 position, float radius)
201+
public static Ped GetClosestPed(Vector3 position)
202202
{
203-
int[] peds = new int[] { };
204-
RDR2DN.NativeMemory.getAllPeds(peds, 150);
205-
Ped[] newPeds = Array.ConvertAll(peds, handle => new Ped(handle));
206-
return GetClosest(position, newPeds);
203+
int[] peds = new int[1024];
204+
int entityCount = RDR2DN.NativeMemory.getAllPeds(peds, 1024);
205+
206+
List<Ped> Peds = new List<Ped>();
207+
for (int i = 0; i < entityCount; i++)
208+
Peds.Add(new Ped(peds[i]));
209+
210+
return GetClosest(position, Peds.ToArray());
207211
}
208212
/// <summary>
209213
/// This method is not fully tested. It uses a straight import from ScriptHookRDR2.dll, and if it is returning 0, then it is *probably* a SHRDR2 issue.
210214
/// </summary>
211-
public static Vehicle GetClosestVehicle(Vector3 position, float radius)
215+
public static Vehicle GetClosestVehicle(Vector3 position)
212216
{
213-
int[] vehs = new int[] { };
214-
RDR2DN.NativeMemory.getAllVehicles(vehs, 150);
215-
Vehicle[] newVehs = Array.ConvertAll(vehs, handle => new Vehicle(handle));
216-
return GetClosest(position, newVehs);
217+
int[] vehs = new int[1024];
218+
int entityCount = RDR2DN.NativeMemory.getAllVehicles(vehs, 1024);
219+
220+
List<Vehicle> Vehs = new List<Vehicle>();
221+
for (int i = 0; i < entityCount; i++)
222+
Vehs.Add(new Vehicle(vehs[i]));
217223

224+
return GetClosest(position, Vehs.ToArray());
218225
}
219226

227+
public static Prop GetClosestProp(Vector3 position)
228+
{
229+
int[] props = new int[1024];
230+
int count = RDR2DN.NativeMemory.getAllObjects(props, 1024);
231+
232+
List<Prop> Prop = new List<Prop>();
233+
for (int i = 0; i < count; i++)
234+
Prop.Add(new Prop(props[i]));
235+
236+
return GetClosest(position, Prop.ToArray());
237+
}
238+
220239
public static Ped CreatePed(PedHash hash, Vector3 position, float heading = 0f, bool isNet = true, bool isMission = true)
221240
{
222241
var model = new Model(hash);

0 commit comments

Comments
 (0)