Skip to content

Commit

Permalink
refactor: fetch sounds when initially opening UI
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Aug 15, 2023
1 parent b74f3dd commit 2add4ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 1 addition & 8 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2add4ba

Please sign in to comment.