diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index ffc4466a33..6d33876806 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1435,7 +1435,6 @@ bool CStaticFunctionDefinitions::SetElementHealth(CClientEntity& Entity, float f // Set the new health Ped.SetHealth(fHealth); - return true; break; } case CCLIENTVEHICLE: diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp index 1b5da5c780..eca0a0debe 100644 --- a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp @@ -406,6 +406,7 @@ void CElementRPCs::SetElementHealth(CClientEntity* pSource, NetBitStreamInterfac case CCLIENTPLAYER: { CClientPed* pPed = static_cast(pSource); + if (pPed->IsHealthLocked()) pPed->LockHealth(fHealth); else @@ -416,6 +417,7 @@ void CElementRPCs::SetElementHealth(CClientEntity* pSource, NetBitStreamInterfac case CCLIENTVEHICLE: { CClientVehicle* pVehicle = static_cast(pSource); + pVehicle->SetHealth(fHealth); break; } @@ -424,6 +426,7 @@ void CElementRPCs::SetElementHealth(CClientEntity* pSource, NetBitStreamInterfac case CCLIENTWEAPON: { CClientObject* pObject = static_cast(pSource); + pObject->SetHealth(fHealth); break; } diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index f6af260975..0617c1fdce 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1601,6 +1601,7 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onElementModelChange", "oldModel, newModel", NULL, false); m_Events.AddEvent("onElementDimensionChange", "oldDimension, newDimension", nullptr, false); m_Events.AddEvent("onElementInteriorChange", "oldInterior, newInterior", nullptr, false); + m_Events.AddEvent("onElementHealthChange", "oldHealth, newHealth", nullptr, false); // Radar area events diff --git a/Server/mods/deathmatch/logic/CObject.cpp b/Server/mods/deathmatch/logic/CObject.cpp index c88dbf3e60..79aef8bb7d 100644 --- a/Server/mods/deathmatch/logic/CObject.cpp +++ b/Server/mods/deathmatch/logic/CObject.cpp @@ -450,3 +450,21 @@ CObject* CObject::GetLowLodObject() return NULL; return m_pLowLodObject; } + +void CObject::SetHealth(float fHealth) +{ + if (fHealth < 0.0f) + fHealth = 0.0; + + float fOldHealth = m_fHealth; + + if (fabs(fOldHealth - fHealth) >= FLOAT_EPSILON) + { + CLuaArguments arguments; + arguments.PushNumber(fOldHealth); + arguments.PushNumber(fHealth); + CallEvent("onElementHealthChange", arguments); + } + + m_fHealth = fHealth; +} diff --git a/Server/mods/deathmatch/logic/CObject.h b/Server/mods/deathmatch/logic/CObject.h index 9e2c23c360..f10a65b87e 100644 --- a/Server/mods/deathmatch/logic/CObject.h +++ b/Server/mods/deathmatch/logic/CObject.h @@ -63,7 +63,7 @@ class CObject : public CElement void SetFrozen(bool bFrozen) { m_bIsFrozen = bFrozen; } float GetHealth() { return m_fHealth; } - void SetHealth(float fHealth) { m_fHealth = fHealth; } + void SetHealth(float fHealth); bool IsSyncable() { return m_bSyncable; } void SetSyncable(bool bSyncable) { m_bSyncable = bSyncable; } diff --git a/Server/mods/deathmatch/logic/CPed.cpp b/Server/mods/deathmatch/logic/CPed.cpp index 0b2ba04d0d..aed479fdd5 100644 --- a/Server/mods/deathmatch/logic/CPed.cpp +++ b/Server/mods/deathmatch/logic/CPed.cpp @@ -523,3 +523,21 @@ void CPed::SetJackingVehicle(CVehicle* pVehicle) if (m_pJackingVehicle) m_pJackingVehicle->SetJackingPed(this); } + +void CPed::SetHealth(float fHealth) +{ + if (fHealth < 0.0f) + fHealth = 0.0; + + float fOldHealth = m_fHealth; + + if (fabs(fOldHealth - fHealth) >= FLOAT_EPSILON) + { + CLuaArguments arguments; + arguments.PushNumber(fOldHealth); + arguments.PushNumber(fHealth); + CallEvent("onElementHealthChange", arguments); + } + + m_fHealth = fHealth; +} diff --git a/Server/mods/deathmatch/logic/CPed.h b/Server/mods/deathmatch/logic/CPed.h index 00eee811ae..4b6abd99a8 100644 --- a/Server/mods/deathmatch/logic/CPed.h +++ b/Server/mods/deathmatch/logic/CPed.h @@ -171,7 +171,7 @@ class CPed : public CElement float GetMaxHealth(); float GetHealth() { return m_fHealth; } - void SetHealth(float fHealth) { m_fHealth = fHealth; } + void SetHealth(float fHealth); float GetArmor() { return m_fArmor; } void SetArmor(float fArmor) { m_fArmor = fArmor; } diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 81462c8377..fc099cda83 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1641,6 +1641,7 @@ bool CStaticFunctionDefinitions::SetElementHealth(CElement* pElement, float fHea { // Limit their max health to what the stat says float fMaxHealth = pPed->GetMaxHealth(); + if (fHealth > fMaxHealth) fHealth = fMaxHealth; @@ -1660,12 +1661,14 @@ bool CStaticFunctionDefinitions::SetElementHealth(CElement* pElement, float fHea case CElement::VEHICLE: { CVehicle* pVehicle = static_cast(pElement); + pVehicle->SetHealth(fHealth); break; } case CElement::OBJECT: { CObject* pObject = static_cast(pElement); + pObject->SetHealth(fHealth); break; } @@ -8663,7 +8666,7 @@ bool CStaticFunctionDefinitions::CreateExplosion(const CVector& vecPosition, uns if (pElement) { RUN_CHILDREN(CreateExplosion(vecPosition, ucType, *iter)) - + if (IS_PLAYER(pElement)) { CPlayer* player = static_cast(pElement); diff --git a/Server/mods/deathmatch/logic/CVehicle.cpp b/Server/mods/deathmatch/logic/CVehicle.cpp index ee5f7eb0e6..67bf0d84cc 100644 --- a/Server/mods/deathmatch/logic/CVehicle.cpp +++ b/Server/mods/deathmatch/logic/CVehicle.cpp @@ -531,6 +531,16 @@ void CVehicle::SetHealth(float fHealth) if (fHealth < 0.0f || IsBlown()) fHealth = 0.0f; + float fOldHealth = m_fHealth; + + if (fabs(fOldHealth - fHealth) >= FLOAT_EPSILON) + { + CLuaArguments arguments; + arguments.PushNumber(fOldHealth); + arguments.PushNumber(fHealth); + CallEvent("onElementHealthChange", arguments); + } + m_fHealth = fHealth; }