From 3e446c576675f33012c7df2f679d7025bb822ac7 Mon Sep 17 00:00:00 2001 From: pongo1231 Date: Sat, 18 Jan 2025 00:11:26 +0000 Subject: [PATCH] ChaosMod: Add effect sound PlayFlags --- .../Components/EffectSound/EffectSound3D.cpp | 5 ++- ChaosMod/Components/LuaScripts.cpp | 39 +++++++++++++++---- ChaosMod/Effects/EffectSoundPlayOptions.h | 8 ++++ .../Effects/db/Peds/PedsSpawnAngryJesus.cpp | 5 ++- .../Effects/db/Peds/PedsSpawnImpotentRage.cpp | 5 ++- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/ChaosMod/Components/EffectSound/EffectSound3D.cpp b/ChaosMod/Components/EffectSound/EffectSound3D.cpp index 091cb048f..94b06f279 100644 --- a/ChaosMod/Components/EffectSound/EffectSound3D.cpp +++ b/ChaosMod/Components/EffectSound/EffectSound3D.cpp @@ -95,6 +95,7 @@ void EffectSound3D::OnRun() ma_sound_set_rolloff(&sound.Handle, .1f); ma_sound_set_pitch(&sound.Handle, 1.f + (!Hooks::GetTargetAudioPitch() ? 0.f : Hooks::GetTargetAudioPitch() * .0001f)); + ma_sound_set_looping(&sound.Handle, sound.PlayOptions.PlayFlags & EffectSoundPlayFlags_Looping); switch (sound.PlayOptions.PlayType) { @@ -103,7 +104,9 @@ void EffectSound3D::OnRun() break; case EffectSoundPlayType::FollowEntity: { - if (!sound.PlayOptions.Entity || !DOES_ENTITY_EXIST(sound.PlayOptions.Entity)) + if (!sound.PlayOptions.Entity || !DOES_ENTITY_EXIST(sound.PlayOptions.Entity) + || (sound.PlayOptions.PlayFlags & EffectSoundPlayFlags_StopOnEntityDeath + && IS_ENTITY_DEAD(sound.PlayOptions.Entity, false))) { uninitSound(); continue; diff --git a/ChaosMod/Components/LuaScripts.cpp b/ChaosMod/Components/LuaScripts.cpp index 8cad7a367..39840fd5d 100644 --- a/ChaosMod/Components/LuaScripts.cpp +++ b/ChaosMod/Components/LuaScripts.cpp @@ -817,18 +817,43 @@ LuaScripts::ParseScriptRaw(std::string scriptName, std::string_view script, Pars CurrentEffect::OverrideEffectNameFromId(overrideId); }; - lua["SetEffectSoundFollowPlayer"] = [effectId](const sol::this_state &lua) + auto getEffectSoundPlayOptions = []() -> EffectSoundPlayOptions * { - CurrentEffect::SetEffectSoundPlayOptions({ .PlayType = EffectSoundPlayType::FollowPlayer }); + auto sharedData = EffectThreads::GetThreadSharedData(GetCurrentFiber()); + if (!sharedData) + return nullptr; + return &sharedData->EffectSoundPlayOptions; }; - lua["SetEffectSoundFollowEntity"] = [effectId](const sol::this_state &lua, Entity entity) + lua["SetEffectSoundFollowPlayer"] = [effectId, getEffectSoundPlayOptions](const sol::this_state &lua) { - CurrentEffect::SetEffectSoundPlayOptions({ .PlayType = EffectSoundPlayType::FollowEntity, .Entity = entity }); + auto soundPlayOptions = getEffectSoundPlayOptions(); + soundPlayOptions->PlayType = EffectSoundPlayType::FollowPlayer; }; - lua["SetEffectSoundAtCoords"] = [effectId](const sol::this_state &lua, const LuaVector3 &coords) + lua["SetEffectSoundFollowEntity"] = [effectId, getEffectSoundPlayOptions](const sol::this_state &lua, Entity entity) { - CurrentEffect::SetEffectSoundPlayOptions( - { .PlayType = EffectSoundPlayType::AtCoords, .Coords = Vector3(coords.X, coords.Y, coords.Z) }); + auto soundPlayOptions = getEffectSoundPlayOptions(); + soundPlayOptions->PlayType = EffectSoundPlayType::FollowEntity; + soundPlayOptions->Entity = entity; + }; + lua["SetEffectSoundAtCoords"] = + [effectId, getEffectSoundPlayOptions](const sol::this_state &lua, const LuaVector3 &coords) + { + auto soundPlayOptions = getEffectSoundPlayOptions(); + soundPlayOptions->PlayType = EffectSoundPlayType::AtCoords; + soundPlayOptions->Coords = { coords.X, coords.Y, coords.Z }; + }; + lua["SetEffectSoundLooping"] = [effectId, getEffectSoundPlayOptions](const sol::this_state &lua, bool state) + { + auto soundPlayOptions = getEffectSoundPlayOptions(); + soundPlayOptions->PlayFlags = state ? soundPlayOptions->PlayFlags | EffectSoundPlayFlags_Looping + : soundPlayOptions->PlayFlags & ~EffectSoundPlayFlags_Looping; + }; + lua["SetEffectSoundStopOnEntityDeath"] = + [effectId, getEffectSoundPlayOptions](const sol::this_state &lua, bool state) + { + auto soundPlayOptions = getEffectSoundPlayOptions(); + soundPlayOptions->PlayFlags = state ? soundPlayOptions->PlayFlags | EffectSoundPlayFlags_StopOnEntityDeath + : soundPlayOptions->PlayFlags & ~EffectSoundPlayFlags_StopOnEntityDeath; }; EffectData effectData; diff --git a/ChaosMod/Effects/EffectSoundPlayOptions.h b/ChaosMod/Effects/EffectSoundPlayOptions.h index 1e8139b5d..9bfb02ad2 100644 --- a/ChaosMod/Effects/EffectSoundPlayOptions.h +++ b/ChaosMod/Effects/EffectSoundPlayOptions.h @@ -8,9 +8,17 @@ enum class EffectSoundPlayType FollowEntity, AtCoords }; + +enum EffectSoundPlayFlags +{ + EffectSoundPlayFlags_Looping = (1 << 0), + EffectSoundPlayFlags_StopOnEntityDeath = (1 << 1) +}; + struct EffectSoundPlayOptions { EffectSoundPlayType PlayType = EffectSoundPlayType::FollowPlayer; + int PlayFlags; union { Entity Entity; diff --git a/ChaosMod/Effects/db/Peds/PedsSpawnAngryJesus.cpp b/ChaosMod/Effects/db/Peds/PedsSpawnAngryJesus.cpp index 20d86d7f0..19844290d 100644 --- a/ChaosMod/Effects/db/Peds/PedsSpawnAngryJesus.cpp +++ b/ChaosMod/Effects/db/Peds/PedsSpawnAngryJesus.cpp @@ -18,7 +18,10 @@ static void OnStart() SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, femCivGroup); auto ped = CreatePoolPed(4, modelHash, playerPos.x, playerPos.y, playerPos.z, 0.f); - CurrentEffect::SetEffectSoundPlayOptions({ .PlayType = EffectSoundPlayType::FollowEntity, .Entity = ped }); + CurrentEffect::SetEffectSoundPlayOptions( + { .PlayType = EffectSoundPlayType::FollowEntity, + .PlayFlags = EffectSoundPlayFlags_Looping | EffectSoundPlayFlags_StopOnEntityDeath, + .Entity = ped }); if (IS_PED_IN_ANY_VEHICLE(playerPed, false)) SET_PED_INTO_VEHICLE(ped, GET_VEHICLE_PED_IS_IN(playerPed, false), -2); diff --git a/ChaosMod/Effects/db/Peds/PedsSpawnImpotentRage.cpp b/ChaosMod/Effects/db/Peds/PedsSpawnImpotentRage.cpp index cd3c21cea..6c17714c0 100644 --- a/ChaosMod/Effects/db/Peds/PedsSpawnImpotentRage.cpp +++ b/ChaosMod/Effects/db/Peds/PedsSpawnImpotentRage.cpp @@ -18,7 +18,10 @@ static void OnStart() Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false); Ped ped = CreatePoolPed(4, model, playerPos.x, playerPos.y, playerPos.z, GET_ENTITY_HEADING(playerPed)); - CurrentEffect::SetEffectSoundPlayOptions({ .PlayType = EffectSoundPlayType::FollowEntity, .Entity = ped }); + CurrentEffect::SetEffectSoundPlayOptions( + { .PlayType = EffectSoundPlayType::FollowEntity, + .PlayFlags = EffectSoundPlayFlags_Looping | EffectSoundPlayFlags_StopOnEntityDeath, + .Entity = ped }); SET_ENTITY_HEALTH(ped, 1000, 0); SET_PED_ARMOUR(ped, 1000);