whorse Posted July 13, 2015 Share Posted July 13, 2015 (edited) Hello, I am having some trouble with my first ASI mod, Melee Riot. I am very new to C++, and I began my mod by editing the source code for Kokolaty's "Provocateur" mod. However, after all this time developing it, I am still not clear on how the <Ped> array works, and Kokolaty is MIA. The script declares a variable called std::vector <Ped> peds; Then, it goes into an infinite while loop and "purges" the peds for every iteration: while (true){ //----------------------------------- //Purge "peds" for (int i = 0; i < peds.size(); i++) { if (!ENTITY::DOES_ENTITY_EXIST(peds.at(i))) { peds.erase(peds.begin() + i); break; } else if (canPedRiot(peds.at(i))) { ENTITY::SET_PED_AS_NO_LONGER_NEEDED(&peds.at(i)); peds.erase(peds.begin() + i); break; } else if (distanceBetween(player, peds.at(i)) > 600) { ENTITY::SET_PED_AS_NO_LONGER_NEEDED(&peds.at(i)); peds.erase(peds.begin() + i); break; } else if (PED::_IS_PED_DEAD(peds.at(i), true)) { peds.erase(peds.begin() + i); break; } else{ AI::TASK (do something) } } After that, the mod checks to see if the hotkey has been activated and does all this stuff to make them fight every x tics. What does it mean to set entities as no longer needed? That they will be deleted like normal when you get too far away or they die? Or that the script stops using them? I'm guessing I have to use peds.erase() on the valid rioters with every iteration because otherwise "peds" will grow infinitely? How can I have my mod just completely ignore one class of ped? By that I mean cops, in particular (I already excluded them in the canPedRiot method). If I do not use the "else" statement at the bottom of the above code, cops who stand around idle after I lose them will drop my frame rate by about 2-3 FPS per cop, even after I leave them behind and they disappear (then I have to load a new game to fix it). If I give them some kind of task inside the else statement, they will follow it and the lag will go away (if the task can hold their attention.) But this screws up their normal behavior, and lag still happens sometimes. In Provocateur, the else statement had the same targeting and combat instructions as the main "active" part of the mod, and yet no peds ever followed the combat commands when the mod was disabled (even though the "purge" section of the mod doesn't check to see if the mod is enabled or not). The PED::IS_PED_HUMAN native was used instead of my canPedRiot() method, though, so maybe it's just nothing valid was getting there. How can I just have the cops return to their default behavior while preventing any FPS lag? Is there any way to just have the mod completely not touch them at all? I notice that, if the mod is on, cops will frequently flee like scared civilians no matter what I try, even though they are excluded. Is it because of the way "peds" is handled? Lastly, what exactly does the command below do? Without it being at the end of all the fight commands, none of the peds will do anything. Here: peds.push_back(); Edited July 13, 2015 by whorse Link to comment Share on other sites More sharing options...
whorse Posted July 13, 2015 Author Share Posted July 13, 2015 (edited) neeevermind, I think I got it. I had to say else{ENTITY::SET_PED_AS_NO_LONGER_NEEDED(&peds.at(i)); peds.erase(peds.begin() + i);} with no "break;" That seems to make it so they don't cause huge lag when player's wanted level is lost (why did it lag in the first place?). I've wrongly thought to have fixed this problem several times in the past, though, so don't be surprised if I come back. I still would appreciate if anyone answered any of my questions about how <Ped> works, though EDIT: Oops! I was tired when I made this thread, I meant to put it in the "coding" section. If a mod could move it there I would appreciate it Edited July 14, 2015 by whorse Link to comment Share on other sites More sharing options...
C06alt Posted July 14, 2015 Share Posted July 14, 2015 (edited) ENTITY::SET_PED_AS_NO_LONGER_NEEDED does indeed remove an entity once it is out of range of the player. peds.push_back(); "push_back()" is a vector command that adds an item to the vector (array). in this case it seems tho you are adding an empty space to the array as it would usually look something like Ped ped = (put code to create or detect a ped here)peds.push_back(ped); This increases the size of the vector peds but since the loop removes any empty slots in the vector by detecting no entity it would correct its self but seems pointless. The following function could help you filter out cops but you could do it other ways. bool isPedACop(Ped ped){return (PED::GET_PED_RELATIONSHIP_GROUP_HASH(ped) == GAMEPLAY::GET_HASH_KEY("cop"));} Edited July 14, 2015 by C06alt whorse 1 Link to comment Share on other sites More sharing options...
whorse Posted July 15, 2015 Author Share Posted July 15, 2015 (edited) ENTITY::SET_PED_AS_NO_LONGER_NEEDED does indeed remove an entity once it is out of range of the player. peds.push_back(); "push_back()" is a vector command that adds an item to the vector (array). in this case it seems tho you are adding an empty space to the array as it would usually look something like Ped ped = (put code to create or detect a ped here)peds.push_back(ped); This increases the size of the vector peds but since the loop removes any empty slots in the vector by detecting no entity it would correct its self but seems pointless. The following function could help you filter out cops but you could do it other ways. bool isPedACop(Ped ped){return (PED::GET_PED_RELATIONSHIP_GROUP_HASH(ped) == GAMEPLAY::GET_HASH_KEY("cop"));} Thank you very much for the explanation! My mistake, in the OP it actually it says "peds.push_back(ped1);" and in the every-x-tics part of the mod, one of the conditions required to run the for-loop that issues all the fight-commands is that peds.size() must be greater than 1; I suppose that is maybe why I need to use peds.push_back(ped1)? Right now I am still having a problem with the cops, though not nearly as bad. I already have excluded them using a similar method to what you posted (as part of the canPedRiot() method, where I check to see if their "ped type" is 6). But still, when I have a wanted level and the cops are searching for me very far away (but still blipped on the map), my frame rate will start chugging to like 1/4th normal speed until I lose my wanted level. Why is this? Every single entity except for dead people and non-existant ones be getting marked as no longer needed, and everything in peds.size() gets deleted from the "peds" vector between every triggering of the mod. Should I manually use the "delete entity" native on distant cops, maybe using an if-statement nested inside the "distanceBetween() > 600" part of the purge? Also, I have another question (for anyone who can answer). Below is a simplified version of how the mod works: while (true){ //(*purge peds section here*) //(*check hotkey here, assign "active"*) tic++; if ((tic >= 75) && (active == true)) { tic = 0; const int numElements = 100; const int arrSize = (numElements+1) * sizeof(Any); Object nearbyPeds[arrSize]; nearbyPeds[0] = numElements; int numRioters = PED::GET_PED_NEARBY_PEDS(player, nearbyPeds, -1); if (nearbyPeds != NULL) { for (int i = 0; i < numRioters; i++) { int offsettedID = i * sizeof(Any) + 2; ped1 = nearbyPeds[offsettedID]; if (peds.size() > 1) { //(*mod body here, instructions for ped1*) } peds.push_back(ped1); } } }WAIT(0);} What is the reason for the arrSize and numElements values? Like, what happens when I change them? Could somebody break down to me how the whole for-statement cycling once for each of nearby ped works, and how the script knows to command only these nearby peds, even though GET_NEARBY_PEDS just returns an int? And finally, why do I need an "offsettedID" and why does it need to be "i" (the nearby ped's order in the list) times sizeof(Any) + 2 ? All this stuff I'm asking about was written by Kokolaty, and I've basically left it all alone since I started the mod Edited July 16, 2015 by whorse Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now