Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invincible peds #777

Merged
9 commits merged into from
Apr 20, 2020
28 changes: 15 additions & 13 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* (Shared logic for modifications)
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/CClientPed.cpp
* FILE: mods/deathmatch/logic/CClientPed.cpp
* PURPOSE: Ped entity class
*
*****************************************************************************/
Expand Down Expand Up @@ -1734,8 +1733,17 @@ void CClientPed::InternalSetHealth(float fHealth)
// Recheck we have a ped, ReCreateModel might destroy it
if (m_pPlayerPed)
{
// update dead state for peds
if (fHealth > 0 && IsDead())
{
m_bDead = false;
}

// Set the new health
m_pPlayerPed->SetHealth(fHealth);

// Recover from dead state to bring the ped back to life
m_pTaskManager->RemoveTask(TASK_PRIORITY_EVENT_RESPONSE_NONTEMP);
}
}
}
Expand Down Expand Up @@ -1884,16 +1892,10 @@ void CClientPed::Kill(eWeaponType weaponType, unsigned char ucBodypart, bool bSt
}
}
}
if (m_bIsLocalPlayer)
{
SetHealth(0.0f);
SetArmor(0.0f);
}
else
{
LockHealth(0.0f);
LockArmor(0.0f);
}

// set health and armor to 0
SetHealth(0.0f);
SetArmor(0.0f);

// Silently remove the ped satchels
DestroySatchelCharges(false, true);
Expand Down
10 changes: 9 additions & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
* PURPOSE: Lua static function definitions class
Expand Down Expand Up @@ -1596,6 +1596,14 @@ bool CStaticFunctionDefinitions::SetElementHealth(CElement* pElement, float fHea
// This makes sure the health is set to what will get reported
unsigned char ucHealth = static_cast<unsigned char>(fHealth * 1.25f);
fHealth = static_cast<float>(ucHealth) / 1.25f;

// update dead state for peds
if (fHealth > 0 && pPed->IsDead())
{
pPed->SetIsDead(false);
}

// set new health
pPed->SetHealth(fHealth);
}
else
Expand Down