Skip to content

Fix client-side createExplosion not triggering onClientExplosion event #4341

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

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
48cde4d
Fix onClientExplosion event not firing for client-side createExplosio…
MohabCodeX Aug 4, 2025
0f011ef
Merge branch 'master' into fix/explosion-trigger-clientside
MohabCodeX Aug 5, 2025
1566e91
Add GetWeaponTypeFromExplosionType and refactor explosion logic
MohabCodeX Aug 5, 2025
5b2584c
Merge branch 'master' into fix/explosion-trigger-clientside
MohabCodeX Aug 6, 2025
7672b77
Merge branch 'master' into fix/explosion-trigger-clientside
MohabCodeX Aug 7, 2025
c3226fa
applying reviews
MohabCodeX Aug 7, 2025
1892f3d
fix typo
MohabCodeX Aug 7, 2025
4c0c418
Merge branch 'master' into fix/explosion-trigger-clientside
MohabCodeX Aug 8, 2025
7bf0b4a
Merge branch 'master' into fix/explosion-trigger-clientside
MohabCodeX Aug 9, 2025
1278d7a
Merge branch 'master' into fix/explosion-trigger-clientside
MohabCodeX Aug 11, 2025
9d5ab5d
Merge branch 'master' into fix/explosion-trigger-clientside
Dutchman101 Aug 11, 2025
580c338
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
ef75488
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
4264f9b
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
1f8350c
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
b824d38
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
895e81a
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
a7d12ca
Update Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Dutchman101 Aug 12, 2025
8b8bb31
Update Client/mods/deathmatch/logic/CClientExplosionManager.h
Dutchman101 Aug 12, 2025
626de69
Merge branch 'master' into fix/explosion-trigger-clientside
Dutchman101 Aug 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ bool CClientExplosionManager::Hook_StaticExplosionCreation(CEntity* pGameExplodi
return g_pExplosionManager->Hook_ExplosionCreation(pGameExplodingEntity, pGameCreator, vecPosition, explosionType);
}

eWeaponType CClientExplosionManager::GetWeaponTypeFromExplosionType(eExplosionType explosionType)
{
switch (explosionType) {
case EXP_TYPE_GRENADE:
return WEAPONTYPE_GRENADE;
case EXP_TYPE_MOLOTOV:
return WEAPONTYPE_MOLOTOV;
case EXP_TYPE_ROCKET:
case EXP_TYPE_ROCKET_WEAK:
return WEAPONTYPE_ROCKET;
case EXP_TYPE_TANK_GRENADE:
return WEAPONTYPE_TANK_GRENADE;
default:
return WEAPONTYPE_EXPLOSION;
}
}

bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEntity, CEntity* pGameCreator, const CVector& vecPosition,
eExplosionType explosionType)
{
Expand All @@ -52,8 +69,21 @@ bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEnti

CClientEntity* const pResponsible = pPools->GetClientEntity(reinterpret_cast<DWORD*>(pResponsibleGameEntity->GetInterface()));

if (!pResponsible)
return false;
if (!pResponsible) {
if (!pGameCreator) return false;

CClientPlayer* pLocalPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
if (!pLocalPlayer || pLocalPlayer->GetGameEntity() != pGameCreator) return false;

eWeaponType explosionWeaponType = GetWeaponTypeFromExplosionType(explosionType);

CLuaArguments arguments;
arguments.PushNumber(vecPosition.fX);
arguments.PushNumber(vecPosition.fY);
arguments.PushNumber(vecPosition.fZ);
arguments.PushNumber(explosionWeaponType);
return pLocalPlayer->CallEvent("onClientExplosion", arguments, true);
}

// Determine the used weapon
eWeaponType explosionWeaponType = WEAPONTYPE_EXPLOSION;
Expand Down Expand Up @@ -167,25 +197,22 @@ CExplosion* CClientExplosionManager::Create(eExplosionType explosionType, CVecto
if (responsibleWeapon != WEAPONTYPE_UNARMED)
m_LastWeaponType = responsibleWeapon;
else
m_LastWeaponType = GetWeaponTypeFromExplosionType(explosionType);

if (pCreator && pCreator->IsLocalEntity())
{
switch (explosionType)
bool bAllowExplosion = Hook_ExplosionCreation(nullptr, pGameCreator, vecPosition, explosionType);
if (!bAllowExplosion)
return nullptr;
}
else if (!pCreator)
{
CClientPlayer* pLocalPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
if (pLocalPlayer)
{
case EXP_TYPE_GRENADE:
m_LastWeaponType = WEAPONTYPE_GRENADE;
break;
case EXP_TYPE_MOLOTOV:
m_LastWeaponType = WEAPONTYPE_MOLOTOV;
break;
case EXP_TYPE_ROCKET:
case EXP_TYPE_ROCKET_WEAK:
m_LastWeaponType = WEAPONTYPE_ROCKET;
break;
case EXP_TYPE_TANK_GRENADE:
m_LastWeaponType = WEAPONTYPE_TANK_GRENADE;
break;
default:
m_LastWeaponType = WEAPONTYPE_EXPLOSION;
break;
bool bAllowExplosion = Hook_ExplosionCreation(nullptr, pLocalPlayer->GetGameEntity(), vecPosition, explosionType);
if (!bAllowExplosion)
return nullptr;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CClientExplosionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ class CClientExplosionManager
CClientEntityPtr m_pLastCreator;

private:
CClientManager* m_pManager;
CClientManager* m_pManager;
eWeaponType GetWeaponTypeFromExplosionType(eExplosionType explosionType);
};
Loading