Hello!
Some time in your life as a user on Fivem you have probably encountered people spamming the chat with aids and you wanted to kill them so hard that you left the server because it got annoying.
Good news for you! I’ve made some simple but useful code that will stop players from spamming the chat with aids…
Please look under the “Mute” command if you want to add a permission system or something to stop random people from muting everyone and being a dick about it.
And if you want to change the delay between messages you can change the “max_delay” variable to your desired time.
local current_messages = {}
local max_delay = 5
local muted_players = {}
function Get_Messagedata(s)
if current_messages[s] == nil then
return 6
end
return (os.time() - current_messages[s]), max_delay + (current_messages[s] - os.time())
end
function Set_UserMute(user, time)
muted_players[user] = os.time() + (time * 60)
end
function Get_UserMute(user)
if muted_players[user] == nil then
return 0
end
return muted_players[user] - os.time()
end
function timeCount(numSec)
local nSeconds = numSec
if nSeconds == 0 then
return 0
else
local nHours = math.floor(nSeconds/3600);
local nMins = math.floor(nSeconds/60 - (nHours*60));
local nSecs = math.floor(nSeconds - nHours*3600 - nMins *60);
return nHours,nMins,nSecs
end
end
function checkIfUserUserIsOnCoolown(author)
if not WasEventCanceled() then
local Msg_time, time_left = Get_Messagedata(author)
if Msg_time <= max_delay then
TriggerClientEvent("chatMessage", author, "^1Please wait ".. time_left.. " seconds before sending another message!")
CancelEvent()
else
current_messages[author] = os.time()
end
end
end
function checkIfUserIsMuted(author)
if not WasEventCanceled() then
local user = GetPlayerIdentifiers(author)
for i=1,10 do
if user[i] then
thing = string.find(user[i], "license:")
if thing then
local time_left = Get_UserMute(thing)
if time_left ~= 0 then
local hour, min, sec = timeCount(time_left)
if hour > 0 then
TriggerClientEvent("chatMessage", author, "^1You are muted! Try again in "..hour.." hour(s) and "..min.." minute(s) and "..sec.." second(s)")
CancelEvent()
return true
elseif min > 0 then
TriggerClientEvent("chatMessage", author, "^1You are muted! Try again in "..min.." minute(s) and "..sec.." second(s)")
CancelEvent()
return true
else
TriggerClientEvent("chatMessage", author, "^1You are muted! Try again in "..sec.." seconds(s)")
CancelEvent()
return true
end
end
end
end
end
end
end
RegisterCommand("mute", function(s,a,r)
local license = ""
local user = GetPlayerIdentifiers(a[1]) local time = a[2]
for i=1,10 do
if user[i] then
thing = string.find(user[i], "license:")
if thing then
license = thing
end
end
end
-- change the true to your permission system check thing
if true then
if Get_UserMute(license) ~= 0 then
TriggerClientEvent("chatMessage", s, "^1User is already muted!")
else
Set_UserMute(license, time)
end
end
end, false)
AddEventHandler('chatMessage', function(author, color, text)
if checkIfUserIsMuted(author) ~= true then
checkIfUserUserIsOnCoolown(author)
end
end)
The mute code download : server.lua (3.4 KB)
For you lazy bastards that doesn’t want to create resources and just want to download and put it in your resources,
chatmute.zip (1.4 KB)
Yes I’m not the greatest coder but it works
/DeOnyx (aka Z3phyrn because I couldn’t change my name on the forum)