Pulling user groups

Hello,

So I’m new to lua and derma. I’m still learning. I’ve been trying to follow wikis and have had no luck. I’m trying to pull user groups. Here is what I mean (probably really simple for most of you).

If the user is the rank superadmin then they can use the chat command !admin which opens a plain DFrame.

Hopefully you can help, thanks Munch

Sooo, you are looking for this?

[editline]31st July 2015[/editline]

There’s also http://wiki.garrysmod.com/page/Player/IsSuperAdmin



if ply:IsSuperAdmin() then...


[editline]31st July 2015[/editline]

robotboy you fucker

I love you too!

Ok, yeah I understand what you mean. Here is my basic derma. Currently F4 opens the dframe which is empty. I want to convert it so, it’s a chat command, which for the time being can be !test. It must only open if the user is in the group SuperAdmin.

http://pastie.org/10322756

Ok, that helped and I made into a chat command. However this chat command can be used by any group. How do I make it so only if the user is superadmin will the command work.

http://pastie.org/10322806

Just check if the player calling the chat command is an admin like so

[lua]
if CLIENT then
usermessage.Hook( “Openpls”, function()
local base = vgui.Create( ‘DFrame’ )
base:SetSize( 1280, 720 )
base:Center()
base:ShowCloseButton( true )
base:MakePopup()
end )
end

if SERVER then
hook.Add( “PlayerSay”, “Openpls”, function( ply, text, public )
text = string.lower( text )
if ( string.sub( text, 1, 5 ) == “!test” and ply:IsAdmin() ) then – will only run if the player is an admin.
umsg.Start( “Openpls”, ply )
umsg.End()
end
end )
end
[/lua]

Also, it’s a good idea to use string.sub for checking chat commands.

Thank you very much!

[editline]31st July 2015[/editline]

How would I make it so if the user isn’t in the groups defined, which is superadmin and admin (i added) it would print in chat a message?

[lua] hook.Add( “PlayerSay”, “Openpls”, function( ply, text, public )

	if ( not ply:IsAdmin() ) then
		ply:PrintMessage( HUD_PRINTTALK, "Oh noes! You aren't an admin!" )
		return
	end

	if ( string.sub( string.lower( text ), 1, 5 ) == "!test" ) then -- will only run if the player is an admin.
		umsg.Start( "Openpls", ply )
		umsg.End()
	end
	
end )

[/lua]

The return stops the rest of the code from running, if the player isn’t admin.

Thank you very much for your help!

[editline]31st July 2015[/editline]

How would I broadcast my DPanel. Here is my code:

[LUA]
if CLIENT then
usermessage.Hook( “Openpls”, function()
local base = vgui.Create( ‘DFrame’ )
base:SetSize( 300, 120 )
base:SetTitle( “Cease Fire” )
base:Center()
base:ShowCloseButton( true )
base:MakePopup()
base:SetDraggable( false )

	function base:Paint( w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 18, 18, 18, 250 ) )
	end
	
	local mess = vgui.Create( 'DPanel' )
		mess:SetSize( 400, 100 )
		mess:SetPos( 20, 20 )
		mess:SetVisible( false )
		mess:MakePopup()
		
		function mess:Paint( w, h )
			draw.RoundedBox( 0, 0, 0, w, h, Color( 18, 18, 18, 150 ) )
		end

[/LUA]

Where I create the DPanel mess. By default it isn’t visible. Essentially when someone clicks a button it sets the visibility to true but this only happens to the client. When the button is clicked to set it visible I want every connected player to see it.