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

@@ -34,7 +34,7 @@ AddEventHandler('__cfx_internal:commandFallback', function(command)
end)
-- player join messages
AddEventHandler('playerConnecting', function()
AddEventHandler('chat:init', function()
TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) .. ' joined.')
end)
@@ -44,4 +44,36 @@ end)
RegisterCommand('say', function(source, args, rawCommand)
TriggerClientEvent('chatMessage', -1, (source == 0) and 'console' or GetPlayerName(source), { 255, 255, 255 }, rawCommand:sub(5))
end)
-- command suggestions for clients
local function refreshCommands(player)
if GetRegisteredCommands then
local registeredCommands = GetRegisteredCommands()
local suggestions = {}
for _, command in ipairs(registeredCommands) do
if IsPlayerAceAllowed(player, ('command.%s'):format(command.name)) then
table.insert(suggestions, {
name = '/' .. command.name,
help = ''
})
end
end
TriggerClientEvent('chat:addSuggestions', player, suggestions)
end
end
AddEventHandler('chat:init', function()
refreshCommands(source)
end)
AddEventHandler('onServerResourceStart', function(resName)
Wait(500)
for _, player in ipairs(GetPlayers()) do
refreshCommands(player)
end
end)