forked from mikigoalie/gta_sound_tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
59 lines (46 loc) · 1.46 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local interfaceReady = false
local soundIds = {}
RegisterNUICallback('loaded', function(data, cb)
print('LOADED')
interfaceReady = true
cb(1)
end)
local function loaded()
Wait(500)
while not interfaceReady do
Wait(100)
end
local loadFile = LoadResourceFile(GetCurrentResourceName(), "soundNames.json")
local fileContent = json.decode(loadFile)
SendNUIMessage({ action = "loadSounds", data = fileContent })
end CreateThread(loaded)
RegisterNUICallback('playSound', function(data, cb)
local soundHandle = GetSoundId()
soundIds[soundHandle] = { audioName = data.audioName, audioRef = data.audioRef, audioId = data.audioId }
PlaySoundFrontend(soundHandle, data.audioName, data.audioRef, true)
ReleaseSoundId(soundHandle)
CreateThread(function()
while not HasSoundFinished(soundHandle) do
Wait(100)
end
SendNUIMessage({ action = "soundFinished", soundId = data.audioId })
end)
cb(1)
end)
RegisterNUICallback('stopSounds', function(data, cb)
for id in pairs(soundIds) do
if not HasSoundFinished(id) then
StopSound(id)
end
id = nil
end
cb(1)
end)
RegisterCommand('testsounds', function()
local hasFocus = IsNuiFocused()
SetNuiFocus(not hasFocus, not hasFocus)
SendNUIMessage({ action = "displayInterface", open = not hasFocus })
end)
RegisterNUICallback('closeInterface', function()
SetNuiFocus(false, false)
end)