What I am trying to do is giving back health to NPCs if they got hit in certain bones - this way I try to implement body part specific damage.
Example: if NPC01 was hit in the leg, check how much health it lost and give it back a part of it.
Somehow it wont work, though.
Here is the code I am using:
//modifiers for health not deducted for the affected body parts
float ini_legdamagemod = 0.99; // 99% of deducted health will be given back
float ini_armdamagemod = 0.99; // 99% of deducted health will be given back
float ini_torsodamagemod = 0.0; // 0% of deducted health will be given back
float ini_headdamagemod = 0.0; // 0% of deducted health will be given back
float ini_neckdamagemod = 0.0; // 0% of deducted health will be given back
//container for peds and a health value to calculate the body part damage
std::map<Ped, int> pedmaplimbhealth;
//container for affected bones
vector<int> legbones, armbones, torsobones, headbones, neckbones;
legbones.push_back(6884);
legbones.push_back(65478);
legbones.push_back(51120);
legbones.push_back(33646);
legbones.push_back(43312);
armbones.push_back(54187);
armbones.push_back(53675);
armbones.push_back(41357);
armbones.push_back(41341);
armbones.push_back(41405);
armbones.push_back(41326);
armbones.push_back(41325);
armbones.push_back(35876);
armbones.push_back(16829);
armbones.push_back(16781);
armbones.push_back(16765);
armbones.push_back(16749);
armbones.push_back(11300);
torsobones.push_back(14410);
torsobones.push_back(14411);
torsobones.push_back(14412);
torsobones.push_back(14413);
torsobones.push_back(14414);
torsobones.push_back(14415);
headbones.push_back(21030);
neckbones.push_back(14284);
neckbones.push_back(14285);
neckbones.push_back(14286);
neckbones.push_back(14287);
neckbones.push_back(14288);
while(true)
{
if (MOD IS ENABLED)
{
//get all peds near player
const int ARR_SIZE = 1024;
Ped peds[ARR_SIZE];
int count = worldGetAllPeds(peds, ARR_SIZE);
//filling the ped container
for (int i = 0; i < count; i++)
{
if (pedmaplimbhealth.find(peds[i]) == pedmaplimbhealth.end())
{
pedmaplimbhealth[peds[i]] = ENTITY::GET_ENTITY_HEALTH(peds[i]);
}
}
//checking if ped health has decreased and if so, give health back according to modifiers
if (pedmaplimbhealth[peds[i]] > ENTITY::GET_ENTITY_HEALTH(peds[i]))
{
float damagedone = pedmaplimbhealth[peds[i]] - ENTITY::GET_ENTITY_HEALTH(peds[i]);
int act_Bone;
if (PED::GET_PED_LAST_DAMAGE_BONE(peds[i], &act_Bone))
{
for (vector<int>::size_type i = 0; i != legbones.size(); i++)
{
if (act_Bone == PED::GET_PED_BONE_INDEX(peds[i], legbones[i]))
{
int healthback = (int)(damagedone * ini_legdamagemod);
if (ENTITY::GET_ENTITY_HEALTH(peds[i]) < ini_dyingmovementthreshold && (healthback + ENTITY::GET_ENTITY_HEALTH(peds[i])) > ini_dyingmovementthreshold) ENTITY::SET_ENTITY_HEALTH(peds[i], ini_dyingthreshold - 1, 0);
else ENTITY::SET_ENTITY_HEALTH(peds[i], ENTITY::GET_ENTITY_HEALTH(peds[i]) + healthback, 0);
pedmaplimbhealth[peds[i]] = ENTITY::GET_ENTITY_HEALTH(peds[i]);
PED::CLEAR_PED_LAST_DAMAGE_BONE(peds[i]);
}
}
for (vector<int>::size_type i = 0; i != armbones.size(); i++)
{
if (act_Bone == PED::GET_PED_BONE_INDEX(peds[i], armbones[i]))
{
int healthback = (int)(damagedone * ini_armdamagemod);
if (ENTITY::GET_ENTITY_HEALTH(peds[i]) < ini_dyingmovementthreshold && (healthback + ENTITY::GET_ENTITY_HEALTH(peds[i])) > ini_dyingmovementthreshold) ENTITY::SET_ENTITY_HEALTH(peds[i], ini_dyingthreshold - 1, 0);
else ENTITY::SET_ENTITY_HEALTH(peds[i], ENTITY::GET_ENTITY_HEALTH(peds[i]) + healthback, 0);
pedmaplimbhealth[peds[i]] = ENTITY::GET_ENTITY_HEALTH(peds[i]);
PED::CLEAR_PED_LAST_DAMAGE_BONE(peds[i]);
}
}
for (vector<int>::size_type i = 0; i != torsobones.size(); i++)
{
if (act_Bone == PED::GET_PED_BONE_INDEX(peds[i], torsobones[i]))
{
int healthback = (int)(damagedone * ini_torsodamagemod);
if (ENTITY::GET_ENTITY_HEALTH(peds[i]) < ini_dyingmovementthreshold && (healthback + ENTITY::GET_ENTITY_HEALTH(peds[i])) > ini_dyingmovementthreshold) ENTITY::SET_ENTITY_HEALTH(peds[i], ini_dyingthreshold - 1, 0);
else ENTITY::SET_ENTITY_HEALTH(peds[i], ENTITY::GET_ENTITY_HEALTH(peds[i]) + healthback, 0);
pedmaplimbhealth[peds[i]] = ENTITY::GET_ENTITY_HEALTH(peds[i]);
PED::CLEAR_PED_LAST_DAMAGE_BONE(peds[i]);
}
}
for (vector<int>::size_type i = 0; i != headbones.size(); i++)
{
if (act_Bone == PED::GET_PED_BONE_INDEX(peds[i], headbones[i]))
{
int healthback = (int)(damagedone * ini_headdamagemod);
if (ENTITY::GET_ENTITY_HEALTH(peds[i]) < ini_dyingmovementthreshold && (healthback + ENTITY::GET_ENTITY_HEALTH(peds[i])) > ini_dyingmovementthreshold) ENTITY::SET_ENTITY_HEALTH(peds[i], ini_dyingthreshold - 1, 0);
else ENTITY::SET_ENTITY_HEALTH(peds[i], ENTITY::GET_ENTITY_HEALTH(peds[i]) + healthback, 0);
pedmaplimbhealth[peds[i]] = ENTITY::GET_ENTITY_HEALTH(peds[i]);
PED::CLEAR_PED_LAST_DAMAGE_BONE(peds[i]);
}
}
for (vector<int>::size_type i = 0; i != neckbones.size(); i++)
{
if (act_Bone == PED::GET_PED_BONE_INDEX(peds[i], neckbones[i]))
{
int healthback = (int)(damagedone * ini_neckdamagemod);
if (ENTITY::GET_ENTITY_HEALTH(peds[i]) < ini_dyingmovementthreshold && (healthback + ENTITY::GET_ENTITY_HEALTH(peds[i])) > ini_dyingmovementthreshold) ENTITY::SET_ENTITY_HEALTH(peds[i], ini_dyingthreshold - 1, 0);
else ENTITY::SET_ENTITY_HEALTH(peds[i], ENTITY::GET_ENTITY_HEALTH(peds[i]) + healthback, 0);
pedmaplimbhealth[peds[i]] = ENTITY::GET_ENTITY_HEALTH(peds[i]);
PED::CLEAR_PED_LAST_DAMAGE_BONE(peds[i]);
}
}
}
}
}
}
For some reason the NPCs still keep dying from three or four leg shots (if health is set to 100).
Does anyone have any idea why that is the case?