Jump to content
View in the app

A better way to browse. Learn more.

RDR2Mods.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Native Details

  • NameGET_PED_NEARBY_PEDS
  • NamespacePED
  • Native Hash0x23F8F5FC7E8C4A6B
  • Typeint
  • First seen version1207

Native Parameters

  • Parameter 0Ped Ped
  • Parameter 1int* Peds
    Pointer to an array that will hold the found peds
  • Parameter 2int ignoredPedType
  • Parameter 3int p3

DESCRIPTION

Return is the number of peds found.

 


CODE EXAMPLE

// Original code from GTAForums modified for rdr2
int* pedArr = new int[8];
PED::GET_PED_NEARBY_PEDS(PLAYER::GET_PLAYER_PED(PLAYER::PLAYER_ID()), pedArr, -1,0);
	for (int i = 0; i < 10; i++) 
	{
		if (ENTITY::DOES_ENTITY_EXIST(pedArr[i]) && (pedArr[i] != PLAYER::GET_PLAYER_PED(PLAYER::PLAYER_ID())))
		{
			// Do something fun with your found peds here
		}	
	}
                           
delete[] pedArr;

User Feedback

Recommended Comments

Me myself and I

Members

For anyone using C#, I've had a couple headaches figuring it out, so here's my code:

Get ped nearby peds

unsafe List<Ped> GetNearbyPeds(Ped p, int maxPeds = 50) {

int[] buffer = new int[maxPeds * 2 + 2];

buffer[0] = maxPeds;

List<Ped> foundPeds = new List<Ped>();

fixed (int* pBuffer = buffer)

{

int foundCount = Function.Call<int>(Hash.GET_PED_NEARBY_PEDS, p, pBuffer, -1, 0);

for (int i = 0; i < foundCount; i++)

{

int pedHandle = buffer[i * 2 + 2];

Ped nearbyPed = new Ped(pedHandle);

foundPeds.Add(nearbyPed);

}

}

return foundPeds;

}

The function deals with a ton of memory, so it needs to be unsafe. For some reason, the first index for the buffer, where the list of handles will go, needs to have the amount of peds, and the second is garbage data, so it'll be empty. It starts at the 2 index, and every other index will be full of garbage. Using fixed (int* pBuffer = buffer) is required so that the garbage collector doesn't change the address of the buffer, which is why it's also used to create the pointer. The return of the function will contain the amount of peds found, which will usually, though not always, be the same amount as the amount of peds that you wanted. The function requires p, which will be the ped that we will search around, and the pointer to the buffer, though not the buffer itself, because it will change the data of the address that you give it. If you give it an object, it will crash. The -1 refers to the type of peds that will be filtered, and while I don't know what the other numbers do, -1 returns all peds. No one knows what the third argument does. Whenever you want to access a handle, you need to first skip the first two, which contain the amount of peds and garbage data respectively, and then multiply your index by two, because every other index has garbage data that will not hesitate to crash the game.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

Recently Browsing 0

  • No registered users viewing this page.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.