From 2add4ba3257394a09879407462fadd5fb12bec9c Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 15 Aug 2023 10:22:15 +1000 Subject: [PATCH] refactor: fetch sounds when initially opening UI --- client/main.lua | 9 +-------- client/utils.lua | 6 ++++++ server/main.lua | 4 ++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/main.lua b/client/main.lua index 794e394b..66e3170c 100644 --- a/client/main.lua +++ b/client/main.lua @@ -37,20 +37,13 @@ end local nearbyDoors = {} local Entity = Entity -lib.callback('ox_doorlock:getDoors', false, function(data, sounds) +lib.callback('ox_doorlock:getDoors', false, function(data) doors = data for _, door in pairs(data) do createDoor(door) end - while not NuiHasLoaded do Wait(0) end - - SendNUIMessage({ - action = 'setSoundFiles', - data = sounds - }) - while true do table.wipe(nearbyDoors) local coords = GetEntityCoords(cache.ped) diff --git a/client/utils.lua b/client/utils.lua index e9683941..c95dd1be 100644 --- a/client/utils.lua +++ b/client/utils.lua @@ -228,11 +228,17 @@ local function openUi(id) if not NuiHasLoaded then NuiHasLoaded = true + SendNuiMessage(json.encode({ action = 'updateDoorData', data = doors }, { with_hole = false })) Wait(100) + + SendNUIMessage({ + action = 'setSoundFiles', + data = lib.callback.await('ox_doorlock:getSounds', false) + }) end SetNuiFocus(true, true) diff --git a/server/main.lua b/server/main.lua index cc9df3ba..52a4196a 100644 --- a/server/main.lua +++ b/server/main.lua @@ -104,6 +104,10 @@ local soundDirectory = Config.NativeAudio and 'audio/dlc_oxdoorlock/oxdoorlock' local fileFormat = Config.NativeAudio and '%.wav' or '%.ogg' local sounds = require 'server.utils'.getFilesInDirectory(soundDirectory, fileFormat) +lib.callback.register('ox_doorlock:getSounds', function() + return sounds +end) + local function createDoor(id, door, name) local double = door.doors door.id = id