chatMessage disable issue

Hello! I’ve been looking for help regarding an issue I have. I’ve been attempting to disable chat messages in my RP server, while sending a notification using ESX, the problem is though, even though that works, every time I use a command and it doesn’t successfully execute, I get the esx.notification sent anyway. I’m gonna attach my script, hoping for a fix <3

AddEventHandler('chatMessage', function(source, name, message)
    CancelEvent()
    TriggerClientEvent('esx:showNotification', source, 'Chat has been disabled. Please use ~r~/ooc')
end)
1 Like

Not sure if this is exactly what you’re looking for but I went into cl_chat.lua and commented the code around line 20 out to avoid it. They still can type and press enter but unless it’s a valid command it doesn’t go into the chat for everyone to see. We still use /ooc /twt, etc…

--[[
--deprecated, use chat:addMessage
AddEventHandler('chatMessage', function(author, color, text)
  local args = { text }
  if author ~= "" then
    table.insert(args, 1, author)
  end
  SendNUIMessage({
    type = 'ON_MESSAGE',
    message = {
      color = color,
      multiline = true,
      args = args
    }
  })
end)
--]]

I did manage to disable chat with no further issues, but I was wondering if there’s any possible way to trigger an Event ‘esx:showNotification’ to lay out a message saying “please use /ooc”.

Figured it out. Go into sv_chat.lua under the [system]\chat\ folder.

Line 15

    TriggerEvent('chatMessage', source, author, message)

Replace with

TriggerClientEvent('esx:showNotification', source, 'Chat has been disabled. Please use ~r~/ooc')
1 Like

Some tweaking made it work like a charm!

for anyone interested in making it work:

  1. read previous message and follow what @Lith did.

  2. Make sure you remove the following lines from the same file:

if not WasEventCanceled() then
    TriggerClientEvent('chatMessage', -1, author,  { 255, 255, 255 }, message)
end
2 Likes

awesome but how can i get just /ooc command working?
cause i want players to chat via /ooc. can explain?
i have roleplay chats installed