Xogy / xsound

Improved audio library for FiveM
MIT License
115 stars 82 forks source link

For some reason, distance isn't working #55

Closed bosskitz closed 10 months ago

bosskitz commented 10 months ago

Here is the code I am using: Client side.

RegisterNetEvent("resource-name:eventname") AddEventHandler("resource-name:eventname", function(audioUrl, volume, distance, rand) local playerped = PlayerPedId() local pedcoords = GetEntityCoords(playerped) local rand = rand exports['xsound']:PlayUrlPos('resp'..rand, audioUrl, volume, pedcoords) exports['xsound']:Distance('resp'..rand, distance) exports['xsound']:setSoundDynamic('resp'..rand, true) print(json.encode(exports['xsound']:getInfo('resp'..rand))) --exports['xsound']:Destroy('resp'..rand, true) end)

Current status: Basically, the audio is working. We're able to hear it. I am using Google tts API for this and it works perfectly fine. Problem is, I am not sure if I'm implementing distance properly. image But it shows here (image) that the distance is set and coords is also set. Did some print tests too and these are set properly.

Problem is, it is still being heard by everyone. Kindly advise, thank you.

Xogy commented 10 months ago

"Problem is, it is still being heard by everyone. Kindly advise, thank you."

Are you using an old version? This issue is known in older versions.

bosskitz commented 10 months ago

Thanks for your response. I am actually using the latest release.

--[[ Resource Information ]]-- name 'xsound' version '1.4.3'

And fortunately, I have found the issue. The thing is, coords and distance and all parameters do work. It was confusing at first because we were all hearing it but then noticed that when someone triggers the event, it is being triggered to all PlayersIds instead of only the source.

So, I changed this to source: Server: TriggerClientEvent("ResourceName:EventName", source, "data:audio/mp3;base64," .. audioData, volume, distance, rand)

Client:

RegisterNetEvent("ResourceName:EventName") AddEventHandler("ResourceName:EventName", function(audioUrl, volume, distance, rand) ---Some other variable here exports['xsound']:PlayUrlPos('resp'..rand, audioUrl, volume, pedcoords) exports['xsound']:Distance('resp'..rand, distance) .....

Then, it's only playing to the source and other players nearby can't hear. Am I missing something?

Thanks for your response.

Xogy commented 10 months ago

You will still need to trigger for every client on your server but send the initial source coordination