From ca26acdb6a2426f287888c865a99e9137b6944d4 Mon Sep 17 00:00:00 2001 From: Tinky <48660658+Tinky124@users.noreply.github.com> Date: Wed, 23 Jun 2021 14:46:02 +0100 Subject: [PATCH] Some fixes sound :) --- client/main.lua | 85 +++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/client/main.lua b/client/main.lua index d8f49b80..666dd0f8 100644 --- a/client/main.lua +++ b/client/main.lua @@ -8,8 +8,12 @@ -- a specific range from the entity to which the sound has been created. ------ -local standardVolumeOutput = 1.0; - +local standardVolumeOutput = 0.3; +local hasPlayerLoaded = false +Citizen.CreateThread(function() + Wait(15000) + hasPlayerLoaded = true +end) ------ -- RegisterNetEvent LIFE_CL:Sound:PlayOnOne -- @@ -23,11 +27,13 @@ local standardVolumeOutput = 1.0; ------ RegisterNetEvent('InteractSound_CL:PlayOnOne') AddEventHandler('InteractSound_CL:PlayOnOne', function(soundFile, soundVolume) - SendNUIMessage({ - transactionType = 'playSound', - transactionFile = soundFile, - transactionVolume = soundVolume - }) + if hasPlayerLoaded then + SendNUIMessage({ + transactionType = 'playSound', + transactionFile = soundFile, + transactionVolume = soundVolume + }) + end end) ------ @@ -43,11 +49,13 @@ end) ------ RegisterNetEvent('InteractSound_CL:PlayOnAll') AddEventHandler('InteractSound_CL:PlayOnAll', function(soundFile, soundVolume) - SendNUIMessage({ - transactionType = 'playSound', - transactionFile = soundFile, - transactionVolume = soundVolume - }) + if hasPlayerLoaded then + SendNUIMessage({ + transactionType = 'playSound', + transactionFile = soundFile, + transactionVolume = soundVolume or standardVolumeOutput + }) + end end) ------ @@ -67,45 +75,18 @@ end) -- @TODO Change sound volume based on the distance the player is away from the playOnEntity. ------ RegisterNetEvent('InteractSound_CL:PlayWithinDistance') -AddEventHandler('InteractSound_CL:PlayWithinDistance', function(playerNetId, maxDistance, soundFile, soundVolume) - local lCoords = GetEntityCoords(GetPlayerPed(-1)) - local eCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(playerNetId))) - local distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, eCoords.x, eCoords.y, eCoords.z) - if(distIs <= maxDistance) then - SendNUIMessage({ - transactionType = 'playSound', - transactionFile = soundFile, - transactionVolume = soundVolume - }) - end -end) +AddEventHandler('InteractSound_CL:PlayWithinDistance', function(otherPlayerCoords, maxDistance, soundFile, soundVolume) + if hasPlayerLoaded then + local myCoords = GetEntityCoords(PlayerPedId()) + local distance = #(myCoords - otherPlayerCoords) - ------- --- RegisterNetEvent LIFE_CL:Sound:PlayWithinDistanceOS (Bigmode varient of InteractSound_CL:PlayWithinDistance) --- --- @param playerCoords - The coords of the player making the sound --- --- @param maxDistance - The maximum float distance (client uses Vdist) to allow the player to --- - hear the soundFile being played. --- @param soundFile - The name of the soundfile within the client/html/sounds/ folder. --- - Can also specify a folder/sound file. --- @param soundVolume - The volume at which the soundFile should be played. Nil or don't --- - provide it for the default of standardVolumeOutput. Should be between --- - 0.1 to 1.0. --- --- Starts playing a sound on a client if the client is within the specificed maxDistance from the playOnEntity. --- @TODO Change sound volume based on the distance the player is away from the playOnEntity. ------- -RegisterNetEvent('InteractSound_CL:PlayWithinDistanceOS') -AddEventHandler('InteractSound_CL:PlayWithinDistanceOS', function(playerCoords, maxDistance, soundFile, soundVolume) - local lCoords = GetEntityCoords(GetPlayerPed(-1)) - local distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, playerCoords.x, playerCoords.y, playerCoords.z) - if(distIs <= maxDistance) then - SendNUIMessage({ - transactionType = 'playSound', - transactionFile = soundFile, - transactionVolume = soundVolume - }) - end + if distance < maxDistance then + SendNUIMessage({ + transactionType = 'playSound', + transactionFile = soundFile, + transactionVolume = soundVolume or standardVolumeOutput + }) + end + end end) +