Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions resources/[gameplay]/chat/sv_chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ end)
local hooks = {}
local hookIdx = 1

local EnterJoinMessageForStaffOnly = true
local StaffGroups = {
'superadmin',
'admin',
'mod'
}
local isESX = false
local ESX = nil
local QBCore = nil

if isESX then
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
else
QBCore = exports["qb-core"]:GetCoreObject()
end

exports('registerMessageHook', function(hook)
local resource = GetInvokingResource()
hooks[hookIdx + 1] = {
Expand Down Expand Up @@ -205,10 +221,6 @@ AddEventHandler('_chat:messageEntered', function(author, color, message, mode)
if not message or not author then
return
end

local source = source

routeMessage(source, author, message, mode)
end)

AddEventHandler('__cfx_internal:commandFallback', function(command)
Expand All @@ -226,20 +238,53 @@ AddEventHandler('playerJoining', function()
return
end

TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) .. ' joined.')
showOnlyForAdmins(function(target)
if not EnterJoinMessageForStaffOnly then target = -1 end
TriggerEvent('okokChat:ServerMessage', "linear-gradient(90deg, rgba(42, 42, 42, 0.9) 0%, rgba(19, 138, 70, 0.9) 100%)", "#1ebc62", "fas fa-cog", "SYSTEM", "", '<b>'..GetPlayerName(source)..'</b> joined.', target)
-- this TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) .. ' joined.')
end)
end)

AddEventHandler('playerDropped', function(reason)
if GetConvarInt('chat_showQuits', 1) == 0 then
return
end

TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) ..' left (' .. reason .. ')')
showOnlyForAdmins(function(target)
if not EnterJoinMessageForStaffOnly then target = -1 end
TriggerEvent('okokChat:ServerMessage', "linear-gradient(90deg, rgba(42, 42, 42, 0.9) 0%, rgba(101, 0, 0, 0.9) 100%)", "#ff0000", "fas fa-cog", "SYSTEM", "", '<b>'..GetPlayerName(source)..'</b> left.', target)
-- this TriggerClientEvent('chatMessage', -1, '', { 255, 255, 255 }, '^2* ' .. GetPlayerName(source) ..' left (' .. reason .. ')')
end)
end)

RegisterCommand('say', function(source, args, rawCommand)
routeMessage(source, (source == 0) and 'console' or GetPlayerName(source), rawCommand:sub(5), nil, true)
end)
function isAdmin(xPlayer)
for k,v in ipairs(StaffGroups) do
if isESX then
if xPlayer.getGroup() == v then
return true
end
else
if QBCore.Functions.GetPermission(xPlayer.PlayerData.source) == v then
return true
end
end
end
return false
end

function showOnlyForAdmins(admins)
for k,v in ipairs(ESX.GetPlayers()) do
local xPlayer = nil
if isESX then
xPlayer = ESX.GetPlayerFromId(v)
else
xPlayer = QBCore.Functions.GetPlayer(v)
end
if isAdmin(xPlayer) then
admins(v)
end
end
end

-- command suggestions for clients
local function refreshCommands(player)
Expand Down Expand Up @@ -290,4 +335,4 @@ end)

AddEventHandler('onResourceStop', function(resName)
unregisterHooks(resName)
end)
end)