chat: add suggestions for commands, reduce 'joined' spam, make server prints white

This commit is contained in:
moscovium
2018-02-20 12:01:29 +01:00
parent da7bcd01f4
commit 7fe212f655
4 changed files with 75 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ RegisterNetEvent('chatMessage')
RegisterNetEvent('chat:addTemplate')
RegisterNetEvent('chat:addMessage')
RegisterNetEvent('chat:addSuggestion')
RegisterNetEvent('chat:addSuggestions')
RegisterNetEvent('chat:removeSuggestion')
RegisterNetEvent('chat:clear')
@@ -35,7 +36,7 @@ AddEventHandler('__cfx_internal:serverPrint', function(msg)
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = { 0, 0, 0 },
templateId = 'print',
multiline = true,
args = { msg }
}
@@ -60,6 +61,15 @@ AddEventHandler('chat:addSuggestion', function(name, help, params)
})
end)
AddEventHandler('chat:addSuggestions', function(suggestions)
for _, suggestion in ipairs(suggestions) do
SendNUIMessage({
type = 'ON_SUGGESTION_ADD',
suggestion = suggestion
})
end
end)
AddEventHandler('chat:removeSuggestion', function(name)
SendNUIMessage({
type = 'ON_SUGGESTION_REMOVE',
@@ -103,9 +113,36 @@ RegisterNUICallback('chatResult', function(data, cb)
cb('ok')
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)) then
table.insert(suggestions, {
name = '/' .. command.name,
help = ''
})
end
end
TriggerEvent('chat:addSuggestions', suggestions)
end
end
AddEventHandler('onClientResourceStart', function(resName)
Wait(500)
refreshCommands()
end)
RegisterNUICallback('loaded', function(data, cb)
TriggerServerEvent('chat:init');
refreshCommands()
cb('ok')
end)