Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes sound :) #21

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 33 additions & 52 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand All @@ -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)

------
Expand All @@ -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)

------
Expand All @@ -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)