How to make an autorun script that autobans through ulx

I need a way to make an autoban script that would go through ulx and autoban anyone who is superadmin on my server besides 2 steam_ids.
Im not sure where to start when making this script.
Any help is appreciated.



local blacklist = {
    "steamid",
    "steamid"
}

hook.Add("Think", "autoban_superadmin", function()
    for k,v in pairs (player.GetAll()) do
        if v:IsSuperAdmin() and !table.HasValue("blacklist", v:SteamID()) then
            RunConsoleCommand("ulx banid " .. v:SteamID() .. " 0")
        end
end)


autorun/server

Next time, I think you should try a Google search first.

That won’t even work…



local blacklist = {
    [ "STEAM_0:0:111" ] = true,
    [ "STEAM_0:1:111" ] = true,
}



local function checkForSuperAdmin()
    for _, ply in ipairs( player.GetAll() ) do
        if ply:IsUserGroup( "superadmin" ) and !blacklist[ ply:SteamID() ] then
            ulx.ban( Entity( 1 ), ply, 0, "Invalid SuperAdmin!" )
        end
    end
end
timer.Create( "CheckForSuperAdmin", 1, 0, checkForSuperAdmin )


Untested, but should work. Probably not the most efficient way to do this - if anyone knows a better way, feel free to let me know.

My bad then, use beastguy’s example as it looks to run better.

Just use NULL in the ulx.ban function, that basically alias to ULib.addBan which will set the name to “(Console)” in the ban reason considering said entity isn’t valid.

As for the superadmin check, it could probably just be done on PlayerInitialSpawn, if you wanted to check when groups changed you could use CAMI.PlayerUsergroupChanged, although I believe this will only be called if they were add through ulx.