Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Trumple

Function args to PED::GET_PED_NEARBY_PEDS?

Recommended Posts

Trumple

Hi there,

 

I'm trying to use the function below:

Any GET_PED_NEARBY_PEDS(Any p0, Any *p1, Any p2)

Does anyone have any hints on what the arguments may be?

 

p0 is probably the player (or ped) that you want to search near.

 

I haven't seen any examples where you have to pass a pointer, though, so if anyone knows of a similar ped function that accepts a pointer that'd be really helpful for p1.

 

Lastly p2 I imagine is a radius limit but I'm not entirely sure.

 

Anyone have any hints? Or maybe any tips for discovering the correct arguments?

 

Edit: what I'm really trying to do is discover all peds within a radius of the player. If anyone knows of a better way that'd be really helpful!

 

Thanks in advance!

Edited by Trumple

Share this post


Link to post
Share on other sites
thewhitehammer99
GET_PED_NEARBY_PED(PLAYER : : PLAYER_PED_ID(), &num3, -1);

should do the job :)

Share this post


Link to post
Share on other sites
Trumple
GET_PED_NEARBY_PED(PLAYER : : PLAYER_PED_ID(), &num3, -1);

should do the job :)

 

 

Ah thanks, for anyone else interested the second argument is a pointer to an array. The array is filled with peds found nearby the ped supplied to the first argument.

Share this post


Link to post
Share on other sites
julionib

can you show a example of this in use in the SDK?

Share this post


Link to post
Share on other sites
Trumple

can you show a example of this in use in the SDK?

	Any* pedArr = new Any[8];	if (PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), pedArr, -1) > 0)	{	    for (int i = 0; i < 10; i++)	    {		    if (pedArr[i] > 0)                        //do something	    }	}

However, I cannot seem to get it to populate the array with anything other than 0's. The function itself returns 0 too. If anyone can figure this out, it'd be much appreciated

Edited by Trumple

Share this post


Link to post
Share on other sites
julionib

thx for the info, let me do some tests ^^

Share this post


Link to post
Share on other sites
julionib

Hey man this is working: well at least it detects peds that are close (10 or less imagine):

Any* pedArr = new Any[8];		PED::GET_PED_NEARBY_PEDS(playerPed, pedArr, -1);		for (int i = 0; i < 10; i++)		{			if (Exists(pedArr[i]) && (pedArr[i] != playerPed))				PED::EXPLODE_PED_HEAD(pedArr[i], 0x5FC3C11);		}

Exists is a method that i created that just call the does_entity_exists


thx guys, now i can proceeed with the madness ^^

Edited by julionib

Share this post


Link to post
Share on other sites
formel117

I think this function works the same as

PED::GET_PED_NEARBY_VEHICLES

I had to do some testing to get it working, but from what I've learned I think it's like this:

//Array to receive vehicles near ped, 100 to make sure it can fit as many as possibleVehicle veh[100];//The function returns an int which is how many vehicles it's found, int result = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), veh);//Simple loop to go through resultsfor(int i = 0; i < result; i++){    //Make sure it exists    if (veh != NULL && veh[i] != NULL && ENTITY::DOES_ENTITY_EXIST(veh[i]))    {        //Do what you want with veh[i]    }}
Edited by formel117

Share this post


Link to post
Share on other sites
Echelonc

Hey man this is working: well at least it detects peds that are close (10 or less imagine):

 

Any* pedArr = new Any[8];		PED::GET_PED_NEARBY_PEDS(playerPed, pedArr, -1);		for (int i = 0; i < 10; i++)		{			if (Exists(pedArr[i]) && (pedArr[i] != playerPed))				PED::EXPLODE_PED_HEAD(pedArr[i], 0x5FC3C11);		}

Exists is a method that i created that just call the does_entity_exists

 

 

thx guys, now i can proceeed with the madness ^^

Does that actually blow up their heads?

Share this post


Link to post
Share on other sites
Trumple

Hey man this is working: well at least it detects peds that are close (10 or less imagine):

 

Any* pedArr = new Any[8];		PED::GET_PED_NEARBY_PEDS(playerPed, pedArr, -1);		for (int i = 0; i < 10; i++)		{			if (Exists(pedArr[i]) && (pedArr[i] != playerPed))				PED::EXPLODE_PED_HEAD(pedArr[i], 0x5FC3C11);		}

Exists is a method that i created that just call the does_entity_exists

 

 

thx guys, now i can proceeed with the madness ^^

 

Thanks, but sadly this code doesn't work for me! Using the replacements you mentioned, I get this:

	Any* pedArr1 = new Any[8];	PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), pedArr1, -1);	for (int i = 0; i < 10; i++)	{		if (ENTITY::DOES_ENTITY_EXIST(pedArr1[i]) && (pedArr1[i] != PLAYER::PLAYER_PED_ID()))			PED::EXPLODE_PED_HEAD(pedArr1[i], 0x5FC3C11);	}	delete[] pedArr1;

