Skip to content
Permalink
Browse files

Add onClientWorldSound event

  • Loading branch information...
botder committed Sep 27, 2018
1 parent 04bd059 commit 8302b4c64da348691303bf56d5f80413b7610fcc
@@ -498,7 +498,21 @@ bool CAudioEngineSA::OnWorldSound(CAESound* pAESound)
return false;

if (m_pWorldSoundHandler)
m_pWorldSoundHandler(pAESound->usGroup, pAESound->usIndex);
{
CEntitySAInterface* pGameEntity = pAESound->pGameEntity;

if (!pGameEntity && pAESound->pAudioEntity)
pGameEntity = pAESound->pAudioEntity->pEntity;

SWorldSoundEvent event = {
pAESound->usGroup,
pAESound->usIndex,
pGameEntity,
pAESound->m_vCurrPosn,
};

return m_pWorldSoundHandler(event);
}

return true;
}
@@ -283,6 +283,7 @@ CClientGame::CClientGame(bool bLocalPlay)
g_pGame->SetPreWeaponFireHandler(CClientGame::PreWeaponFire);
g_pGame->SetPostWeaponFireHandler(CClientGame::PostWeaponFire);
g_pGame->SetTaskSimpleBeHitHandler(CClientGame::StaticTaskSimpleBeHitHandler);
g_pGame->GetAudioEngine()->SetWorldSoundHandler(CClientGame::StaticWorldSoundHandler);
g_pCore->SetMessageProcessor(CClientGame::StaticProcessMessage);
g_pCore->GetKeyBinds()->SetKeyStrokeHandler(CClientGame::StaticKeyStrokeHandler);
g_pCore->GetKeyBinds()->SetCharacterKeyHandler(CClientGame::StaticCharacterKeyHandler);
@@ -2888,6 +2889,8 @@ void CClientGame::AddBuiltInEvents(void)
m_Events.AddEvent("onClientFileDownloadComplete", "fileName, success", NULL, false);

m_Events.AddEvent("onClientWeaponFire", "ped, x, y, z", NULL, false);

m_Events.AddEvent("onClientWorldSound", "group, index, x, y, z", nullptr, false);
}

void CClientGame::DrawFPS(void)
@@ -6447,11 +6450,6 @@ void CClientGame::SetDevelopmentMode(bool bEnable, bool bEnableWeb)
{
m_bDevelopmentMode = bEnable;

if (m_bDevelopmentMode)
g_pGame->GetAudioEngine()->SetWorldSoundHandler(CClientGame::StaticWorldSoundHandler);
else
g_pGame->GetAudioEngine()->SetWorldSoundHandler(NULL);

if (g_pCore->IsWebCoreLoaded())
g_pCore->GetWebCore()->SetTestModeEnabled(bEnableWeb);
}
@@ -6463,9 +6461,9 @@ void CClientGame::SetDevelopmentMode(bool bEnable, bool bEnableWeb)
// Handle callback from CAudioSA when a world sound is played
//
//////////////////////////////////////////////////////////////////
void CClientGame::StaticWorldSoundHandler(uint uiGroup, uint uiIndex)
bool CClientGame::StaticWorldSoundHandler(const SWorldSoundEvent& event)
{
g_pClientGame->WorldSoundHandler(uiGroup, uiIndex);
return g_pClientGame->WorldSoundHandler(event);
}

//////////////////////////////////////////////////////////////////
@@ -6475,10 +6473,31 @@ void CClientGame::StaticWorldSoundHandler(uint uiGroup, uint uiIndex)
// Handle callback from CAudioSA when a world sound is played
//
//////////////////////////////////////////////////////////////////
void CClientGame::WorldSoundHandler(uint uiGroup, uint uiIndex)
bool CClientGame::WorldSoundHandler(const SWorldSoundEvent& event)
{
if (m_bShowSound)
m_pScriptDebugging->LogInformation(NULL, "%s - World sound group:%d index:%d", *GetLocalTimeString(false, true), uiGroup, uiIndex);
m_pScriptDebugging->LogInformation(NULL, "%s - World sound group:%d index:%d", *GetLocalTimeString(false, true), event.uiGroup, event.uiIndex);

// Audio events without a game entity could default to the root element, but the
// best approach is to avoid spamming the event with the barely notable sounds (without a source).
// Warning: Canceling sounds emitted by an audio entity (like vehicles do) will cause massive spam
if (event.pGameEntity)
{
CClientEntity* pEntity = g_pClientGame->GetGameEntityXRefManager()->FindClientEntity(event.pGameEntity);

if (pEntity)
{
CLuaArguments Arguments;
Arguments.PushNumber(event.uiGroup);
Arguments.PushNumber(event.uiIndex);
Arguments.PushNumber(event.vecPosition.fX);
Arguments.PushNumber(event.vecPosition.fY);
Arguments.PushNumber(event.vecPosition.fZ);
return pEntity->CallEvent("onClientWorldSound", Arguments, true);
}
}

return true;
}

//////////////////////////////////////////////////////////////////
@@ -523,7 +523,7 @@ class CClientGame
static void StaticGamePlayerDestructHandler(CEntitySAInterface* pPlayer);
static void StaticGameProjectileDestructHandler(CEntitySAInterface* pProjectile);
static void StaticGameModelRemoveHandler(ushort usModelId);
static void StaticWorldSoundHandler(uint uiGroup, uint uiIndex);
static bool StaticWorldSoundHandler(const SWorldSoundEvent& event);
static void StaticGameEntityRenderHandler(CEntitySAInterface* pEntity);
static void StaticTaskSimpleBeHitHandler(CPedSAInterface* pPedAttacker, ePedPieceTypes hitBodyPart, int hitBodySide, int weaponId);
static void StaticFxSystemDestructionHandler(void* pFxSAInterface);
@@ -562,7 +562,7 @@ class CClientGame
void GamePlayerDestructHandler(CEntitySAInterface* pPlayer);
void GameProjectileDestructHandler(CEntitySAInterface* pProjectile);
void GameModelRemoveHandler(ushort usModelId);
void WorldSoundHandler(uint uiGroup, uint uiIndex);
bool WorldSoundHandler(const SWorldSoundEvent& event);
void TaskSimpleBeHitHandler(CPedSAInterface* pPedAttacker, ePedPieceTypes hitBodyPart, int hitBodySide, int weaponId);
AnimationId DrivebyAnimationHandler(AnimationId animGroup, AssocGroupId animId);

@@ -14,7 +14,17 @@
#include <windows.h>
#include "CVehicle.h"

typedef void(WorldSoundHandler)(uint uiGroup, uint uiIndex);
class CEntitySAInterface;

struct SWorldSoundEvent
{
unsigned int uiGroup;
unsigned int uiIndex;
CEntitySAInterface* pGameEntity;
CVector vecPosition;
};

using WorldSoundHandler = bool(const SWorldSoundEvent& event);

enum eSurfaceType
{

0 comments on commit 8302b4c

Please sign in to comment.
You can’t perform that action at this time.