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

    1. GrandTheftAuto.net - Website Re-Launch

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

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

      1. Events
    1. Red Dead Redemption 2

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

    1. Grand Theft Auto Series

    2. GTA 6

    3. GTA V

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

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    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
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

YUNoCake

Counting peds killed (Script Hook V)

Recommended Posts

YUNoCake

So a few days ago I started developing a new mod and today I got stuck at this point: I need to count the pedestrians killed by the player, and when the counter reaches a value some other things will happen. The problem is my method counts deaths, but in a "strange" way, and by that I mean it's like : 0 dead pedestrians, I kill one pedestrian and it suddenly jumps to 8 pedestrians, or 12 or God knows how many :panic:

I know exactly why this happens: when a pedestrian dies, the game still counts it as a pedestrian and assigns it as being dead for a few seconds, and then it's considered as a entity. When my code checks for dead peds in the area, that certain ped is still considered as being dead and the counter goes up once again, and again, and again, untill the killed pedestrian is not considered as a ped anymore.

 

Anyways, I'm pretty sure nobody will ever understand my explanation, because I'm not very good at explaing code and it sounds better in my mind :lol:

I think you already got the point: I beg you guys, if you can, to help me modifying the code to make it work as it should, or if you know a better way to do it, why not, teach me.

Thanks in advice!

 

P.S.: Sorry if my English skills are not perfect.

//This is my subprogram that counts the dead pedsvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				deadPeds++;			}		}	}}
Edited by YUNoCake

Share this post


Link to post
Share on other sites
gtaVmod

that's easy: GET_PED_NEARBY_PEDS return array with handles, just store them and don't count twice.

Share this post


Link to post
Share on other sites
YUNoCake

that's easy: GET_PED_NEARBY_PEDS return array with handles, just store them and don't count twice.

Can you be more specific, please? I'm not sure what handles mean because I haven't learned programming in english and I only know some terms in my native language, but I'm pretty sure if I see the code I'll get it.

Share this post


Link to post
Share on other sites
gtaVmod

Any peds[arrSize] in your code stores (unique) handles for peds.

 

BTW you declare/use them incorrectly, they are 8bytes wide elements.

Share this post


Link to post
Share on other sites
CamxxCore

 

So a few days ago I started developing a new mod and today I got stuck at this point: I need to count the pedestrians killed by the player, and when the counter reaches a value some other things will happen. The problem is my method counts deaths, but in a "strange" way, and by that I mean it's like : 0 dead pedestrians, I kill one pedestrian and it suddenly jumps to 8 pedestrians, or 12 or God knows how many :panic:

I know exactly why this happens: when a pedestrian dies, the game still counts it as a pedestrian and assigns it as being dead for a few seconds, and then it's considered as a entity. When my code checks for dead peds in the area, that certain ped is still considered as being dead and the counter goes up once again, and again, and again, untill the killed pedestrian is not considered as a ped anymore.

 

Anyways, I'm pretty sure nobody will ever understand my explanation, because I'm not very good at explaing code and it sounds better in my mind :lol:

I think you already got the point: I beg you guys, if you can, to help me modifying the code to make it work as it should, or if you know a better way to do it, why not, teach me.

Thanks in advice!

 

P.S.: Sorry if my English skills are not perfect.

//This is my subprogram that counts the dead pedsvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				deadPeds++;			}		}	}}

 

Not sure what the mystery native is that you are using but there is a native for checking the killer of a ped. So maybe something like this would work better for you..

int playerKills;void UpdatePlayerKills(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	int* peds = new int[arrSize];	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]) && ENTITY::IS_ENTITY_DEAD(peds[offsettedID]))		{			Entity killer = PED::_GET_PED_KILLER(peds[offsettedID]);			if (killer == PLAYER::PLAYER_PED_ID())				playerKills++;		}	}}

But if I remember right, GET_PED_NEARBY_PEDS returns the handles of the dead peds as well. So you would probably have to keep track of the peds in a vector or something and then make sure they haven't already been counted.

Share this post


Link to post
Share on other sites
YUNoCake

 

 

So a few days ago I started developing a new mod and today I got stuck at this point: I need to count the pedestrians killed by the player, and when the counter reaches a value some other things will happen. The problem is my method counts deaths, but in a "strange" way, and by that I mean it's like : 0 dead pedestrians, I kill one pedestrian and it suddenly jumps to 8 pedestrians, or 12 or God knows how many :panic:

I know exactly why this happens: when a pedestrian dies, the game still counts it as a pedestrian and assigns it as being dead for a few seconds, and then it's considered as a entity. When my code checks for dead peds in the area, that certain ped is still considered as being dead and the counter goes up once again, and again, and again, untill the killed pedestrian is not considered as a ped anymore.

 

Anyways, I'm pretty sure nobody will ever understand my explanation, because I'm not very good at explaing code and it sounds better in my mind :lol:

I think you already got the point: I beg you guys, if you can, to help me modifying the code to make it work as it should, or if you know a better way to do it, why not, teach me.

Thanks in advice!

 

P.S.: Sorry if my English skills are not perfect.

//This is my subprogram that counts the dead pedsvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				deadPeds++;			}		}	}}

 

Not sure what the mystery native is that you are using but there is a native for checking the killer of a ped. So maybe something like this would work better for you..

int playerKills;void UpdatePlayerKills(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	int* peds = new int[arrSize];	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]) && ENTITY::IS_ENTITY_DEAD(peds[offsettedID]))		{			Entity killer = PED::_GET_PED_KILLER(peds[offsettedID]);			if (killer == PLAYER::PLAYER_PED_ID())				playerKills++;		}	}}

But if I remember right, GET_PED_NEARBY_PEDS returns the handles of the dead peds as well. So you would probably have to keep track of the peds in a vector or something and then make sure they haven't already been counted.

 

"So you would probably have to keep track of the peds in a vector or something and then make sure they haven't already been counted." - That's exactly what I was thinking (was not sure though). I will try it when I have time.

 

"Not sure what the mystery native is that you are using" - Sorry, forgot to comment it , "_0x3317DEDB88C95038" is the hash value of the "IS_PED_DEAD" native, which I think is the same as "IS_ENTITY_DEAD", but the entity one also works for vehicles when being destroyed.

Edited by YUNoCake

Share this post


Link to post
Share on other sites
InfamousSabre

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

Share this post


Link to post
Share on other sites
YUNoCake

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

 

Can you be more specific, please? What native should I more exactly use?

Share this post


Link to post
Share on other sites
InfamousSabre

 

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

Can you be more specific, please? What native should I more exactly use?

 

Figure it out.

 

You want STATS. Look in the STATS namespace. [162 Natives]

You want to GET stats. Look for the word GET in the native. [14 Natives]

You want STATS. Look for the word STAT in the native. [9 Natives]

A stat representing how many peds a player killed will always only be a whole number as you cant kill half a ped. What data type is that? Look for that data type in the native [2 Natives]

Make a judgement call on those last 2. Which one would you think it is? I'd go for the simpler one that doesn't have any extra words we aren't looking for.

 

How do I use it?

Good question, really.

For stats, you need the hash of the stat, but before we get the hash, we need the stat's name. Let's search for clues.

Start up OpenIV, go to Tools, and click Search. Type "stats", click Search. multiple files will come up. It should be pretty obvious which one we need to look into, as its one of the very first that will show up. Right click it, then click Open. It should open up in a text reader.

Oh, my! A list! How nice. You can see all the stat names right there in plain text. Find the one you're looking for and use that.

 

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

 

But wait! Thats a name! I need a hash!

Yes, of course. use Hash GAMEPLAY::GET_HASH_KEY(char *value) to get the hash key from the stat name.

 

What are these other parameters for?

Well, one is surely an output param. You need to supply it with a previously declared variable to use as a 'container' of sorts for your output. Heres psuedocode:

void NAMESPACE::NATIVE_IM_USING(float *outValue, BOOL p2) //native I'm using. Ignore this line. It's just to show you what the native is.float myValue; //declare a variable to use as a container for outputNAMESPACE::NATIVE_IM_USING(&myValue, 1); //fill that container with outputDisplayText(myValue); //use output.

For the rest of the params, check the decompiled scripts. sometimes they just always use the same value, and basically have no purpose. (none that we currently know of, at least)

 

This should more or less be your logic and process for anything you're trying to do when scripting for GTA.

Asking for help should be your last resort.

 

Sometimes it doesn't go this easy. If it doesn't, just keep trying different things. Look for different approaches, and try to think about how R* would have done it. Where might you be able to find some clues?

When you figure it out, don't be afraid to share your findings with the community.

