[Release] Play Custom Sounds for Interactions

Just wanted to let everyone know that an issue was opened about the couldn’t start resource error. I’m looking into it and will release an update when i’ve got a solution.

It says on index.html line 0 there is no supported source found

Have you added the sound to the _resource file ?

Sorry I could have removed comment, I fixed it. Thanks anyways

I’m not even able to play the demo sound.

I created the folder \server-data\resources\interact-sound and put all the files in there (with the __resource.lua file directly in that folder). I put “start interact-sound” into the server.cfg so it automatically starts. Then when I use “TriggerServerEvent(‘InteractSound_SV:PlayOnAll’, ‘demo’, 1.0)” in a client script nothing happens when it gets triggered. I also tried other events and none of them work.

What am I doing wrong?

Do I need to add start interact-sound to the server.cfg?

I followed the documentation but this aint working

make sure that you didn’t forget to add symbol ‘’,’’ after the demo sound line as:
if you just copy paste, it should work :wink:

– Manifest Version
resource_manifest_version ‘77731fab-63ca-442c-a67b-abc70f28dfa5’

– Client Scripts
client_script ‘client/main.lua’

– Server Scripts
server_script ‘server/main.lua’

– NUI Default Page
ui_page(‘client/html/index.html’)

– Files needed for NUI
– DON’T FORGET TO ADD THE SOUND FILES TO THIS!
files {
‘client/html/index.html’,
– Begin Sound Files Here…
– client/html/sounds/ … .ogg
‘client/html/sounds/demo.ogg’,
‘client/html/sounds/speedcamera.ogg’
}

It work’s but you need to add “,”

Thats wrong:
‘client/html/sounds/demo.ogg’

It should look like this:
‘client/html/sounds/demo.ogg’,

You need to use it for everything you add NOT ONLY for demo.ogg!
Hope i can help!

1 Like

i added the comma on all of them and now it says could not load resource InteractSound

Then try to remove the comma from the last line you added so it looks like this:

‘client/html/sounds/demo.ogg’,
‘client/html/sounds/test1.ogg’,
‘client/html/sounds/test2.ogg’,
‘client/html/sounds/test2.ogg’

1 Like

thats how it was before i even tried changing the comma

my only issue atm is triggering the server event to play the sound from my own script

i followed the documentation and couldnt get the down to work properly

This is how it looks on my client script

Citizen.CreateThread(function(source, args)
    local dict = "anim@mp_player_intmenu@key_fob@"
    RequestAnimDict(dict)
    while not HasAnimDictLoaded(dict) do
        Citizen.Wait(100)
    end
    while true do
        Citizen.Wait(2)
        if Vdist(GetEntityCoords(GetPlayerPed(-1), false), v1) < distance_to_tp and IsControlJustReleased(0, e_key) then
            TaskPlayAnim(GetPlayerPed(-1), dict, "fob_click", 8.0, 8.0, -1, 48, 1, false, false, false)
            Citizen.Wait(300)
            TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 0.5, 'demo', 1.0)
            Citizen.Wait(1000)
            SetEntityCoords(GetPlayerPed(-1), -2150.01, 221.68, 184.6, true, true, true, false)
            SetEntityHeading(GetPlayerPed(-1), 236.96)
        end
    end
end)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		if IsControlJustReleased(0, Keys['K']) then
    			RequestAnimDict("anim@mp_player_intmenu@key_fob@")
    		while (not HasAnimDictLoaded("anim@mp_player_intmenu@key_fob@")) do Citizen.Wait(0) end
    				TaskPlayAnim(GetPlayerPed(-1),"anim@mp_player_intmenu@key_fob@","fob_click",8.0,1.0, -1, 2, 0, 0, 0, 0)
    				TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 0.5, 'carlock', 100.0)
    				--TaskPlayAnim(ped, animDictionary, animationName, speed, speedMultiplier, duration, flag, playbackRate, lockX, lockY, lockZ)
				lock()
				Citizen.Wait(1000)
				ClearPedTasks(GetPlayerPed(-1))
		end
	end
end)

Why is this not working? :thinking:

