YUNoCake Posted September 24, 2015 Share Posted September 24, 2015 (edited) 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 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 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 September 24, 2015 by YUNoCake Link to comment Share on other sites More sharing options...
gtaVmod Posted September 25, 2015 Share Posted September 25, 2015 that's easy: GET_PED_NEARBY_PEDS return array with handles, just store them and don't count twice. Link to comment Share on other sites More sharing options...
YUNoCake Posted September 25, 2015 Author Share Posted September 25, 2015 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. Link to comment Share on other sites More sharing options...
gtaVmod Posted September 25, 2015 Share Posted September 25, 2015 Any peds[arrSize] in your code stores (unique) handles for peds. BTW you declare/use them incorrectly, they are 8bytes wide elements. Link to comment Share on other sites More sharing options...
CamxxCore Posted September 25, 2015 Share Posted September 25, 2015 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 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 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. Link to comment Share on other sites More sharing options...
YUNoCake Posted September 25, 2015 Author Share Posted September 25, 2015 (edited) 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 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 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 September 25, 2015 by YUNoCake Link to comment Share on other sites More sharing options...
InfamousSabre Posted September 25, 2015 Share Posted September 25, 2015 If you just want to know when the player kills a ped, just check stats. Way easier than worrying about handles and duplicates Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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? Link to comment Share on other sites More sharing options...
InfamousSabre Posted September 26, 2015 Share Posted September 26, 2015 (edited) 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 September 26, 2015 by InfamousSabre jaky2008 1 Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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]; } } } }} Link to comment Share on other sites More sharing options...
InfamousSabre Posted September 26, 2015 Share Posted September 26, 2015 You're welcome. I'm sure someone will find it useful, even if it's too much for you decoy1212 1 Link to comment Share on other sites More sharing options...
gtaVmod Posted September 26, 2015 Share Posted September 26, 2015 InfamousSabre, can you please find hash for stat "Distance travelled in cars" for Michael and the same for Boats? Link to comment Share on other sites More sharing options...
CamxxCore Posted September 26, 2015 Share Posted September 26, 2015 (edited) 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 September 26, 2015 by CamxxCore InfamousSabre 1 Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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. Link to comment Share on other sites More sharing options...
CamxxCore Posted September 26, 2015 Share Posted September 26, 2015 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. InfamousSabre 1 Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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. Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 (edited) 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 September 26, 2015 by YUNoCake Link to comment Share on other sites More sharing options...
gtaVmod Posted September 26, 2015 Share Posted September 26, 2015 int killedPeds; STATS::STAT_GET_INT(GAMEPLAY::GET_HASH_KEY("KILLS_INNOCENTS"), &killedPeds, 1) Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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? Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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) Link to comment Share on other sites More sharing options...
gtaVmod Posted September 26, 2015 Share Posted September 26, 2015 try -1 Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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! 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. Link to comment Share on other sites More sharing options...
InfamousSabre Posted September 26, 2015 Share Posted September 26, 2015 (edited) 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 September 26, 2015 by InfamousSabre Link to comment Share on other sites More sharing options...
gtaVmod Posted September 26, 2015 Share Posted September 26, 2015 where did you find this "SP1_KILLS_INNOCENTS" ? Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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 ). where did you find this "SP1_KILLS_INNOCENTS" ? https://github.com/crosire/scripthookvdotnet/issues/179 Link to comment Share on other sites More sharing options...
YUNoCake Posted September 26, 2015 Author Share Posted September 26, 2015 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 InfamousSabre 1 Link to comment Share on other sites More sharing options...
InfamousSabre Posted September 26, 2015 Share Posted September 26, 2015 You got it! Link to comment Share on other sites More sharing options...
whorse Posted September 27, 2015 Share Posted September 27, 2015 (edited) 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 September 27, 2015 by whorse Link to comment Share on other sites More sharing options...
YUNoCake Posted September 27, 2015 Author Share Posted September 27, 2015 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 Link to comment Share on other sites More sharing options...
YUNoCake Posted September 28, 2015 Author Share Posted September 28, 2015 Hi, guys! Here's the mod I was talking about : https://www.gta5-mods.com/scripts/kill-frenzy It still needs a few things fixed and added, but that's mainly it. Thank you all again for help me, you are the best! Link to comment Share on other sites More sharing options...