I’m looking for a /clear command for chat, is this already made or do I need to make it?
You need to make it yourself, don’t think anyone has made/released a version here.
Okay cheers, I did some searching. Just wanted to check, rather than making one when someone has released one.
Pretty sure all you need to do is trigger this client event chat:clear
So a very simple client script example would be:
client.lua
RegisterCommand('clear', function()
TriggerEvent('chat:clear')
end, false)
Haven’t tested it but I think it should work just fine.
(This’d clear it just for the user that ran the command btw, not for all players currently online)
yeah, I’m just trying to set it as a whole server function, which requires admin permissions.
local admin = {}
AddEventHandler('chat:clear', function(source, name, msg)
player = GetPlayerIdentifiers(source)[1]
local result = MySQL.Sync.fetchAll(
'SELECT * FROM users WHERE identifier = @identifier',
{
['@identifier'] = player
}
)
for i=1, #result, 1 do
local sm = stringsplit(msg, " ");
if sm[1] == "/clear" then
if #admin == 0 then
TriggerClientEvent('chatMessage', source, "^1SYSTEM", {255, 0, 0}, "Insufficient Permissions!")
else
if result[i].group == 'superadmin' or 'admin' then
for _,id in ipairs(admin) do
TriggerEvent('chat:clear')
CancelEvent()
end
else
TriggerClientEvent('chatMessage', source, "^1SYSTEM", {255, 0, 0}, "Insufficient Permissions!")
end
end
end
end
end, false)
RegisterServerEvent('serverjoin')
AddEventHandler('serverjoin', function()
local id = source
local player = GetPlayerIdentifiers(id)[1]
local result = MySQL.Sync.fetchAll(
'SELECT * FROM users WHERE identifier = @identifier',
{
['@identifier'] = player
}
)
for i=1, #result, 1 do
if result[i].group == 'superadmin' or 'admin' then
table.insert(admin, id)
end
end
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
Just use @Vespura 's function and replace the false
with true
. Boom. You have now made it so people need the permission set in the server config (the aces seen at the bottom of the example config).
There’s no need to put this on the server, do some shit to the chat message event and run an SQL query. You’re vastly overcomplicating this.
If you want one command to clear the chat for everyone then yes you need to make it serverside.
was this ever made?
(20 char)
Server and client version yes.
Link to serverside version?
Bump bumpy for server side also…