Edited by InfamousSabre
  • Like 1

Share this post


Link to post
Share on other sites
YUNoCake

 

 

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

Can you be more specific, please? What native should I more exactly use?

 

Figure it out.

 

You want STATS. Look in the STATS namespace. [162 Natives]

You want to GET stats. Look for the word GET in the native. [14 Natives]

You want STATS. Look for the word STAT in the native. [9 Natives]

A stat representing how many peds a player killed will always only be a whole number as you cant kill half a ped. What data type is that? Look for that data type in the native [2 Natives]

Make a judgement call on those last 2. Which one would you think it is? I'd go for the simpler one that doesn't have any extra words we aren't looking for.

 

How do I use it?

Good question, really.

For stats, you need the hash of the stat, but before we get the hash, we need the stat's name. Let's search for clues.

Start up OpenIV, go to Tools, and click Search. Type "stats", click Search. multiple files will come up. It should be pretty obvious which one we need to look into, as its one of the very first that will show up. Right click it, then click Open. It should open up in a text reader.

Oh, my! A list! How nice. You can see all the stat names right there in plain text. Find the one you're looking for and use that.

 

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

 

But wait! Thats a name! I need a hash!

Yes, of course. use Hash GAMEPLAY::GET_HASH_KEY(char *value) to get the hash key from the stat name.

 

What are these other parameters for?

Well, one is surely an output param. You need to supply it with a previously declared variable to use as a 'container' of sorts for your output. Heres psuedocode:

void NAMESPACE::NATIVE_IM_USING(float *outValue, BOOL p2) //native I'm using. Ignore this line. It's just to show you what the native is.float myValue; //declare a variable to use as a container for outputNAMESPACE::NATIVE_IM_USING(&myValue, 1); //fill that container with outputDisplayText(myValue); //use output.

For the rest of the params, check the decompiled scripts. sometimes they just always use the same value, and basically have no purpose. (none that we currently know of, at least)

 

This should more or less be your logic and process for anything you're trying to do when scripting for GTA.

Asking for help should be your last resort.

 

Sometimes it doesn't go this easy. If it doesn't, just keep trying different things. Look for different approaches, and try to think about how R* would have done it. Where might you be able to find some clues?

When you figure it out, don't be afraid to share your findings with the community.

 

 

Thanks, but that's way too much work for my lazy ass. Instead I've done this and it works like a charm:

Any killedPeds[100]; //In my mod I never have to count more than 50-60 dead peds, so 100 is more than enoughvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				bool alreadyKilled = false;				for (int j = 0; j <= deadPeds; j++)				{					if (killedPeds[j] == peds[offsettedID])					{						alreadyKilled = true;						j = deadPeds + 1;					}				}				if (alreadyKilled == false)				{					deadPeds++;					killedPeds[deadPeds] = peds[offsettedID];				}			}		}	}}

Share this post


Link to post
Share on other sites
InfamousSabre

You're welcome. I'm sure someone will find it useful, even if it's too much for you :)

  • Like 1

Share this post


Link to post
Share on other sites
gtaVmod

 

InfamousSabre, can you please find hash for stat "Distance travelled in cars" for Michael and the same for Boats?

 

Share this post


Link to post
Share on other sites
CamxxCore

 

 

 

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

 

Can you be more specific, please? What native should I more exactly use?

 

Figure it out.

You want STATS. Look in the STATS namespace. [162 Natives]

You want to GET stats. Look for the word GET in the native. [14 Natives]

You want STATS. Look for the word STAT in the native. [9 Natives]

A stat representing how many peds a player killed will always only be a whole number as you cant kill half a ped. What data type is that? Look for that data type in the native [2 Natives]

Make a judgement call on those last 2. Which one would you think it is? I'd go for the simpler one that doesn't have any extra words we aren't looking for.

 

How do I use it?

Good question, really.

For stats, you need the hash of the stat, but before we get the hash, we need the stat's name. Let's search for clues.

Start up OpenIV, go to Tools, and click Search. Type "stats", click Search. multiple files will come up. It should be pretty obvious which one we need to look into, as its one of the very first that will show up. Right click it, then click Open. It should open up in a text reader.

Oh, my! A list! How nice. You can see all the stat names right there in plain text. Find the one you're looking for and use that.

 

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

 

But wait! Thats a name! I need a hash!

