Home PendingSound
Post
Cancel

PendingSound

Background

PendingSound is a FiveM utility resource that allows you to play sounds to your clients in a modular way. It’s the first of it’s kind; the FiveM client code was even changed because of it. See the FiveM forum thread.

Play a sound

  1. Add PendingSound to your resources folder.
  2. Add ensure PendingSound to your server.cfg BEFORE any resources with sound playing through PendingSound.
  3. Create or edit a resource that is above the “cerelean” FX Version. See Resource Manifest for more information.
  4. Add the sound files that you wish to play into the resource that you wish to play it from.
  5. Add the following in your __resource.lua file, replacing the sound file names with the ones that you will use. There is support for all sound files that can be played through HTML and FiveM’s NUI system. !! Ensure that you add the file extension name at the end, and any folder directories that may be before the sound file itself !!
    1
    2
    3
    4
    5
    
    dependency 'PendingSound'
    files {
      "sound1.ogg",
      "sound2.ogg"
    }
    
  6. Use PlaySound export.

Exports

PlaySound - Client

1
exports["PendingSound"]:PlaySound(name, resource, volume)

E.G.:
name: “sound.ogg”
resource: “MyResource”
volume: 1 (Volume is between 0-1)

1
exports["PendingSound"]:PlaySound("sound.ogg", "MyResource", 1)

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:PlaySound("sound.ogg", GetCurrentResourceName(), 1)

PlaySound - Server

1
exports["PendingSound"]:PlaySound(src, name, resource, volume)

E.G.:
src: -1
name: “sound.ogg”
resource: “MyResource”
volume: 1 (Volume is between 0-1)

1
exports["PendingSound"]:PlaySound(-1, "sound.ogg", "MyResource", 1)

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:PlaySound(-1, "sound.ogg", GetCurrentResourceName(), 1)

PlaySoundURL - Client

1
exports["PendingSound"]:PlaySoundURL(name, resource, volume)

E.G.:
name: “https://mywebsite.com/mymp3.mp3”
resource: “MyResource”
volume: 1 (Volume is between 0-1)

1
exports["PendingSound"]:PlaySoundURL("https://mywebsite.com/mymp3.mp3", "MyResource", 1)

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:PlaySoundURL("https://mywebsite.com/mymp3.mp3", GetCurrentResourceName(), 1)

PlaySoundURL - Server

1
exports["PendingSound"]:PlaySoundURL(src, url, resource, volume)

E.G.:
src: -1
url: “https://mywebsite.com/mymp3.mp3”
resource: “MyResource”
volume: 1 (Volume is between 0-1)

1
exports["PendingSound"]:PlaySoundURL(-1, "https://mywebsite.com/mymp3.mp3", "MyResource", 1)

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:PlaySoundURL(-1, "https://mywebsite.com/mymp3.mp3", GetCurrentResourceName(), 1)

PlayLocalSound - Client

PlayLocalSound plays a sound based off a coordinate. This function only plays the sound to the play of which the client script is running on.

1
exports["PendingSound"]:PlayLocalSound(pos, sound, resource, volume)

E.G.:
pos: {x = 0.0, y = 0.0, z = 0.0}
sound: “sound.ogg”
resource: “MyResource” volume: 1

1
  exports["PendingSound"]:PlayLocalSound({x = 0.0, y = 0.0, z = 0.0}, "sound.ogg", "MyResource", 1)

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:PlayLocalSound({x = 0.0, y = 0.0, z = 0.0}, "sound.ogg", GetCurrentResourceName(), 1)

PlayLocalSound - Server

1
TriggerServerEvent("PendingSound:PlayLocalSound", pos, sound, resource, volume)

PlayLocalSound plays a sound based off a coordinate. This function plays the sound to all clients. If they are close enough - they will hear it.

1
exports["PendingSound"]:PlayLocalSound(pos, sound, resource, volume)

E.G.:
pos: {x = 0.0, y = 0.0, z = 0.0}
sound: “sound.ogg”
resource: “MyResource” volume: 1

1
  exports["PendingSound"]:PlayLocalSound({x = 0.0, y = 0.0, z = 0.0}, "sound.ogg", "MyResource", 1)

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:PlayLocalSound({x = 0.0, y = 0.0, z = 0.0}, "sound.ogg", GetCurrentResourceName(), 1)

PlayLocalSoundURL - Client

Minimum Version Number: 2.0 “The Entity Update”

1
exports["PendingSound"]:PlayLocalSoundURL(pos, url, volume)

E.G.:
pos: {x = 0.0, y = 0.0, z = 0.0}
url: “https://mywebsite.com/mymp3.mp3”
volume: 1

PlayLocalSoundURL - Server

Minimum Version Number: 2.0 “The Entity Update”

1
exports["PendingSound"]:PlayLocalSoundURL(pos, url, volume)

E.G.:
pos: {x = 0.0, y = 0.0, z = 0.0}
url: “https://mywebsite.com/mymp3.mp3”
volume: 1


PlaySoundFromEntity - Client

Minimum Version Number: 2.0 “The Entity Update”

1
exports["PendingSound"]:PlaySoundFromEntity(sound, resource, entity, volume)

E.G.:
sound: “sound.ogg”
resource: “MyResource” entity: GetPlayerPed(-1) volume: 1

1
exports.PendingSound:PlaySoundFromEntity("sound.ogg", "MyResource", GetPlayerPed(-1), 1)

You can combat repeating “MyResource” by doing the following:

1
exports.PendingSound:PlaySoundFromEntity("sound.ogg", GetCurrentResourceName(), GetPlayerPed(-1), 1)

PlaySoundFromEntityURL - Client

Minimum Version Number: 2.0 “The Entity Update”

1
exports["PendingSound"]:PlaySoundFromEntity(url, entity, volume)

E.G.:
url: “https://mywebsite.com/mymp3.mp3”
entity: GetPlayerPed(-1) volume: 1

1
exports.PendingSound:PlaySoundFromEntity("https://mywebsite.com/mymp3.mp3", GetPlayerPed(-1), 1)

StopSound - Client

1
exports["PendingSound"]:StopSound(name, resource)

E.G.:
name: “sound.ogg”
resource: “MyResource”

1
exports["PendingSound"]:StopSound("sound.ogg", "MyResource")

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:StopSound("sound.ogg", GetCurrentResourceName())

StopSound - Server

1
exports["PendingSound"]:StopSound(src, name, resource)

E.G.:
src: -1
name: “sound.ogg”
resource: “MyResource”

1
exports["PendingSound"]:StopSound(-1, "sound.ogg", "MyResource")

You can combat repeating “MyResource” by doing the following:

1
exports["PendingSound"]:StopSound(-1, "sound.ogg", GetCurrentResourceName())

StopSoundURL - Client

1
exports["PendingSound"]:StopSoundURL(url)

E.G.:
url: “https://mywebsite.com/mymp3.mp3”

1
exports["PendingSound"]:StopSoundURL("https://mywebsite.com/mymp3.mp3")

StopSoundURL - Server

1
exports["PendingSound"]:StopSoundURL(src, url)

E.G.:
src: -1
url: “https://mywebsite.com/mymp3.mp3”

1
exports["PendingSound"]:StopSoundURL(-1, "https://mywebsite.com/mymp3.mp3")

StopSoundFromEntity - Client

Minimum Version Number: 2.0 “The Entity Update”

1
exports["PendingSound"]:StopSoundFromEntity(Entity)

entity: GetPlayerPed(-1)

This post is licensed under CC BY 4.0 by the author.