Xogy / xsound

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

PlayUrlPos refuses to work #61

Closed DolfinoPlays closed 2 months ago

DolfinoPlays commented 2 months ago

Issue

When i run the code below, the print functions all work fine, but no audio is playing whatsoever, I've been running in circles trying to figure out what I've done wrong, if anything.

RegisterNetEvent('SEM_InteractionMenu:PlaySound')
AddEventHandler('SEM_InteractionMenu:PlaySound', function(action)

    if action == 'Cuff' then
    xSound = exports.xsound

        local pos = GetEntityCoords(playerPed)

        print('Attempting to play cuff sound')

        xSound:PlayUrlPos("cuff", 'https://www.youtube.com/watch?v=6EhtM5M2Iu8', 1, pos)
        xSound:Distance("cuff", 100)

        print('Played cuff sound')

        Citizen.Wait(2000)
        xSound:Destroy("cuff")

        print('Destroyed cuff sound')

    elseif action == 'Uncuffed' then

    xSound = exports.xsound

        local pos = GetEntityCoords(playerPed)

        print('Attempting to play uncuff sound')

        xSound:PlayUrlPos("uncuff", 'https://www.youtube.com/watch?v=t9ujXXs90j8', 1, pos)
        xSound:Distance("uncuff", 100)

        print('Played uncuff sound')

        Citizen.Wait(2000)
        xSound:Destroy("uncuff")

        print('Destoryed uncuff sound')

    else
        print("Unexpected action: " .. action)
    end
end)

Console The console prints out this:

[script:SEM_Interacti] Attempting to play cuff sound
[script:SEM_Interacti] Played cuff sound
[script:SEM_Interacti] Destroyed cuff sound
[script:SEM_Interacti] Attempting to play uncuff sound
[script:SEM_Interacti] Played uncuff sound
[script:SEM_Interacti] Destoryed uncuff sound
Xogy commented 2 months ago

Hello, you're missing local playerPed = PlayerPedId()

Tested it and it is working with no issue.

DolfinoPlays commented 2 months ago

Im running this in a server.lua script

[script:SEM_Interacti] SCRIPT ERROR: @SEM_InteractionMenu/server.lua:21: attempt to call a nil value (global 'PlayerPedId')
[script:SEM_Interacti] > handler (@SEM_InteractionMenu/server.lua:21)
[script:SEM_Interacti] SCRIPT ERROR: @SEM_InteractionMenu/server.lua:40: attempt to call a nil value (global 'PlayerPedId')
[script:SEM_Interacti] > handler (@SEM_InteractionMenu/server.lua:40)
Xogy commented 2 months ago

The code you sent is client-sided only.