mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-02-13 09:42:53 +08:00
chat: add suggestions for commands, reduce 'joined' spam, make server prints white
This commit is contained in:
parent
da7bcd01f4
commit
7fe212f655
@ -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)
|
||||
|
||||
|
@ -68,6 +68,9 @@ window.APP = {
|
||||
if (!suggestion.params) {
|
||||
suggestion.params = []; //TODO Move somewhere else
|
||||
}
|
||||
if (this.suggestions.find(a => a.name == suggestion.name)) {
|
||||
return;
|
||||
}
|
||||
this.suggestions.push(suggestion);
|
||||
},
|
||||
ON_SUGGESTION_REMOVE({ name }) {
|
||||
|
@ -6,6 +6,7 @@ window.CONFIG = {
|
||||
templates: { //You can add static templates here
|
||||
'default': '<b>{0}</b>: {1}',
|
||||
'defaultAlt': '{0}',
|
||||
'print': '<pre>{0}</pre>',
|
||||
'example:important': '<h1>^2{0}</h1>'
|
||||
},
|
||||
fadeTimeout: 7000,
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user