Skip to content

Commit

Permalink
Fix invincible peds (#777)
Browse files Browse the repository at this point in the history
* Fix invincible peds and ArranTuna issue

* Remove whitespaces

* Small fix, i forgot about this

* Update Client/mods/deathmatch/logic/CClientPed.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Clean up project comments

* Change task

Co-authored-by: Qais Patankar <qaisjp@gmail.com>
Co-authored-by: Patrik Juvonen <patrik@scope.studio>
  • Loading branch information
3 people committed Apr 20, 2020
1 parent a928d80 commit e43d34f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
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

0 comments on commit e43d34f

Please sign in to comment.