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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
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
52 changes: 52 additions & 0 deletions Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,42 @@ bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEnti
CClientEntity* const pResponsible = pPools->GetClientEntity(reinterpret_cast<DWORD*>(pResponsibleGameEntity->GetInterface()));

if (!pResponsible)
{
if (pGameCreator)
{
CClientPlayer* pLocalPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
if (pLocalPlayer && pLocalPlayer->GetGameEntity() == pGameCreator)
{
eWeaponType explosionWeaponType = WEAPONTYPE_EXPLOSION;
switch (explosionType)
{
case EXP_TYPE_GRENADE:
explosionWeaponType = WEAPONTYPE_GRENADE;
break;
case EXP_TYPE_MOLOTOV:
explosionWeaponType = WEAPONTYPE_MOLOTOV;
break;
case EXP_TYPE_ROCKET:
case EXP_TYPE_ROCKET_WEAK:
explosionWeaponType = WEAPONTYPE_ROCKET;
break;
case EXP_TYPE_TANK_GRENADE:
explosionWeaponType = WEAPONTYPE_TANK_GRENADE;
break;
default:
break;
}

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

// Determine the used weapon
eWeaponType explosionWeaponType = WEAPONTYPE_EXPLOSION;
Expand Down Expand Up @@ -189,6 +224,23 @@ CExplosion* CClientExplosionManager::Create(eExplosionType explosionType, CVecto
}
}

if (pCreator && pCreator->IsLocalEntity())
{
bool bAllowExplosion = Hook_ExplosionCreation(nullptr, pGameCreator, vecPosition, explosionType);
if (!bAllowExplosion)
return nullptr;
}
else if (!pCreator)
{
CClientPlayer* pLocalPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
if (pLocalPlayer)
{
bool bAllowExplosion = Hook_ExplosionCreation(nullptr, pLocalPlayer->GetGameEntity(), vecPosition, explosionType);
if (!bAllowExplosion)
return nullptr;
}
}

CExplosion* pExplosion = g_pGame->GetExplosionManager()->AddExplosion(NULL, pGameCreator, explosionType, vecPosition, 0, bMakeSound, fCamShake, bNoDamage);
return pExplosion;
}
Loading