It compiles, but doesn't do anything when called in-game. May I please see the rest of your code? Many thanks for any help.

Share this post


Link to post
Share on other sites
julionib

my code is inside the While that we have inside the Main method, when i press vk_rbutton it call that lines, the only difference is that i forget to delete the array, the explode head just make them die ^^

Share this post


Link to post
Share on other sites
metiri

 

Hey man this is working: well at least it detects peds that are close (10 or less imagine):

 

Any* pedArr = new Any[8];		PED::GET_PED_NEARBY_PEDS(playerPed, pedArr, -1);		for (int i = 0; i < 10; i++)		{			if (Exists(pedArr[i]) && (pedArr[i] != playerPed))				PED::EXPLODE_PED_HEAD(pedArr[i], 0x5FC3C11);		}

Exists is a method that i created that just call the does_entity_exists

 

 

thx guys, now i can proceeed with the madness ^^

 

Thanks, but sadly this code doesn't work for me! Using the replacements you mentioned, I get this:

	Any* pedArr1 = new Any[8];	PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), pedArr1, -1);	for (int i = 0; i < 10; i++)	{		if (ENTITY::DOES_ENTITY_EXIST(pedArr1[i]) && (pedArr1[i] != PLAYER::PLAYER_PED_ID()))			PED::EXPLODE_PED_HEAD(pedArr1[i], 0x5FC3C11);	}	delete[] pedArr1;

It compiles, but doesn't do anything when called in-game. May I please see the rest of your code? Many thanks for any help.

 

 

