Help with Derma Panels

Hi guys,
I am new in Garry’s Mod Lua and I tried to code myself and watched tutorials but I did not find anything for this.
So feel free to help me :3.

[Lua]
TAmount = 5
DAmount = 2

function TMenu(ply,text)
if(text == “!pass”) then
local Frame = vgui.Create( “DFrame” )
Frame:SetPos(surface.ScreenHeight() - 300 ,surface.ScreenWidth() - 1250)
Frame:SetSize( 500, 500 )
Frame:SetTitle( “TTT-Passes” )
Frame:SetVisible( true )
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 150, 150, 150,200 ) )
end

	local FrameView = vgui.Create( "DListView", Frame )
	FrameView:SetPos(50,70)
	FrameView:SetSize(400,400)
	FrameView:SetMultiSelect(false)
	FrameView:AddColumn("Type")
	FrameView:AddColumn("T-Amount")
	FrameView:AddColumn("D-Amount")
	FrameView.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color(100,100,100,200))
	end
end

end

hook.Add( “PlayerSay”,“OpenTMenu”, TMenu )
[/LUA]

Here are my questions.

I began programming with a Derma Panel that opens if you type in !pass but it doesn’t open. Why doesn’t it?

Is it possible to have a Derma List like this: https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/images/a/a4/Scoreboard.png,
and be able to press on a name to get some options like kick player or something? (If I didn’t explain well enough tell me I’ll try to draw it xD)

I have an error if I try to write
[LUA]
local FrameView = vgui.Create( “DListView”, Frame )
FrameView:SetPos(50,70)
FrameView:SetSize(400,400)
FrameView:SetMultiSelect(false)
FrameView:AddColumn(“Type”)
FrameView:AddColumn(“T-Amount”)
FrameView:AddColumn(“D-Amount”)
FrameView.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color(100,100,100,200))
end
– THIS -----------------------------------------------------------
FrameView:AddLine("Something ( not names ), TAmount)
FrameView:AddLine("Something ( not names ), TAmount)
– ABOVE-------------------------------------------------------------
end
[/LUA]
It says something with ERROR Derma Dirt, how to code it correctly?

All bests
Dagun :3

I suggest testing it first with a concommand, you can take a look at that here. Then, once you can open it with the concommand just use this, to hook the function on a specified player chat message.

You are forgetting the third arg for the PlayerSay hook which should be “public” or “team”.

Use string.sub for the text:


hook.Add("PlayerSay", "Chat_Command", function(ply, text, public)
	if (string.sub(text,1,5) == "!pass" ) then --Will only read !pass regardless of what's after
		-- Draw Derma here
		end
end)

You can create a right click menu on players by using PANEL:DoRightClick() (make sure you set the player as self.Player)



function PANEL:DoRightClick()

	local ply = self.Player
	local powers_list = DermaMenu()
	powers_list:AddOption("Kick", function () RunConsoleCommand("ulx", "kick", ply:Nick(), "Kicked")) --Can add sounds and images here as well
			
end


Edit: Ignore the weird spacing on this one.

Could you please explain me what you mean with “Puplic” or “team”?
Thanks :3

“Public Chat is false when it’s team chat and true if it’s public chat.”

Thanks guys! Everything worked well but this one.

[LUA]
function FrameView:DoRightClick()
local ply = self.Player
local powers_list = FrameView()
FrameView:AddOption(“Kick”,function() RunConsoleCommand(“ulx”, “kick”, ply:Nick()))
end
[/LUA]
[LUA]
[ERROR] lua/test.lua:31: unexpected symbol near ‘)’

  1. unknown - lua/test.lua:0
    [/LUA]

[editline]23rd January 2017[/editline]

Oh now I understand what you mean. Thanks

Show your current code if you will.

[LUA]
TAmount = 5
DAmount = 2

hook.Add(“OnPlayerChat”, “Chat_Command”, function(ply, text, public)
if (string.lower(text) == “!pass” ) then
local Frame = vgui.Create( “DFrame” )
Frame:SetPos(surface.ScreenHeight() - 300 ,surface.ScreenWidth() - 1250)
Frame:SetSize( 500, 500 )
Frame:SetTitle( “TTT-Passes” )
Frame:SetVisible( true )
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 150, 150, 150,200 ) )
end

	local FrameView = vgui.Create( "DListView", Frame )
	FrameView:SetPos(50,70)
	FrameView:SetSize(400,400)
	FrameView:SetMultiSelect(false)
	FrameView:AddColumn("T-Amount")
	FrameView:AddColumn("D-Amount")
	FrameView.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color(100,100,100,200))
	end
	function FrameView:DoRightClick()
		local ply = self.Player
		local powers_list = FrameView()
		FrameView:AddOption("Kick",function() RunConsoleCommand("ulx", "kick", ply:Nick()))
	end
