Admin List

So I saw how some of these cheats on gmod.org have a “admin list” Where it lists all admins on the server and I thought that sounded fun. This is what I have so far, and it’s not exactly working to well, let me post the code.

[lua]
–making a font
surface.CreateFont(“coolvetica” , 20 , 500 , true , true , “AdminFont”)

function GetAdmins()
if ply:IsAdmin() then
draw.SimpleText(". .ply:Nick(). .",“AdminFont”,ScrW()*0.01,ScrH()*0.05,Color(255,104,86,255),0,0)
end
end[/lua]

Any errors? Also, I figured I wouldn’t need a concommand…was I wrong(I think I am, but not sure). I don’t get any errors here is my whole entire log.


maxplayers set to 1
Lua initialized (Lua 5.1)
Registering gamemode 'sandbox' derived from 'base'
ScriptEnforce is disabled
Executing listen server config file
exec: couldn't exec listenserver.cfg
InitFastCopy: only 51% fast props. Bug?
Lua initialized (Lua 5.1)
Registering gamemode 'sandbox' derived from 'base'
Sending 267 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Redownloading all lightmaps

Thanks for the help.

here, try this
[lua]
–making a font
surface.CreateFont(“coolvetica” , 20 , 500 , true , true , “AdminFont”)

function GetAdmins()
for k, v in pairs (player.GetAll()) do
if v:IsAdmin() or v:IsSuperAdmin() then do
draw.SimpleText(". .ply:Nick(). .",“AdminFont”,ScrW()*0.01,ScrH()*0.05,Color(255,104,86,255),0,0)
end
end
end
end
[/lua]
Fixed (I hope) and tweaked it a little bit to be more efficient.

Thank you, will test now.

[editline]08:05PM[/editline]

didn’t work, I did it a bit different then you.

[lua]–just doing this for ease
width = ScrW()
height = ScrH()
–making a font
surface.CreateFont(“coolvetica” , 20 , 500 , true , true , “AdminFont”)
–actual list
function GetAdmins()
for k, v in pairs (player.GetAll()) do
if v:IsAdmin() or v:IsSuperAdmin then do
draw.SimpleText(". .ply:Nick(). .",“AdminFont”,width0.01,height0.05,Color(255,1 04,86,255),0,0)
end
end
end
end[/lua]
Should I rearrange it the way you did it?

[editline]08:06PM[/editline]

Also, I am doing this is single player(since I would be an admin), should I test on an online server?

-snippity snip-

=, thanks! So I am guessing I can get rid off my font create.

[editline]08:20PM[/editline]

[lua\autorun\client\admins.lua:23] function arguments expected near ‘or’

=, sorry for the trouble!

uh there’s no ‘or’ near line 23

sorry I had some other code in there it’s this line

[lua]if v:IsAdmin or if v:IsSuperAdmin() then do[/lua]

oh, change v:IsAdmin to v:IsAdmin()

forgot argument brackets :slight_smile:

Oh wow! I can’t believe I didn’t spot that either! Thanks!

Line 10 is wrong. Do this.
[lua]draw.SimpleText(v:Nick(),“AdminFont”,width0.01,height0.05,Color(255,104,86,255),0,0)[/lua]

This should work I think
[lua]
–just doing this for ease
width = ScrW()
height = ScrH()

–making a font
surface.CreateFont(“coolvetica” , 20 , 500 , true , true , “AdminFont”)

–actual list
function GetAdmins()
for k, v in pairs (player.GetAll()) do
if v:IsAdmin() or v:IsSuperAdmin() then
draw.SimpleText(v:Nick(),“AdminFont”,width0.01,height0.05,Color(255,104,86,255),0,0)
end
end
end
hook.Add( “HUDPaint”, “GetAdmin-HUDPaint”, GetAdmins )
[/lua]

Trivkz is the only one with a chance of working so far, but you still need to implement a counter and offset the height, otherwise each one will draw on top of the next one.
I personally don’t bother with VGUI.
[lua]–[[ Admin Gettr ]]–

concommand.Add(“getadmins”, function()
print("===== Admins ======");
for _, ply in pairs(player.GetAll()) do
if (ply:IsAdmin()) then
print(ply:Name());
end
end
print("===================");
end);

concommand.Add(“getsuperadmins”, function()
print("=== SuperAdmins ===");
for _, ply in pairs(player.GetAll()) do
if (ply:IsSuperAdmin()) then
print(ply:Name());
end
end
print("===================");
end);[/lua]

Also, v:IsAdmin() will return true if they are a SuperAdmin, so you don’t need that check.

I see how yours works, but where do you “define” where the text will be printed?

It’s printed in console, so there is no VGUI.

[editline]02:44PM[/editline]

I just wiped this up, It’s properly not the best code, but I think it’s what you want.
[lua]
–Just doing this for ease
local Width = ScrW()
local Height = ScrH()
local Count = 0

–Making a font
surface.CreateFont( “coolvetica”, 20, 500, true, true, “AdminFont” )

–Table to store our admins in
local Admins = {}

–Actual list
function GetAdmins()

--Collect all our admins and put them in a table, then add a offset so they don't draw onto of each other
for k, v in pairs ( player.GetAll() ) do 
	if v:IsAdmin() then
		--Might not be the best way..
		Admins[Count] = v:Nick()
		Count = Count + 1
	end 
end

--Loop our Admins table and draw the admins
for k, v in pairs ( Admins ) do 
	--Draw it, v is the name, K is the admin number (20 is to make a bigger offset)
	draw.SimpleText( v, "AdminFont", Width * 0.1, Height * 0.5 + ( k * 20 ), Color(255,104,86,255), 0, 0 )
	--Reset the position, A little hacky..
	Count = 0
end

end
hook.Add( “HUDPaint”, “GetAdmin-HUDPaint”, GetAdmins )

[/lua]

Sorry I took so long to respond, wasn’t able to be on my computer. Thanks for the code will test now!

I’ve only known Lua for about a week now, yet I could do better than most of the codes in this thread. Damn lazy people.

Then let us see please?

Trivkz and Lexic are the only people that are actually making sense in this thread. The rest of the Lua is just plain wrong.

[editline]06:16PM[/editline]

Edit that, Lexic is the only person that is making sense.

My codes work…