both of these crash my game the minute i try to run it :(

Share this post


Link to post
Share on other sites
moment0

Ok I think i've finally figured out what's going on. Two things, the 0 index element is the max count/array size, and there is padding on the array elements. For my machine, I am seeing each element padded by 1, regardless of whether I'm making an array of Ped or Any. This also applies to GET_PED_NEARBY_VEHICLES.

 

You will crash if you aren't indexing right because you will be reading garbage in the padding space.

 

I suppose R* has an internal array creation function to make this all easier and machine independent, but I have it working with the padding hardcoded. It would be nice for someone to make a clean way to create the array, but try this and see if it fixes your crash issues.

//Setup the array	const int numElements = 10;	const int arrSize = numElements * 2 + 2;  //Start at index 2, and the odd elements are padding	Any peds[arrSize];	//0 index is the size of the array	peds[0] = numElements;	int count = PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), peds, -1);	for (int i = 0; i < count; ++i)	{		int offsettedID = i * 2 + 2;		if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]))		{			PED::EXPLODE_PED_HEAD(peds[offsettedID], 0x5FC3C11);		}	}

Here's the equivalent for vehicles.

//Setup the array	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any veh[arrSize];	//0 index is the size of the array	veh[0] = numElements;	int count = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), veh);	if (veh != NULL)	{		//Simple loop to go through results		for (int i = 0; i < count; i++)		{			int offsettedID = i * 2 + 2;			//Make sure it exists			if (veh[offsettedID] != NULL && ENTITY::DOES_ENTITY_EXIST(veh[offsettedID]))			{				//Get all the peds in the vehicle				for (int j = -1; j <= 2; ++j)				{					Any ped = VEHICLE::GET_PED_IN_VEHICLE_SEAT(veh[offsettedID], j);					if (ped != NULL)					{						PED::EXPLODE_PED_HEAD(ped, 0x5FC3C11);					}				}			}		}	}

Finally, if you are still having trouble, clear the array with 0's (except the size element at index 0) and print the elements after the function call to see what's going down.

Share this post


Link to post
Share on other sites
Trumple

Ok I think i've finally figured out what's going on. Two things, the 0 index element is the max count/array size, and there is padding on the array elements. For my machine, I am seeing each element padded by 1, regardless of whether I'm making an array of Ped or Any. This also applies to GET_PED_NEARBY_VEHICLES.

 

You will crash if you aren't indexing right because you will be reading garbage in the padding space.

 

I suppose R* has an internal array creation function to make this all easier and machine independent, but I have it working with the padding hardcoded. It would be nice for someone to make a clean way to create the array, but try this and see if it fixes your crash issues.

//Setup the array	const int numElements = 10;	const int arrSize = numElements * 2 + 2;  //Start at index 2, and the odd elements are padding	Any peds[arrSize];	//0 index is the size of the array	peds[0] = numElements;	int count = PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), peds, -1);	for (int i = 0; i < count; ++i)	{		int offsettedID = i * 2 + 2;		if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]))		{			PED::EXPLODE_PED_HEAD(peds[offsettedID], 0x5FC3C11);		}	}

Here's the equivalent for vehicles.

//Setup the array	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any veh[arrSize];	//0 index is the size of the array	veh[0] = numElements;	int count = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), veh);	if (veh != NULL)	{		//Simple loop to go through results		for (int i = 0; i < count; i++)		{			int offsettedID = i * 2 + 2;			//Make sure it exists			if (veh[offsettedID] != NULL && ENTITY::DOES_ENTITY_EXIST(veh[offsettedID]))			{				//Get all the peds in the vehicle				for (int j = -1; j <= 2; ++j)				{					Any ped = VEHICLE::GET_PED_IN_VEHICLE_SEAT(veh[offsettedID], j);					if (ped != NULL)					{						PED::EXPLODE_PED_HEAD(ped, 0x5FC3C11);					}				}			}		}	}

Finally, if you are still having trouble, clear the array with 0's (except the size element at index 0) and print the elements after the function call to see what's going down.

 

Fantastic, thanks so much! I'll give that a go later.

Where PED::GET_PED_NEARBY_PEDS is used in the game, the array is usually created using a function called initArray, which accepts a pointer and a size parameter. I think that's the internal function you guessed at earlier. Sadly I do not know if we can access that function.

 

The fact its padded is weird. Probably means PED::GET_PED_NEARBY_PEDS actually returns an array of structures of some kind rather than simple Peds/longs.

 

However, it seems as though you've accurately guessed at what initArray does, which is good because that's used all over the place. Good job!

Edited by Trumple

Share this post


Link to post
Share on other sites
Fireboyd78

Sounds like it's returning a structure like this:

 

 

struct PED_ENTRY {  int unknown;  int pedID;}struct PED_ARRAY {  int count;  std::vector<PED_ARRAY> peds;}
I'm still a bit of a C++ dummy so the list thing is probably incorrect. I cannot test this because my computer is dead at the moment. Edited by CarLuver69

Share this post


Link to post
Share on other sites
julionib

thats odd, here that code works perfect, im using windows 7 sp1 + visual studio 2013, but i noticed something weird, if i declare the array as a local variable inside the method it seems to crash the Thread (only works again after save game/game load), but if i declare it global outside the method it works fine

Share this post


Link to post
Share on other sites
moment0

julionib, my first guess based on my testing is that you may be reading garbage which happens to be a valid integer for the size parameter, and you either don't have padding, or your padding was also some reasonable int value for entity checks. If I zeroed out my array, all entries would remain 0 because the size parameter was 0. If I didn't zero out my array, I would crash because the size parameter was some negative garbage value, which the function obviously did not like. If I made my array all 1's, the size parameter was 1, and only index 2 was overridden. That's how I came to the conclusion I did.

 

So I think that's a possibility for why your code worked for you but not for me and Trumple. It also would explain why your array had different behavior depending on if it was on the stack or the heap.

Share this post


Link to post
Share on other sites
Fireboyd78

I don't think it's returning a simple array with padding. Could someone try my code out?

Share this post


Link to post
Share on other sites
xsploit

I need help with

 

CLEAR_AREA_OF_PEDS

I pretty much want despawn all the peds on the map or even set all the peds to the same model, but i'm going to try this first.

Share this post


Link to post
Share on other sites
thewhitehammer99

I need help with

 

 

CLEAR_AREA_OF_PEDS

I pretty much want despawn all the peds on the map or even set all the peds to the same model, but i'm going to try this first.

void CLEAR_AREA_OF_PEDS(float *XCoord, float *YCoord, float *zCoord,

float Area, Any p4) // 0x25BE7FA8

Share this post


Link to post
Share on other sites
julionib

I don't think it's returning a simple array with padding. Could someone try my code out?

 

how would be the declaration of the variable? sorry, my c++ knownledge is limited

Share this post


Link to post
Share on other sites
julionib

Today i was having big issues with that code and then i tried this method that you guys talked about in previous posts:

//Setup the arrayconst int numElements = 10;const int arrSize = numElements * 2 + 2;Any veh[arrSize];//0 index is the size of the arrayveh[0] = numElements;int count = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), veh);

But applied the idea for the peds:

Any* pedsAround = new Any[102];void AIAttackTick(){	if (tickCount > reloadTargetsTick + 1000){		pedsAround[0] = 50;						int pedCount = PED::GET_PED_NEARBY_PEDS(playerPed, pedsAround, -1);						for (int c = 1; c <= pedCount; c++){

Its working fine, im just not sure about the "int c = 1;" in the For statement

Share this post


Link to post
Share on other sites
Fireboyd78

You declare it like any other type...

 

 

PED_ARRAY peds;peds.count = 10;// etc.
Also change the array declaration to a std::vector<PED_ENTRY>. Not "PED_ENTRY peds[count]" Edited by CarLuver69

Share this post


Link to post
Share on other sites
xsploit

Today i was having big issues with that code and then i tried this method that you guys talked about in previous posts:

 

 

//Setup the arrayconst int numElements = 10;const int arrSize = numElements * 2 + 2;Any veh[arrSize];//0 index is the size of the arrayveh[0] = numElements;int count = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), veh);

But applied the idea for the peds:

Any* pedsAround = new Any[102];void AIAttackTick(){	if (tickCount > reloadTargetsTick + 1000){		pedsAround[0] = 50;						int pedCount = PED::GET_PED_NEARBY_PEDS(playerPed, pedsAround, -1);						for (int c = 1; c <= pedCount; c++){

Its working fine, im just not sure about the "int c = 1;" in the For statement

hmm it's start ro look like this is what i need, just need to convert to lua

i hope one of these works with this code.

ENTITY::CREATE_MODEL_SWAP or PLAYER::SET_PLAYER_MODEL

if something like this works i can start setting up the ai to attack people that walk really close for a zombie mod

i did see a gta 4 infection mod and it goes beyond what i want to do

Share this post


Link to post
Share on other sites
wozzy

Ok I think i've finally figured out what's going on. Two things, the 0 index element is the max count/array size, and there is padding on the array elements. For my machine, I am seeing each element padded by 1, regardless of whether I'm making an array of Ped or Any. This also applies to GET_PED_NEARBY_VEHICLES.

 

You will crash if you aren't indexing right because you will be reading garbage in the padding space.

 

I suppose R* has an internal array creation function to make this all easier and machine independent, but I have it working with the padding hardcoded. It would be nice for someone to make a clean way to create the array, but try this and see if it fixes your crash issues.

//Setup the array	const int numElements = 10;	const int arrSize = numElements * 2 + 2;  //Start at index 2, and the odd elements are padding	Any peds[arrSize];	//0 index is the size of the array	peds[0] = numElements;	int count = PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), peds, -1);	for (int i = 0; i < count; ++i)	{		int offsettedID = i * 2 + 2;		if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]))		{			PED::EXPLODE_PED_HEAD(peds[offsettedID], 0x5FC3C11);		}	}

 

Thank you for this! I was having trouble with this method, and you're definitely right, it pads each element in the array

 

I've made a pull request for this fix in the .NET wrapper: https://github.com/crosire/scripthookvdotnet/pull/16

Share this post


Link to post
Share on other sites
xsploit

 

Ok I think i've finally figured out what's going on. Two things, the 0 index element is the max count/array size, and there is padding on the array elements. For my machine, I am seeing each element padded by 1, regardless of whether I'm making an array of Ped or Any. This also applies to GET_PED_NEARBY_VEHICLES.

 

You will crash if you aren't indexing right because you will be reading garbage in the padding space.

 

I suppose R* has an internal array creation function to make this all easier and machine independent, but I have it working with the padding hardcoded. It would be nice for someone to make a clean way to create the array, but try this and see if it fixes your crash issues.

//Setup the array	const int numElements = 10;	const int arrSize = numElements * 2 + 2;  //Start at index 2, and the odd elements are padding	Any peds[arrSize];	//0 index is the size of the array	peds[0] = numElements;	int count = PED::GET_PED_NEARBY_PEDS(PLAYER::PLAYER_PED_ID(), peds, -1);	for (int i = 0; i < count; ++i)	{		int offsettedID = i * 2 + 2;		if (ENTITY::DOES_ENTITY_EXIST(peds[offsettedID]))		{			PED::EXPLODE_PED_HEAD(peds[offsettedID], 0x5FC3C11);		}	}

Thank you for this! I was having trouble with this method, and you're definitely right, it pads each element in the array

 

I've made a pull request for this fix in the .NET wrapper: https://github.com/crosire/scripthookvdotnet/pull/16

 

how does this transfer to vb with all these arrays?

Share this post


Link to post
Share on other sites
unknown modder

You need to realise the natives are designed to be used in script files. in script files the array pointer contains the size of the array, and the arrays are 64 bits wide. anyway declare an array of uint64s 1 bigger than the max items to find, then set the first item to the max. then push the pointer to the first item. that should work fine, afterwards just do an int cast for each value in the array after first to get the handles, or you could use a struct

typedef struct{

int handle;

it padding;

} HandleArrayItem;

 

HandleArrayItem Handles[11];

Handles[0].handle = 10;

int max = GET_PED_NEARBY_PEDS(PlayerPed, &Handles[0].handle, -1);

for (int i = 1; i<= max; i++)

{

if (DOES_ENTITY_EXIST(Handles.handle))

{

//do stuff

}

}

Edited by unknown modder

Share this post


Link to post
Share on other sites
wozzy

how does this transfer to vb with all these arrays?

If you're using the Community Script Hook V .NET, you don't need to worry about passing pointers or padding, that's handled in the C++/CLI layer for you. You can use this method which returns an array:

 

Ped[] World.GetNearbyPeds(Ped ped, float radius, int maxAmount)
EDIT: Make sure you're using v0.4 or higher of the .NET wrapper

 

Example in VB.NET:

 

Dim peds() As Ped = World.GetNearbyPeds(Game.Player.Character, 55.0, 100)
peds is then an array that will contain all Peds within a radius of 55.0 units. World.GetNearbyVehicles() works the same way

 

55.0 actually seems to be the maximum radius that the native functions GET_NEARBY_PEDS and GET_NEARBY_VEHICLES will use, even if passed something greater, so these cannot be used to get all Peds/Vehicles

Edited by wozzy

Share this post


Link to post
Share on other sites
warchild66


UINT64 dwPeds[200] = {0};

dwPeds[0] = sizeof(dwPeds) / sizeof(UINT64) - 1;

PED::GET_PED_NEARBY_PEDS(playerPed, dwPeds, -1);

 

for (size_t i = 1; i < dwPeds[0]; ++i)

{

UINT64 ped = dwPeds;

}

Share this post


Link to post
Share on other sites
darkphoenixxx

When i do so the GET_PED_NEARBY_PEDS want int* , it aint talking Any* or UINT64* for an answer, is there some crazy way to cast pointers O_O?? What can i do to it?

Edited by darkphoenixxx

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.