Yes, of course. use Hash GAMEPLAY::GET_HASH_KEY(char *value) to get the hash key from the stat name.

 

What are these other parameters for?

Well, one is surely an output param. You need to supply it with a previously declared variable to use as a 'container' of sorts for your output. Heres psuedocode:

 

void NAMESPACE::NATIVE_IM_USING(float *outValue, BOOL p2) //native I'm using. Ignore this line. It's just to show you what the native is.float myValue; //declare a variable to use as a container for outputNAMESPACE::NATIVE_IM_USING(&myValue, 1); //fill that container with outputDisplayText(myValue); //use output.
For the rest of the params, check the decompiled scripts. sometimes they just always use the same value, and basically have no purpose. (none that we currently know of, at least)

 

This should more or less be your logic and process for anything you're trying to do when scripting for GTA.

Asking for help should be your last resort.

 

Sometimes it doesn't go this easy. If it doesn't, just keep trying different things. Look for different approaches, and try to think about how R* would have done it. Where might you be able to find some clues?

When you figure it out, don't be afraid to share your findings with the community.

 

Thanks, but that's way too much work for my lazy ass. Instead I've done this and it works like a charm:

 

Any killedPeds[100]; //In my mod I never have to count more than 50-60 dead peds, so 100 is more than enoughvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				bool alreadyKilled = false;				for (int j = 0; j <= deadPeds; j++)				{					if (killedPeds[j] == peds[offsettedID])					{						alreadyKilled = true;						j = deadPeds + 1;					}				}				if (alreadyKilled == false)				{					deadPeds++;					killedPeds[deadPeds] = peds[offsettedID];				}			}		}	}}
The method may work but there is still some things you aren't considering. You are only checking if the ped is dead, not who killed it. So if there was already 4 or 5 dead peds around the player, those are going to be counted as well. And since you are using a fixed size array, you might go out of bounds and run into problems. Edited by CamxxCore
  • Like 1

Share this post


Link to post
Share on other sites
YUNoCake

 

 

 

 

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

Can you be more specific, please? What native should I more exactly use?

Figure it out.

You want STATS. Look in the STATS namespace. [162 Natives]

You want to GET stats. Look for the word GET in the native. [14 Natives]

You want STATS. Look for the word STAT in the native. [9 Natives]

A stat representing how many peds a player killed will always only be a whole number as you cant kill half a ped. What data type is that? Look for that data type in the native [2 Natives]

Make a judgement call on those last 2. Which one would you think it is? I'd go for the simpler one that doesn't have any extra words we aren't looking for.

 

How do I use it?

Good question, really.

For stats, you need the hash of the stat, but before we get the hash, we need the stat's name. Let's search for clues.

Start up OpenIV, go to Tools, and click Search. Type "stats", click Search. multiple files will come up. It should be pretty obvious which one we need to look into, as its one of the very first that will show up. Right click it, then click Open. It should open up in a text reader.

Oh, my! A list! How nice. You can see all the stat names right there in plain text. Find the one you're looking for and use that.

 

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

 

But wait! Thats a name! I need a hash!

Yes, of course. use Hash GAMEPLAY::GET_HASH_KEY(char *value) to get the hash key from the stat name.

 

What are these other parameters for?

Well, one is surely an output param. You need to supply it with a previously declared variable to use as a 'container' of sorts for your output. Heres psuedocode:

 

void NAMESPACE::NATIVE_IM_USING(float *outValue, BOOL p2) //native I'm using. Ignore this line. It's just to show you what the native is.float myValue; //declare a variable to use as a container for outputNAMESPACE::NATIVE_IM_USING(&myValue, 1); //fill that container with outputDisplayText(myValue); //use output.
For the rest of the params, check the decompiled scripts. sometimes they just always use the same value, and basically have no purpose. (none that we currently know of, at least)

 

This should more or less be your logic and process for anything you're trying to do when scripting for GTA.

Asking for help should be your last resort.

 

Sometimes it doesn't go this easy. If it doesn't, just keep trying different things. Look for different approaches, and try to think about how R* would have done it. Where might you be able to find some clues?

When you figure it out, don't be afraid to share your findings with the community.

Thanks, but that's way too much work for my lazy ass. Instead I've done this and it works like a charm:

 

