Mail3ee / xsound

a small library for FiveM to play better sounds.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Improved audio library for FiveM

SoundSystem functions

1. Functions (client side)

Playing sound

  • PlayUrl(name, url, volume)
    Will play sound from url (can be heared everywhere)

  • PlayUrlPos(name, url, volume, Vector3 vec)
    Will play sound from url at x,y,z location


Manipulation with sound

  • Position(name, Vector3 vec)
    Will update location of sound

  • Distance(name, newDistance)
    Will set new playing distance from location

  • Destroy(name)
    Will destroy sound

  • Pause(name)
    Will pause sound

  • Resume(name)
    Will resume sound

  • setVolume(name,volume) volume is from 0.0 to 1.0
    Will set a new value to volume.

  • setVolumeMax(name,volume) volume is from 0.0 to 1.0
    will set new value to max volume.


Getting info about sound

  • soundExists(name)
    Will return true/false if sound exists

  • isPaused(name)
    Will return true/false if song is paused

  • isPlaying(name)
    Will return true/false if song is playing

  • isLooped(name)
    Will return true/false if sound is looped

  • getDistance(name)
    Will return distance in Integer

  • getVolume(name)
    Will return current volume of music.

  • getPosition(name)
    Will return vector3

  • getLink(name)
    Will return url link

  • getInfo(name)
    Will return an array with info of song..
    it will return

{
volume,   -- value from 0.0 to 1.0
url ,     -- sound url
id,       -- id 
position, -- will be nil if position isnt set.
distance, -- distance in integer
playing,  -- true/false
paused,   -- true/false
loop,     -- true/false
}

Example client

xSound = exports.xsound
Citizen.CreateThread(function()
    local pos = GetEntityCoords(PlayerPedId())
    xSound:PlayUrlPos("name","http://relisoft.cz/assets/brainleft.mp3",1,pos)
    xSound:Distance("name",100)
    
    Citizen.Wait(1000*30)
    xSound:Destroy("name")
end)

How to play youtube link

xSound = exports.xsound
Citizen.CreateThread(function()
    local pos = GetEntityCoords(PlayerPedId())
    xSound:PlayUrlPos("name","https://www.youtube.com/watch?v=6Dh-RL__uN4",1,pos)
    --some links will not work cause to copyright or autor did not allowed to play video from iframe.
    xSound:Distance("name",100)
    
    Citizen.Wait(1000*30)
    xSound:Destroy("name")
end)

Showcase what i did with my api

https://www.youtube.com/watch?v=OOf6PZFpfkI

https://www.youtube.com/watch?v=JRTVga_FwGw

Showcase how it can stream sound at game

https://www.youtube.com/watch?v=zyZmF5bRSA4

https://www.youtube.com/watch?v=19Q2GVYElSE

About

a small library for FiveM to play better sounds.

License:MIT License


Languages

Language:JavaScript 60.3%Language:Lua 33.3%Language:HTML 6.4%