From a76613604a807c12d1b5d0f12cc2ccf97312bbcb Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 13 Dec 2021 20:36:50 -0600 Subject: [PATCH] augments playSoundAsset adds hooks to the garbage collector exposes an (optional) position. adds a ServerPlaySound + clientCMDPlaySound command pair to trip that for all clients --- .../clientServer/scripts/server/audio.tscript | 7 +++++++ .../utility/scripts/helperFunctions.tscript | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Templates/BaseGame/game/core/clientServer/scripts/server/audio.tscript b/Templates/BaseGame/game/core/clientServer/scripts/server/audio.tscript index 67b2fbf5e..627701371 100644 --- a/Templates/BaseGame/game/core/clientServer/scripts/server/audio.tscript +++ b/Templates/BaseGame/game/core/clientServer/scripts/server/audio.tscript @@ -38,3 +38,10 @@ function ServerPlay3D(%profile,%transform) ClientGroup.getObject(%idx).play3D(%profile,%transform); } +function ServerPlaySound(%profile,%pos) +{ + // Play the given sound profile at the given position on every client + // The sound will be transmitted as an event, not attached to any object. + for(%idx = 0; %idx < ClientGroup.getCount(); %idx++) + commandToClient(ClientGroup.getObject(%idx), PlaySound, %pos); +} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/utility/scripts/helperFunctions.tscript b/Templates/BaseGame/game/core/utility/scripts/helperFunctions.tscript index 3143eb410..98d616529 100644 --- a/Templates/BaseGame/game/core/utility/scripts/helperFunctions.tscript +++ b/Templates/BaseGame/game/core/utility/scripts/helperFunctions.tscript @@ -645,11 +645,21 @@ function populateAllFonts(%font) } //------------------------------------------------------------------------------ -function playSoundAsset(%soundAssetId) +function clientCMDPlaySound(%soundAssetId,%pos) +{ + playSoundAsset(%soundAssetId,%pos); +} + +function playSoundAsset(%soundAssetId,%pos) { %assetDef = AssetDatabase.acquireAsset(%soundAssetId); + %handle = 0; if(isObject(%assetDef)) - %assetDef.playSound(); - - AssetDatabase.releaseAsset(%soundAssetId); + { + %handle = %assetDef.playSound(%pos); + if( isObject( ClientMissionCleanup ) ) + ClientMissionCleanup.add(%handle); + } + AssetDatabase.releaseAsset(%soundAssetId); + return %handle; } \ No newline at end of file