Any killedPeds[100]; //In my mod I never have to count more than 50-60 dead peds, so 100 is more than enoughvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				bool alreadyKilled = false;				for (int j = 0; j <= deadPeds; j++)				{					if (killedPeds[j] == peds[offsettedID])					{						alreadyKilled = true;						j = deadPeds + 1;					}				}				if (alreadyKilled == false)				{					deadPeds++;					killedPeds[deadPeds] = peds[offsettedID];				}			}		}	}}
The method may work but there is still some things you aren't considering. You are only checking if the ped is dead, not who killed it. So if there was already 4 or 5 dead peds around the player, those are going to be counted as well. And since you are using a fixed size array, you might go out of bounds and run into problems.

 

 

In certain situations yes, but for what I need I will never roun out of boundaries. I have tested the mod few times and no, the peds that are already dead do not count, because, as I said, a few seconds after the ped is dead it is not considered a ped anymore (or atleast not a dead ped). But, I've got another problem now : the PED::GET_PED_NEARBY_PEDS native only gets peds from a small radius and if I kill a ped from a distance of like 50 meters it does not count. I don't like to admit it, and I'm feeling tired already when thinking about the time it's going to take, but I will be forced to use InfamousSabre's method.

Share this post


Link to post
Share on other sites
CamxxCore

 

 

 

 

 

If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates

 

Can you be more specific, please? What native should I more exactly use?

Figure it out.

You want STATS. Look in the STATS namespace. [162 Natives]

You want to GET stats. Look for the word GET in the native. [14 Natives]

You want STATS. Look for the word STAT in the native. [9 Natives]

A stat representing how many peds a player killed will always only be a whole number as you cant kill half a ped. What data type is that? Look for that data type in the native [2 Natives]

Make a judgement call on those last 2. Which one would you think it is? I'd go for the simpler one that doesn't have any extra words we aren't looking for.

How do I use it?

Good question, really.

For stats, you need the hash of the stat, but before we get the hash, we need the stat's name. Let's search for clues.

Start up OpenIV, go to Tools, and click Search. Type "stats", click Search. multiple files will come up. It should be pretty obvious which one we need to look into, as its one of the very first that will show up. Right click it, then click Open. It should open up in a text reader.

Oh, my! A list! How nice. You can see all the stat names right there in plain text. Find the one you're looking for and use that.

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

But wait! Thats a name! I need a hash!

Yes, of course. use Hash GAMEPLAY::GET_HASH_KEY(char *value) to get the hash key from the stat name.

What are these other parameters for?

Well, one is surely an output param. You need to supply it with a previously declared variable to use as a 'container' of sorts for your output. Heres psuedocode:

void NAMESPACE::NATIVE_IM_USING(float *outValue, BOOL p2) //native I'm using. Ignore this line. It's just to show you what the native is.float myValue; //declare a variable to use as a container for outputNAMESPACE::NATIVE_IM_USING(&myValue, 1); //fill that container with outputDisplayText(myValue); //use output.
For the rest of the params, check the decompiled scripts. sometimes they just always use the same value, and basically have no purpose. (none that we currently know of, at least)

This should more or less be your logic and process for anything you're trying to do when scripting for GTA.

Asking for help should be your last resort.

 

Sometimes it doesn't go this easy. If it doesn't, just keep trying different things. Look for different approaches, and try to think about how R* would have done it. Where might you be able to find some clues?

When you figure it out, don't be afraid to share your findings with the community.

Thanks, but that's way too much work for my lazy ass. Instead I've done this and it works like a charm:

Any killedPeds[100]; //In my mod I never have to count more than 50-60 dead peds, so 100 is more than enoughvoid checkIfDead(){	const int numElements = 10;	const int arrSize = numElements * 2 + 2;	Any peds[arrSize];	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]))		{			if (PED::_0x3317DEDB88C95038(peds[offsettedID], 1))			{				bool alreadyKilled = false;				for (int j = 0; j <= deadPeds; j++)				{					if (killedPeds[j] == peds[offsettedID])					{						alreadyKilled = true;						j = deadPeds + 1;					}				}				if (alreadyKilled == false)				{					deadPeds++;					killedPeds[deadPeds] = peds[offsettedID];				}			}		}	}}
The method may work but there is still some things you aren't considering. You are only checking if the ped is dead, not who killed it. So if there was already 4 or 5 dead peds around the player, those are going to be counted as well. And since you are using a fixed size array, you might go out of bounds and run into problems.

 

