MM, I think it’s becuase it’s a Server only function. In which case I fail to see why this method is available in a client side C# library when I’ve referenced CitizenFX.Core.Client nuget package. Why have a library that provides compile time access to methods which aren’t supposed to be available in that layer?
Does anyone have an example of using GetPedNearbyPeds(…) from C#?
OK, Thanks for the reply. So why when I’m standing next to peds do I get an empty list?
By the way the doco clearly shows it as server only
When I click “client” in the API Set selector the GetAllPeds function disappears.
But entHandle and handle are supposed to be written to multiple times before EndFindPed is reached and in my case it’s always -1. The World.GetAllPeds() also fails to find anything and it definitely calls EndFindPed
Thanks, will try it out.
WOuld be great if you could pass your own Expression<Func<…>> to add on where conditions rather than do it after the call. Encapsulate all in one go
I created extension methods for the Ped[] array that suit my needs. Can probably be optimized, but feel free to mess around with it.
Of course you can replace the .Where(x => ...) with whatever suits your needs. I just provided an example code that I know to be working on the versions I provided.
In my case, I need two different types of data from living peds, so I filter it after the fact.
public static class ExtensionMethods
{
/// <summary>
/// Retrieve the nearest human that's on foot
/// </summary>
/// <param name="peds"></param>
/// <param name="ped"></param>
/// <returns></returns>
public static Ped GetNearestHumanOnFoot(this Ped[] peds, Ped ped)
{
if (!(ped?.Exists() ?? false))
{
return default;
}
return peds?
.Where(x => (x?.IsHuman ?? false) && (!x?.IsInVehicle() ?? false))?
.OrderBy(x => x?.Position.DistanceToSquared(ped.Position))?
.FirstOrDefault();
}
/// <summary>
/// Retrieve the closest player ped
/// </summary>
/// <param name="peds"></param>
/// <param name="ped"></param>
/// <returns></returns>
public static Ped GetNearestPlayer(this Ped[] peds, Ped ped)
{
if (!(ped?.Exists() ?? false))
{
return default;
}
return peds?
.Where(x => x?.IsPlayer ?? false)?
.OrderBy(x => x?.Position.DistanceToSquared(ped.Position))?
.FirstOrDefault();
}
}