[Release] xSound audio library for FiveM

fixed, download new version from github… Thanks for reporting.

1 Like

Hello, i have an issue, i am using OneSync Infinity and xsound, the problem is that when a sound gets played, the entire server hears it. For example: when i play the “LSPD STOP THE CAR” sound from my police car, the entire server hears it. any suggestions?

never test it on OneSync infinity, I can’t really help you with this sadly.

have anyone tried on infinity?

Hi, if you using InteractSound_CL:PlayWithinDistance, replace the old event by this new in

xsound\client\emulator\interact_sound

(The bug is because the ped isn’t in your scope.)

RegisterNetEvent('InteractSound_CL:PlayWithinDistance')
    AddEventHandler('InteractSound_CL:PlayWithinDistance', function(playerNetId, maxDistance, soundFile, soundVolume)
        if GetPlayerFromServerId(playerNetId) ~= -1 then
            local eCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(playerNetId)))
            PlayUrlPos("./sounds/" .. soundFile, "./sounds/" .. soundFile .. "." .. config.interact_sound_file, soundVolume, eCoords)
            Distance("./sounds/" .. soundFile, maxDistance)
        end
    end)

Maybe @Xogos1 can pull the fix ?

1 Like

Well, thanks for the report. if the playerNetId is -1 it will be always player Ped entity… cuz. GetPlayerPed(-1) that was the reason why the whole server heard it :smiley:

1 Like

How i can put sound to a NPC? same ur video? O_o thanks and nice work man!

1 Like
xSound = exports.xsound
Citizen.CreateThread(function()
   local id = "follow_npc_sound"
   local model = GetHashKey("a_m_m_afriamer_01")
   RequestModel(model)
   while not HasModelLoaded(model) do
     Citizen.Wait(33)
     RequestModel(model)
   end

   local pedId = CreatePed(1, model , pos.x, pos.y, pos.z, 0.0,  true, false)   

   xSound:PlayUrlPos(id ,"http://relisoft.cz/assets/brainleft.mp3",1,vector3(0,0,0))
   xSound:onPlayStart(id, function() 
       while true do
          Citizen.Wait(50)
          xSound:Position(id, GetEntityCoords(pedId))
       end
   end)
end)   

you can do something like this… you need to fetch the position of the NPC and update it in some period of time. But it is just a client-side, if you want to sync it you need to register the ped as Network one and send info about what is playing to everyone else on the server etc etc.

Honestly, my knowledge is not enough to get a coordinate update, could you guide me a bit? I achieve that with the code that NPC, the music sounds, but I cannot do it in my script I suppose that is why you indicate, thanks for the code part.

Dont support only audio Twitch or copyright YouTube ? Like hypnonema but dont Play video

Can you please format your question better? I don’t understand anything that you just said.

support to play a twitch live only the audio of the live

Feel free to edit it, but in near future, even in the distant future, I am not planning to support twitch.

Requesting for help

make sure you run xsound before “qwe”

also, add this into fxmanifest.lua

dependencies {
	"xsound",
}

and if you have an older version where exports are manually written in fxmanifest, update the resource. Thanks

How i can put sound to a NPC?

xSound = exports.xsound
Citizen.CreateThread(function()
   local id = "follow_npc_sound"
   local model = GetHashKey("u_m_y_zombie_01")
   RequestModel(model)
   while not HasModelLoaded(model) do
     Citizen.Wait(33)
     RequestModel(model)
   end

   local pedId = CreatePed(1, model 1, 1, 1, 0.0,  true, false)   

   xSound:PlayUrlPos(id ,"http://relisoft.cz/assets/brainleft.mp3",1,vector3(0,0,0))
   xSound:onPlayStart(id, function() 
       while true do
          Citizen.Wait(50)
          xSound:Position(id, GetEntityCoords(pedId))
       end
   end)
end) 

I used this code
Different from the movie
Could you do me a favor?
I’m not good at English

You should do this

xSound:onPlayStart(id, function()
    CreateThread(function()
        while true do
            Wait(200)
            xSound:Position(id, GetEntityCoords(pedId))
        end
    end)
end)
xSound = exports.xsound
Citizen.CreateThread(function()
   local id = "follow_npc_sound"
   local model = GetHashKey("u_m_y_zombie_01")
   RequestModel(model)
   while not HasModelLoaded(model) do
     Citizen.Wait(33)
     RequestModel(model)
   end

   local pedId = CreatePed(1, model, 1.0, 1.0, 1.0, 0.0,  true, false)   

   xSound:PlayUrlPos(id ,"https://www.youtube.com/watch?v=B0h3ix2PJg0",1,vector3(0,0,0))
   xSound:onPlayStart(id, function()
    CreateThread(function()
        while true do
            Wait(200)
            xSound:Position(id, GetEntityCoords(pedId))
        end
    end)
end)

excuse me sir, could you tell me it’s correct or not?

it is, but you’re spawning the NPC at 1x 1y 1z so you won’t see the NPC…

i recommend spawning the NPC on your position

local pos = GetEntityCoords(PlayerPedId())
local pedId = CreatePed(1, model, pos.x, pos.y, pos.z, 0.0,  true, false)

Can someone help me to play a custom sound from ped like from the zombie system?