In certain situations yes, but for what I need I will never roun out of boundaries. I have tested the mod few times and no, the peds that are already dead do not count, because, as I said, a few seconds after the ped is dead it is not considered a ped anymore (or atleast not a dead ped). But, I've got another problem now : the PED::GET_PED_NEARBY_PEDS native only gets peds from a small radius and if I kill a ped from a distance of like 50 meters it does not count. I don't like to admit it, and I'm feeling tired already when thinking about the time it's going to take, but I will be forced to use InfamousSabre's method.

No reason to feel overwhelmed. All you need to do is find the stat hash. The rest is history.

  • Like 1

Share this post


Link to post
Share on other sites
YUNoCake

Found the stats that I need

    <stat Name="KILLS_INNOCENTS"              Type="int"    SaveCategory="1"   online="true"  profile="false"   Owner="coder"   characterStat="true"  Comment="Number of ped's killed" />    <stat Name="KILLS_COP"                    Type="int"    SaveCategory="1"   online="true"  profile="true"    Owner="coder"   characterStat="true"  Comment="Number of Cops killed" />    <stat Name="KILLS_SWAT"                   Type="int"    SaveCategory="1"   online="true"  profile="true"    Owner="coder"   characterStat="true"  Comment="Number of Swat killed" />    <stat Name="KILLS_ENEMY_GANG_MEMBERS"     Type="int"    SaveCategory="1"   online="true"  profile="false"   Owner="coder"   characterStat="true"  Comment="Enemy Gang members killed" />    <stat Name="KILLS_FRIENDLY_GANG_MEMBERS"  Type="int"    SaveCategory="1"   online="true"  profile="false"   Owner="coder"   characterStat="true"  Comment="Friendly Gang members killed" />

I will now try to get the hashes.

Share this post


Link to post
Share on other sites
YUNoCake

So I wrote a small script to get the five hashes I needed.

#include "script.h"#include <fstream>void main(){	std::ofstream fout("hash.txt");	Any hash1,hash2,hash3,hash4,hash5;	hash1 = GAMEPLAY::GET_HASH_KEY("KILLS_INNOCENTS");	hash2 = GAMEPLAY::GET_HASH_KEY("KILLS_COP");	hash3 = GAMEPLAY::GET_HASH_KEY("KILLS_SWAT");	hash4 = GAMEPLAY::GET_HASH_KEY("KILLS_ENEMY_GANG_MEMBERS");	hash5 = GAMEPLAY::GET_HASH_KEY("KILLS_FRIENDLY_GANG_MEMBERS");	fout << hash1 << '\n' << hash2 << '\n' << hash3 << '\n' << hash4 << '\n' << hash5;}void ScriptMain(){	main();}

The "hash.txt" file says:

415692660626840543373606726964863569692619890975

What now? Should I use something like this?

int killedPeds;STATS::STAT_GET_INT(4156926606, killedPeds, 1)

EDIT: WOW, actually there is a website that does all this work (tested it and it gave me the same results) -> http://gta5hasher.glokon.org/

Edited by YUNoCake

Share this post


Link to post
Share on other sites
gtaVmod


int killedPeds;

STATS::STAT_GET_INT(GAMEPLAY::GET_HASH_KEY("KILLS_INNOCENTS"), &killedPeds, 1)

Share this post


Link to post
Share on other sites
YUNoCake
int killedPeds;STATS::STAT_GET_INT(GAMEPLAY::GET_HASH_KEY("KILLS_INNOCENTS"), &killedPeds, 1)

 

Oh, right :)) I shouldn't have struggled with that other script, but hey : it's the same thing, isn't it?

Share this post


Link to post
Share on other sites
YUNoCake

Well, I've added this code to my script and it gives me a random 10 digit value everytime, sometimes even a negative value. I think it's because of that "1", which I tried changing to 0 and 2 and the same thing happens. Anybody knows what value should the third argument have?

int killedPeds;STATS::STAT_GET_INT(GAMEPLAY::GET_HASH_KEY("KILLS_INNOCENTS"), &killedPeds, 1)

Share this post


Link to post
Share on other sites
YUNoCake

try -1

 

Yup, that's right. Did some research and found out the 3rd argument is -1 and, the most important : the correct syntax of the code is this:

