mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(client/notification): add support for native audio sounds (#455)
This commit is contained in:
15
imports/requestAudioBank/client.lua
Normal file
15
imports/requestAudioBank/client.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
---Loads audio bank
|
||||
---@param audioBank string
|
||||
---@param timeout number?
|
||||
---@return boolean
|
||||
function lib.requestAudioBank(audioBank, timeout)
|
||||
RequestScriptAudioBank(audioBank, false)
|
||||
|
||||
if not coroutine.isyieldable() then return true end
|
||||
|
||||
return lib.waitFor(function()
|
||||
if RequestScriptAudioBank(audioBank, false) then return true end
|
||||
end, ("failed to load audiobank '%s'"):format(audioBank), timeout or 500)
|
||||
end
|
||||
|
||||
return lib.requestAudioBank
|
||||
@@ -14,6 +14,9 @@
|
||||
---@field iconAnimation? IconAnimationType;
|
||||
---@field iconColor? string;
|
||||
---@field alignIcon? 'top' | 'center';
|
||||
---@field sound? {bank?: string, set: string, name: string}
|
||||
|
||||
local enableSound = GetConvar('ox:enableSound', 'true') == 'true'
|
||||
|
||||
---`client`
|
||||
---@param data NotifyProps
|
||||
@@ -23,6 +26,18 @@ function lib.notify(data)
|
||||
action = 'notify',
|
||||
data = data
|
||||
})
|
||||
if not enableSound then return end
|
||||
if data.sound then
|
||||
if data.sound?.bank then
|
||||
lib.requestAudioBank(data.sound.bank)
|
||||
end
|
||||
local soundId = GetSoundId()
|
||||
PlaySoundFrontend(soundId, data.sound.name, data.sound.set, true)
|
||||
ReleaseSoundId(soundId)
|
||||
if data.sound?.bank then
|
||||
ReleaseNamedScriptAudioBank(data.sound.bank)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@class DefaultNotifyProps
|
||||
|
||||
Reference in New Issue
Block a user