Is there a way to check how many admins are on a server?
[highlight](User was banned for this post ("Wrong section" - mahalis))[/highlight]
[QUOTE=HeavyMtl123;21363704]Is there a way to check how many admins are on a server?[/QUOTE]
[lua]
local admins = 0
for k,v in pairs(player.GetAll()) dp
if v:IsAdmin() then
admins = admins + 1
end
end
[/lua]
Ah thankyou!
[QUOTE=HeavyMtl123;21363718]Ah thankyou![/QUOTE]
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?
[QUOTE=HeavyMtl123;21382491]Also, one last question, how would I make it so I can have a counter on the HUD of In-server admins?[/QUOTE]
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:
[QUOTE=HeavyMtl123;21382491]Also, one last question, how would I make it so I can have a counter on the HUD of In-server admins?[/QUOTE]
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!
[QUOTE=bromvlieg;21382555]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![/QUOTE]
Wouldn't it be more efficient to get the number of admins say every 30 seconds / minute instead of every frame?
[QUOTE=sintwins;21382928]Wouldn't it be more efficient to get the number of admins say every 30 seconds / minute instead of every frame?[/QUOTE]
Dont make it overcomplicated please for him -_-
[QUOTE=bromvlieg;21383520]Dont make it overcomplicated please for him -_-[/QUOTE]
Efficiency is better than complication.
[QUOTE=Jamie932;21383689]Efficiency is better than complication.[/QUOTE]
[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:
[QUOTE=Jamie932;21383689]Efficiency is better than complication.[/QUOTE]
Does it really matter?
If it was serverside I would say it matters.
But it's clientside.
[QUOTE=Bigdogbikers;21405290]Does it really matter?
If it was serverside I would say it matters.
But it's clientside.[/QUOTE]
It's just as important client-side.
[QUOTE=sintwins;21382928]Wouldn't it be more efficient to get the number of admins say every 30 seconds / minute instead of every frame?[/QUOTE]
Wouldn't it be more efficient to check once when you join the server then update the count as players join and leave?
[QUOTE=Crazy Quebec;21407274]Wouldn't it be more efficient to check once when you join the server then update the count as players join and leave?[/QUOTE]
That would be even better :D
[code]
local admins = 0
function PlayerConnect(ply)
if ply:IsAdmin() then admins = admins + 1
end
end
[/code]
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.
[QUOTE=MakeR;21421811][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.[/QUOTE]
Then you could maybe every 10 or so minutes loop through the players and check how many admins are in the server to resync it. :D
[QUOTE=MakeR;21421811][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.[/QUOTE]
[b][url=wiki.garrysmod.com/?title=Gamemode.PlayerInitialSpawn]Gamemode.PlayerInitialSpawn [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[QUOTE=sintwins;21425248]Then you could maybe every 10 or so minutes loop through the players and check how many admins are in the server to resync it. :D[/QUOTE]
Yes, you could.
[QUOTE=CombineGuru;21425296]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img][/QUOTE]
Ok then the server could send usermessages to the client, but would that be more inefficent than looping through the players every 30 seconds?
[QUOTE=CombineGuru;21425296][b][url=wiki.garrysmod.com/?title=Gamemode.PlayerInitialSpawn]Gamemode.PlayerInitialSpawn [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img]
[img]http://wiki.garrysmod.com/images/9/9f/NewerServer.png[/img][/QUOTE]
Forgot this was being done clientside.
Somewhat hacky but you could hook to player leave and join messages.
Their adminship probably wouldn't be assigned at join time.
Why not just make a console command to print the number of admins and identify them?
[lua]
concommand.Add( "printadmins", function()
local ac = 0
for _, v in ipairs( player.GetAll() ) do
if v:IsSuperAdmin() then
print( v:Nick() .. " is a super admin." )
ac = ac + 1
elseif v:IsAdmin() then
print( v:Nick() .. " is an admin." )
ac = ac + 1
else
print( v:Nick() .. " is a regular player." )
end
end
print( "There are currently " .. ac .. " admins on the server." )
end )
[/lua]
[QUOTE=cheiftiger;21428692]Why not just make a console command to print the number of admins and identify them?[/QUOTE]
Because that's too simple a solution. We want it to be fully automated. It's a problem and we're trying to find the best way to solve it.
You could use [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerAuthed]Gamemode.PlayerAuthed [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=wiki.garrysmod.com/?title=Gamemode.EntityRemoved]Gamemode.EntityRemoved [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] which both are shared according to Wiki. EntityRemoved however isn't very reliable, so you might end up with too many admins.
Sorry, you need to Log In to post a reply to this thread.