93 lines
2.5 KiB
Lua
93 lines
2.5 KiB
Lua
|
RegisterServerEvent('chat:init')
|
||
|
RegisterServerEvent('chat:addTemplate')
|
||
|
RegisterServerEvent('chat:addMessage')
|
||
|
RegisterServerEvent('chat:addSuggestion')
|
||
|
RegisterServerEvent('chat:removeSuggestion')
|
||
|
RegisterServerEvent('_chat:messageEntered')
|
||
|
RegisterServerEvent('chat:server:ClearChat')
|
||
|
RegisterServerEvent('__cfx_internal:commandFallback')
|
||
|
|
||
|
RegisterNetEvent('playerJoining')
|
||
|
|
||
|
AddEventHandler('_chat:messageEntered', function(author, color, message)
|
||
|
if not message or not author then return end
|
||
|
if not WasEventCanceled() then
|
||
|
local time = os.date(Config.DateFormat)
|
||
|
TriggerClientEvent('chat:addMessage', -1, {
|
||
|
template = '<div class="chat-messagedefault defaultmessage"><i class="fas fa-message"></i> <b><span style="color: #ffffff">{0}</span> <span style="font-size: 14px; color: #e1e1e1;">{2}</span></b><div style="margin-top: 5px; font-weight: 300;">{1}</div></div>',
|
||
|
args = { author, message, time }
|
||
|
})
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
AddEventHandler('__cfx_internal:commandFallback', function(command)
|
||
|
local name = GetPlayerName(source)
|
||
|
|
||
|
TriggerEvent('chatMessage', source, name, '/' .. command)
|
||
|
|
||
|
if not WasEventCanceled() then
|
||
|
TriggerClientEvent('chatMessage', -1, name, {255, 255, 255}, '/' .. command)
|
||
|
end
|
||
|
|
||
|
CancelEvent()
|
||
|
end)
|
||
|
|
||
|
RegisterCommand('say', function(source, args, rawCommand)
|
||
|
TriggerClientEvent('chatMessage', -1, (source == 0) and 'console' or GetPlayerName(source), {255, 255, 255}, rawCommand)
|
||
|
end)
|
||
|
|
||
|
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('onServerResourceStart', function(resName)
|
||
|
Wait(500)
|
||
|
|
||
|
for _, player in ipairs(GetPlayers()) do
|
||
|
refreshCommands(player)
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
AddEventHandler("chatMessage", function(source, color, message)
|
||
|
local src = source
|
||
|
args = stringsplit(message, " ")
|
||
|
CancelEvent()
|
||
|
if string.find(args[1], "/") then
|
||
|
local cmd = args[1]
|
||
|
table.remove(args, 1)
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
commands = {}
|
||
|
commandSuggestions = {}
|
||
|
|
||
|
function starts_with(str, start)
|
||
|
return str:sub(1, #start) == start
|
||
|
end
|
||
|
|
||
|
function stringsplit(inputstr, sep)
|
||
|
if sep == nil then
|
||
|
sep = "%s"
|
||
|
end
|
||
|
local t={} ; i=1
|
||
|
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
|
||
|
t[i] = str
|
||
|
i = i + 1
|
||
|
end
|
||
|
return t
|
||
|
end
|