diff --git a/ext/system-resources/resources/chat/cl_chat.lua b/ext/system-resources/resources/chat/cl_chat.lua index 0834bd3a61..f1e041d464 100644 --- a/ext/system-resources/resources/chat/cl_chat.lua +++ b/ext/system-resources/resources/chat/cl_chat.lua @@ -163,22 +163,22 @@ RegisterRawNuiCallback('chatResult', function(requestData, cb) end) local function refreshCommands() - if GetRegisteredCommands then - local registeredCommands = GetRegisteredCommands() - - local suggestions = {} - - for _, command in ipairs(registeredCommands) do - if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'toggleChat' then - table.insert(suggestions, { - name = '/' .. command.name, - help = '' - }) - end + local registeredCommands = GetRegisteredCommands() + if not next(registeredCommands) then return end + + local suggestions = {} + + for i = 1, #registeredCommands do + local command = registeredCommands[i] + if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'openChat' then + suggestions[#suggestions + 1] = { + name = '/' .. command.name, + help = '' + } end - - TriggerEvent('chat:addSuggestions', suggestions) end + + TriggerEvent('chat:addSuggestions', suggestions) end local function refreshThemes() @@ -208,18 +208,26 @@ local function refreshThemes() }) end -AddEventHandler('onClientResourceStart', function(resName) - Wait(500) +local commandsRefreshScheduled = false - refreshCommands() - refreshThemes() -end) +local function scheduleCommandsRefresh() + if commandsRefreshScheduled then return end -AddEventHandler('onClientResourceStop', function(resName) - Wait(500) + commandsRefreshScheduled = true - refreshCommands() - refreshThemes() + SetTimeout(500, function() + commandsRefreshScheduled = false + refreshCommands() + refreshThemes() + end) +end + +AddEventHandler('onClientResourceStart', function(_) + scheduleCommandsRefresh() +end) + +AddEventHandler('onClientResourceStop', function(_) + scheduleCommandsRefresh() end) RegisterNUICallback('loaded', function(data, cb)