Checking For Admins

Is there a way to check how many admins are on a server?


(User was banned for this post ("Wrong section" - mahalis))

[lua]
local admins = 0
for k,v in pairs(player.GetAll()) dp
if v:IsAdmin() then
admins = admins + 1
end
end
[/lua]

Ah thankyou!

epic fast answer ftw!:smug:

[lua]
concommand.Add(“AdminCheck”, function(ply, cmd, args)
local admins = 0
for k,v in pairs(player.GetAll()) do
if v:IsAdmin() then
admins = admins + 1
end
end
ply:ChatPrint(admins)
end)
[/lua]

Also, one last question, how would I make it so I can have a counter on the HUD of In-server admins?

You wil have to hook the HUDPaint, and draw it in!

hook.Add(“HUDPaint”,“some_fucked_up_name”, function()

end)

Thanks again, lightning quick as usual :dance:

You wil have to hook the HUDPaint, and draw it in!
[lua]
hook.Add(“HUDPaint”,“some_fucked_up_name”, function() // ad zeh hook whit zeh functio!
local admins = 0 // make the admin number varible
for k,v in pairs(player.GetAll()) do // loop truw all players
if v:IsAdmin() then // Yaw an admin!
admins = admins + 1 // Oh goodie! an admin
end // end the if
end // end the loop
draw.SimpleText("Admins: " … admins, “Default”, 0, 10, Color(0,0,0,255))// draw it
end)
[/lua]
However, untested. But it should work if my grammar doenst fail on me!

Wouldn’t it be more efficient to get the number of admins say every 30 seconds / minute instead of every frame?

Dont make it overcomplicated please for him -_-

Efficiency is better than complication.

[lua]
local admins = 0

timer.Create(“Admin_Counter”,30,0,function()
admins = 0
for k,v in pairs(player.GetAll()) do
if v:IsAdmin() then
admins = admins + 1
end
end
end)

hook.Add(“HUDPaint”,“Admin_Draw_Count”, function()
draw.SimpleText("Admins: " … admins, “Default”, 0, 10, Color(0,0,0,255))
end)
[/lua]

ARE YOU HAPPY NOW :argh:

It’s not overcomplicated… I just did not know how to check for admins and to add them to a counter on the Hud. I know about timers and what not.
And thanks bromvlieg for being so helpful :3:

Does it really matter?

If it was serverside I would say it matters.

But it’s clientside.

It’s just as important client-side.

Wouldn’t it be more efficient to check once when you join the server then update the count as players join and leave?

That would be even better :smiley:



local admins = 0

function PlayerConnect(ply)

if ply:IsAdmin() then admins = admins + 1

end 

end


Would that be it?

[lua]local admins = 0;

hook.Add(“PlayerInitialSpawn”, function(ply)
if ply:IsAdmin() then
admins = admins + 1;
end
end);

hook.Add(“PlayerDisconnect”, function(ply)
if ply:IsAdmin() then
admins = admins - 1;
end
end);[/lua]

The only problem with this is that when an admin is kicked through the console, or through gatekeeper (unlikely) the admin count will not be reduced.