[Release] Simple banning system

Hi, I had to do this code for someone for whom the new Essentialmode ban system was not working so I decide to share it.

It is a basic system that checks if a player who is banned is connected to the server.

If this is the case, a check is carried out every 15 seconds to exclude them.
Apparently, the connection time is enough to make the check and the player is instantly expelled.

The script require Essentialmode and the bans table in the DB.

To use it, you just need to add this code to an existing resource or create one. Do not forget to add server_script '@mysql-async/lib/MySQL.lua' in the file _resource.lua if it is not already there.

local bannedUser = {}

TriggerEvent('es:addGroupCommand', 'banplayer', "admin", function(source, args, user)
    if args[2] then
        local src = args[2]
        local identifier = GetPlayerIdentifiers(src)[1]
        MySQL.Sync.execute('INSERT INTO bans (identifier, time, raison, duree) VALUES (@identifier, "1", "raison", "1")', {['@identifier'] = identifier})
        table.insert(bannedUser, identifier)
    end
end, function(source, args, user)
    TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end, {help = "Ban a player"})

AddEventHandler('onMySQLReady', function()
    local result = MySQL.Sync.fetchAll('SELECT * FROM bans')
    for i=1, #result do
        table.insert(bannedUser, result[i].identifier)
    end
end)

local function checkBannedUser()

    SetTimeout(15000, function()
        TriggerEvent('es:getPlayers', function(Users)
            for k, v in pairs(Users) do
                if Users[k] ~= nil then

                    local src = v.get('source')
                    local identifier = v.get('identifier')

                    for _, v in ipairs(bannedUser) do
                        if v == identifier then
                            DropPlayer(src, "You are banned from this server !")
                        end
                    end
                end
            end
        end)
        checkBannedUser()
    end)
end

checkBannedUser()
4 Likes

Why check every 15 seconds to check if a user is online that is banned and not when the playerConnecting event is fired?

Maybe because the client can bypass some events and passing other datas?
Just reducing the risk, not the solution obviously
Maybe a if user == nil then Drop should be a nice line :wink:

1 Like

It’s just a basic script that I do quickly for a quick need. That’s all. There will be no upgrade, it’s just to troubleshoot those who would need it.

This is unnecessary, es_admin already has an admin system. For who that don’t known, juste press “Origin” key, near Insert and delete.

Dude, this is a sharing, so firstly respect that. I can’t see any sharing from you.
Secondly, FYI, the es_admin is using NUI system which isn’t whished by all

1 Like

I would not even take the time to answer to that.

I respect your work, I just wanted to tell you that there was a better system for that.

1 Like

Atleast appreciate that he has shared this as it takes time to code dude. Not only that but your comment is wrong, the es_admin ban system does not even work properly. People can join back sometimes straight away or sometimes after restart.

Nice work! A lot of poeple will need this.

1 Like

.Doesnt work. Tried Testing it

It works, I have already tested it and the others do not seem to have any problems.

Wiould you mind helping me out and seeing where I’m going wrong?