How to make an autorun script that autobans through ulx
4 replies, posted
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.
[code]
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)
[/code]
autorun/server
Next time, I think you should try a Google search first.
[QUOTE=stickman14714;50979211][code]
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)
[/code]
autorun/server
Next time, I think you should try a Google search first.[/QUOTE]
That won't even work...
[code]
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 )
[/code]
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.
[QUOTE=xbeastguyx;50979738]That won't even work...
[code]
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 )
[/code]
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.[/QUOTE]
My bad then, use beastguy's example as it looks to run better.
[QUOTE=xbeastguyx;50979738]That won't even work...
[code]
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 )
[/code]
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.[/QUOTE]
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.
Sorry, you need to Log In to post a reply to this thread.