Skip to content

Commit e490616

Browse files
authored
Fix onClientWorldSound event cancellation for non-entity sounds (#3269) (#4416)
Refactor WorldSoundHandler
1 parent 24d6d69 commit e490616

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6477,20 +6477,26 @@ bool CClientGame::WorldSoundHandler(const SWorldSoundEvent& event)
64776477
// Audio events without a game entity could default to the root element, but the
64786478
// best approach is to avoid spamming the event with the barely notable sounds (without a source).
64796479
// Warning: Canceling sounds emitted by an audio entity (like vehicles do) will cause massive spam
6480+
CClientEntity* pEntity = nullptr;
6481+
64806482
if (event.pGameEntity)
64816483
{
6482-
CPools* pPools = g_pGame->GetPools();
6483-
CClientEntity* pEntity = pPools->GetClientEntity((DWORD*)event.pGameEntity);
6484-
if (pEntity)
6485-
{
6486-
CLuaArguments Arguments;
6487-
Arguments.PushNumber(event.uiGroup);
6488-
Arguments.PushNumber(event.uiIndex);
6489-
Arguments.PushNumber(event.vecPosition.fX);
6490-
Arguments.PushNumber(event.vecPosition.fY);
6491-
Arguments.PushNumber(event.vecPosition.fZ);
6492-
return pEntity->CallEvent("onClientWorldSound", Arguments, true);
6493-
}
6484+
CPools* pPools = g_pGame->GetPools();
6485+
pEntity = pPools->GetClientEntity((DWORD*)event.pGameEntity);
6486+
}
6487+
6488+
if (!pEntity)
6489+
pEntity = GetRootEntity();
6490+
6491+
if (pEntity)
6492+
{
6493+
CLuaArguments Arguments;
6494+
Arguments.PushNumber(event.uiGroup);
6495+
Arguments.PushNumber(event.uiIndex);
6496+
Arguments.PushNumber(event.vecPosition.fX);
6497+
Arguments.PushNumber(event.vecPosition.fY);
6498+
Arguments.PushNumber(event.vecPosition.fZ);
6499+
return pEntity->CallEvent("onClientWorldSound", Arguments, true);
64946500
}
64956501

64966502
return true;

0 commit comments

Comments
 (0)