mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-02-15 20:03:05 +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:addTemplate')
|
||||||
RegisterNetEvent('chat:addMessage')
|
RegisterNetEvent('chat:addMessage')
|
||||||
RegisterNetEvent('chat:addSuggestion')
|
RegisterNetEvent('chat:addSuggestion')
|
||||||
|
RegisterNetEvent('chat:addSuggestions')
|
||||||
RegisterNetEvent('chat:removeSuggestion')
|
RegisterNetEvent('chat:removeSuggestion')
|
||||||
RegisterNetEvent('chat:clear')
|
RegisterNetEvent('chat:clear')
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ AddEventHandler('__cfx_internal:serverPrint', function(msg)
|
|||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = 'ON_MESSAGE',
|
type = 'ON_MESSAGE',
|
||||||
message = {
|
message = {
|
||||||
color = { 0, 0, 0 },
|
templateId = 'print',
|
||||||
multiline = true,
|
multiline = true,
|
||||||
args = { msg }
|
args = { msg }
|
||||||
}
|
}
|
||||||
@ -60,6 +61,15 @@ AddEventHandler('chat:addSuggestion', function(name, help, params)
|
|||||||
})
|
})
|
||||||
end)
|
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)
|
AddEventHandler('chat:removeSuggestion', function(name)
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = 'ON_SUGGESTION_REMOVE',
|
type = 'ON_SUGGESTION_REMOVE',
|
||||||
@ -103,9 +113,36 @@ RegisterNUICallback('chatResult', function(data, cb)
|
|||||||
cb('ok')
|
cb('ok')
|
||||||
end)
|
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)
|
RegisterNUICallback('loaded', function(data, cb)
|
||||||
TriggerServerEvent('chat:init');
|
TriggerServerEvent('chat:init');
|
||||||
|
|
||||||
|
refreshCommands()
|
||||||
|
|
||||||
cb('ok')
|
cb('ok')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -68,6 +68,9 @@ window.APP = {
|
|||||||
if (!suggestion.params) {
|
if (!suggestion.params) {
|
||||||
suggestion.params = []; //TODO Move somewhere else
|
suggestion.params = []; //TODO Move somewhere else
|
||||||
}
|
}
|
||||||
|
if (this.suggestions.find(a => a.name == suggestion.name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.suggestions.push(suggestion);
|
this.suggestions.push(suggestion);
|
||||||
},
|
},
|
||||||
ON_SUGGESTION_REMOVE({ name }) {
|
ON_SUGGESTION_REMOVE({ name }) {
|
||||||
|
@ -6,6 +6,7 @@ window.CONFIG = {
|
|||||||
templates: { //You can add static templates here
|
templates: { //You can add static templates here
|
||||||
'default': '<b>{0}</b>: {1}',
|
'default': '<b>{0}</b>: {1}',
|
||||||
'defaultAlt': '{0}',
|
'defaultAlt': '{0}',
|
||||||
|
'print': '<pre>{0}</pre>',
|
||||||
'example:important': '<h1>^2{0}</h1>'
|
'example:important': '<h1>^2{0}</h1>'
|
||||||
},
|
},
|
||||||
fadeTimeout: 7000,
|
fadeTimeout: 7000,
|
||||||
|
@ -34,7 +34,7 @@ AddEventHandler('__cfx_internal:commandFallback', function(command)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- player join messages
|
-- player join messages
|
||||||
AddEventHandler('playerConnecting', function()
|
AddEventHandler('chat:init', function()
|
||||||
TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) .. ' joined.')
|
TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) .. ' joined.')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -45,3 +45,35 @@ end)
|
|||||||
RegisterCommand('say', function(source, args, rawCommand)
|
RegisterCommand('say', function(source, args, rawCommand)
|
||||||
TriggerClientEvent('chatMessage', -1, (source == 0) and 'console' or GetPlayerName(source), { 255, 255, 255 }, rawCommand:sub(5))
|
TriggerClientEvent('chatMessage', -1, (source == 0) and 'console' or GetPlayerName(source), { 255, 255, 255 }, rawCommand:sub(5))
|
||||||
end)
|
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