the one i did works perfectly minus the custom sound try that one

got it working, thank you though.

how did you get the sound to play

my jb_vehiclelockclient.lua


Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		if IsControlJustReleased(0, Keys['K']) then
    			RequestAnimDict("anim@mp_player_intmenu@key_fob@")
    		while (not HasAnimDictLoaded("anim@mp_player_intmenu@key_fob@")) do Citizen.Wait(0) end
    				TaskPlayAnim(GetPlayerPed(-1),"anim@mp_player_intmenu@key_fob@","fob_click",8.0,1.0, -1, 2, 0, 0, 0, 0)
    				TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 5, 'carlock', 0.4)
				lock()
				Citizen.Wait(1000)
				ClearPedTasks(GetPlayerPed(-1))
		end
	end
end)

My interactsound server event:

RegisterServerEvent('InteractSound_SV:PlayWithinDistance')
AddEventHandler('InteractSound_SV:PlayWithinDistance', function(maxDistance, soundFile, soundVolume)
    TriggerClientEvent('LIFE_CL:Sound:PlayWithinDistance', -1, source, maxDistance, soundFile, soundVolume)
end)

My Interactsound client event;

RegisterNetEvent('LIFE_CL:Sound:PlayWithinDistance')
AddEventHandler('LIFE_CL:Sound: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)
1 Like

2 questions why do u put LIFE_CL is that the name of your client and server file or the name of your resource foulder, and can you tell me if i am doing something wrong cz for some reason no sound plays when i press the button.

Client File:

RegisterNetEvent('testblips:Sound:PlayWithinDistance')
AddEventHandler('testblips_CL:Sound: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)

-- Teleports Player to Certain Coordinate if player is inside the marker and presses "E". It will also play an animation before teleporting.
Citizen.CreateThread(function(source, args)
    local dict = "anim@mp_player_intmenu@key_fob@"
    RequestAnimDict(dict)
    while not HasAnimDictLoaded(dict) do
        Citizen.Wait(100)
    end

    while true do
        Citizen.Wait(2)
        if Vdist(GetEntityCoords(GetPlayerPed(-1), false), v1) < distance_to_tp and IsControlJustReleased(0, e_key) then
            TaskPlayAnim(GetPlayerPed(-1), dict, "fob_click", 8.0, 8.0, -1, 48, 1, false, false, false)
            Citizen.Wait(300)
            TriggerServerEvent('testblips_SV:PlayWithinDistance', 5, 'unlock', 0.9)
            Citizen.Wait(1000)
            SetEntityCoords(GetPlayerPed(-1), -2150.01, 221.68, 184.6, true, true, true, false)
            SetEntityHeading(GetPlayerPed(-1), 236.96)
        end
    end
end)

Server File:

RegisterServerEvent('testblips_SV:PlayWithinDistance')
AddEventHandler('testblips_SV:PlayWithinDistance', function(maxDistance, soundFile, soundVolume)
    TriggerClientEvent('testblips_CL:Sound:PlayWithinDistance', -1, source, maxDistance, soundFile, soundVolume)
end)

html file:

<!-- Code from Scott's InteractSound script : https://forum.cfx.re/t/release-play-custom-sounds-for-interactions/8282 -->
<html>
    <head>
        <!-- Need to include jQuery! -->
        <script src="nui://game/ui/jquery.js" type="text/javascript"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.1.1/howler.min.js" type="text/javascript"></script>
        <script>
            var audioPlayer = null;
            // Listen for NUI Messages.
            window.addEventListener('message', function(event) {
                // Check for playSound transaction
                if (event.data.transactionType == "playSound") {

                  if (audioPlayer != null) {
                    audioPlayer.pause();
                  }

                  audioPlayer = new Howl({src: ["./sounds/" + event.data.transactionFile + ".ogg"]});
                  audioPlayer.volume(event.data.transactionVolume);
                  audioPlayer.play();

                }
            });
        </script>
    </head>
</html>

Sound Folder name: sounds
with lock.ogg and unlock.ogg in them

Please someone tell me what im doing wrong!

NVM Finally got it working