Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions ext/system-resources/resources/chat/cl_chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Loading