end

end)

hook.Add(“OnPlayerChat”, “Chat_Command”, function(ply, text, public)
if (string.lower(text) == “!adminpass” ) then
local Frame = vgui.Create( “DFrame” )
Frame:SetPos(surface.ScreenHeight() - 300 ,surface.ScreenWidth() - 1250)
Frame:SetSize( 500, 500 )
Frame:SetTitle( “TTT-Passes [ADMIN]” )
Frame:SetVisible( true )
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 150, 150, 150,200 ) )
end

	local FrameView = vgui.Create( "DListView", Frame )
	FrameView:SetPos(50,70)
	FrameView:SetSize(400,400)
	FrameView:SetMultiSelect(false)
	FrameView:AddColumn("Name")
	FrameView:AddColumn("T-Amount")
	FrameView:AddColumn("D-Amount")
	FrameView.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color(100,100,100,200))
	end
	function FrameView:DoRightClick()
		local ply = self.Player
		local powers_list = FrameView()
		FrameView:AddOption("Kick",function() RunConsoleCommand("ulx", "kick", ply:Nick()))
	end
end

end)
[/LUA]

Replace line 30 and 64 with


FrameView:AddOption("Kick", function() RunConsoleCommand("ulx","kick",ply:Nick(),"You were kicked") end)


Also below the last option you’ve added you need to add


 FrameView:Open() 

Which last option do you mean?


FrameView:AddOption("Kick", function() RunConsoleCommand("ulx","kick",ply:Nick(),"You were kicked") end)
FrameView:Open()

Under the last option you list you need to make sure you still Open() the frame.

Now I’m not getting any error message, neither can I rightclick on the thing to pop-up something.

Have I “copied” something wrong? Or do I need to write somethinge else in there?

[LUA]
TAmount = 5
DAmount = 2

hook.Add(“OnPlayerChat”, “Chat_Command2”, function(ply, text, public)
if (string.lower(text) == “!adminpass” ) then
local Frame2 = vgui.Create( “DFrame” )
Frame2:SetPos(surface.ScreenHeight() - 300 ,surface.ScreenWidth() - 1250)
Frame2:SetSize( 500, 500 )
Frame2:SetTitle( “TTT-Passes [ADMIN]” )
Frame2:SetVisible( true )
Frame2:SetDraggable( true )
Frame2:ShowCloseButton( true )
Frame2:MakePopup()
Frame2.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 150, 150, 150,200 ) )
end

	local FrameView2 = vgui.Create( "DListView", Frame2 )
	FrameView2:SetPos(50,70)
	FrameView2:SetSize(400,400)
	FrameView2:SetMultiSelect(false)
	FrameView2:AddColumn("Name")
	FrameView2:AddColumn("T-Amount")
	FrameView2:AddColumn("D-Amount")
	FrameView2.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color(100,100,100,200))
	end
	for k,v in pairs(player.GetAll()) do
		FrameView2:AddLine(v:Nick()) -- Add lines
	end
	function FrameView2:DoRightClick()
		local ply = self.Player
		local powers_list = FrameView2()
		FrameView2:AddOption("Kick", function() RunConsoleCommand("ulx","kick",ply:Nick(),"You were kicked") end)
		FrameView2:Open()
	end
end

end)
[/LUA]

Use the function DListView.OnRowRightClick to perform an acton on right clicking a row. Here’s an example on how you should use it on combination with a popup menu:



FrameView2.OnRowRightClick = function( panel, rowId, row )
    local playerName = row:GetColumnText( 1 ) // this will return the value of the first column of this row, which is the Name in your code.

    local menu = DermaMenu()
    menu:AddOption( "Kick", function()
        // this is called after you click the on the option Kick.
        RunConsoleCommand( "ulx", "kick", playerName, "Kicked by " .. LocalPlayer():Nick() )
    end )
    menu:Open() // this needs to be called for the DermaMenu to open
end


[editline]23rd January 2017[/editline]

Some more documentation to add on my previous post:

Fixed! Thanks guys!