Scripts/resources/[standalone]/interact-sound/client/main.lua

46 lines
1.3 KiB
Lua
Raw Normal View History

2024-12-29 20:02:20 +00:00
local standardVolumeOutput = 0.3;
local hasPlayerLoaded = false
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
hasPlayerLoaded = true
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
hasPlayerLoaded = false
end)
RegisterNetEvent('InteractSound_CL:PlayOnOne', function(soundFile, soundVolume)
if hasPlayerLoaded then
SendNUIMessage({
transactionType = 'playSound',
transactionFile = soundFile,
transactionVolume = soundVolume
})
end
end)
RegisterNetEvent('InteractSound_CL:PlayOnAll', function(soundFile, soundVolume)
if hasPlayerLoaded then
SendNUIMessage({
transactionType = 'playSound',
transactionFile = soundFile,
transactionVolume = soundVolume or standardVolumeOutput
})
end
end)
RegisterNetEvent('InteractSound_CL:PlayWithinDistance', function(otherPlayerCoords, maxDistance, soundFile, soundVolume)
if hasPlayerLoaded then
local myCoords = GetEntityCoords(PlayerPedId())
local distance = #(myCoords - otherPlayerCoords)
if distance < maxDistance then
SendNUIMessage({
transactionType = 'playSound',
transactionFile = soundFile,
transactionVolume = soundVolume or standardVolumeOutput
})
end
end
end)