int killedPeds;STATS::STAT_GET_INT(GAMEPLAY::GET_HASH_KEY("SP1_KILLS_INNOCENTS"), &killedPeds, -1)//SP1 meaning SinglePlayer character 1 (that's Franklin, 0 is for Michael and 2 for Trevor)

Thank you all very much! This is now working thanks to you! Awesome forum, keep it up! :lol:

 

I'll get back if I encounter issues, and when the mod is done and uploaded I'll post a link here for you guys to see the results.

Share this post


Link to post
Share on other sites
InfamousSabre

You're making it way more complicated than it needs to be.

How do I know what I'm looking for?
You're looking for KILLS, are you not? [66 Stats]
Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
gtaVmod

where did you find this "SP1_KILLS_INNOCENTS" ?

Share this post


Link to post
Share on other sites
YUNoCake

 

You're making it way more complicated than it needs to be.

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

 

I did not found such a stat, plus it's not that complicated and now that I can track if the player ped killed a normal ped, a cop or a swat, I can implement cash rewards for killing cops, respective bigger rewards for killing swat troups (you will see when the mode is done :lol:).

 

 

where did you find this "SP1_KILLS_INNOCENTS" ?

https://github.com/crosire/scripthookvdotnet/issues/179

Share this post


Link to post
Share on other sites
YUNoCake

 

You're making it way more complicated than it needs to be.

How do I know what I'm looking for?

You're looking for KILLS, are you not? [66 Stats]

Most of these are for kills with a specific weapon, but we want TOTAL kills [1 Stat]

 

Oh, think I found it. You meant this?

TOTAL_LEGITIMATE_KILLS
  • Like 1

Share this post


Link to post
Share on other sites
InfamousSabre

You got it!

Share this post


Link to post
Share on other sites
whorse

I realize you're past this, but GET_PED_NEARBY_PEDS only has a max range of 55, and can only return the 16 closest peds. You can get sort of get around this by retaining the peds in a std::vector<Ped> container, but really don't have to use GET_PED_NEARBY_PEDS at all anymore. Since the v1.0.393.4a version of ScriptHookV (the patch before last), Alexander Blade has put in three functions to fetch all the entities in the "active entity" pool (any in memory) by their type - peds, vehicles and objects:

std::vector<Ped> peds;const int ARR_SIZE = 1024; //max size of array to hold all the pedsPed worldPeds[ARR_SIZE]; //array to hold all the pedsint count = worldGetAllPeds(worldPeds, ARR_SIZE); //fills up worldPeds array with peds, and returns the number of peds found as an int in count (just like GET_PED_NEARBY_PEDS)for (int i = 0; i < count; i++){     if (canAddPed(worldPeds[i])) //made-up function          peds.push_back(worldPeds[i]); //move the peds you want from the array to the vector}//You can also use this in exactly the same way with objects and vehicles, using:int worldGetAllVehicles(int *arr, int arrSize);//andint worldGetAllObjects(int *arr, int arrSize);

I pasted this in from a thread I made in the documentation section

Edited by whorse

Share this post


Link to post
Share on other sites
YUNoCake

I realize you're past this, but GET_PED_NEARBY_PEDS only has a max range of 55, and can only return the 16 closest peds. You can get sort of get around this by retaining the peds in a std::vector<Ped> container, but really don't have to use GET_PED_NEARBY_PEDS at all anymore. Since the v1.0.393.4a version of ScriptHookV (the patch before last), Alexander Blade has put in three functions to fetch all the entities in the "active entity" pool (any in memory) by their type - peds, vehicles and objects:

std::vector<Ped> peds;const int ARR_SIZE = 1024; //max size of array to hold all the pedsPed worldPeds[ARR_SIZE]; //array to hold all the pedsint count = worldGetAllPeds(worldPeds, ARR_SIZE); //fills up worldPeds array with peds, and returns the number of peds found as an int in count (just like GET_PED_NEARBY_PEDS)for (int i = 0; i < count; i++){     if (canAddPed(worldPeds[i])) //made-up function          peds.push_back(worldPeds[i]); //move the peds you want from the array to the vector}//You can also use this in exactly the same way with objects and vehicles, using:int worldGetAllVehicles(int *arr, int arrSize);//andint worldGetAllObjects(int *arr, int arrSize);

I pasted this in from a thread I made in the documentation section

 

Thank you ! That's very useful information in your thread, it may help me in the future :)

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.

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.


  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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