A Custom Player List

I can’t seem to get a custom player list working no matter how I try.

The Derma tutorial on the Wiki says to do this:



local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 500, 700 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
 
local DermaListView = vgui.Create("DListView")
DermaListView:SetParent(DermaPanel)
DermaListView:SetPos(25, 50)
DermaListView:SetSize(450, 625)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn("Name") -- Add column
DermaListView:AddColumn("Amount of kills")
 
for k,v in pairs(player.GetAll()) do
    DermaListView:AddLine(v:Nick(),v:Frags()) -- Add lines
end 

Which is supposed to return this: http://wiki.garrysmod.com/images/5/56/Dlistpanelje8.png

While it does return the DPanel, none of the player data is included. Why won’t the “for” return what I want it to? I’ve been at this for hours and I’m just stumped.

Where did you save it?

Well, “player.GetAll” is shared and the “vGui.Create” is client so its all supposed to be in a clientside script, right? What I’m saying is “player.GetAll” just won’t return anything, even if it just prints a message instead, like this:



for k, v in pairs(player.GetAll()) do
   Msg( v:Nick() .. "
")
end


That was taken directly from the Wiki. I’ve tried many permutations but it just won’t return anything.

for k,v in pairs(player.GetAll()) do
DermaListView:AddLine(v:Nick(),v:Frags()) – Add lines
end
if #player.GetAll() == 0 then
DermaListView:AddLine(“No Players Online”)
end

Whoa, that’s really strange. So for some reason player.GetAll is returning 0, as your little bit of code there has shown me. How could it return 0 if I’m in the server that’s testing it?

the if check means if there are no players online, add a line saying “No Players Online” otherwise it won’t add that line

Try starting the server as multiplayer and not singleplayer.

Derek_SM I’m not sure what exactly you mean by that.

RTM xBEASTx, I’m running on a multiplayer listen server. Could it be that its just not seeing me because I’m host?

No answer on my question? Did you save it in lua/autorun/client/ ?

I answered your question with a question, sorry. My point was that it all runs on a clientside script.

Well I used this code today.

Make a file.lua in garrysmod/garrysmod/Lua with your stuff in.

Ingame type lua_openscript_cl file.Lua

Tell me if it works then.

Hm, that worked for some reason.

I’m actually trying to run it within a custom gamemode so something must be conflicting. This at least proves that I’m not losing my mind. Thanks all!

EDIT: Well, it works in sandbox, but not in my gamemode, so I’m missing one of those “big picture” things. Any thoughts?

EDIT2: When I run it through lua_openscript_cl it works fine, but when it runs through cl_init.lua, it doesn’t work. This is very confusing indeed.

Well stick it in cl_init in your gamemode and hook it to a command.

Work step by step. Don’t try and jump the gun.

Please post your cl_init.lua file here

Sorry about that, I didn’t see your edits when I posted.

Seeing the cl_init will help us diagnose the problem.



include( "shared.lua" )
include( "hud.lua" )
/* include( "tabmenu.lua" ) */


--[[ Hides the original sandbox HL2 HUD ]]--

	function hidehud(name)
		for k, v in pairs
		{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do
			if name == v then return false end
		end
	end
	hook.Add("HUDShouldDraw", "hidehud", hidehud)
	
--[[ Derma For The Team Selection Menu ]]--

	function TabMenu()
	
		teampanel = vgui.Create( "DFrame" )
		teampanel:SetPos( 10, ScrH() * 0.44 )
		teampanel:SetSize( 300, 500 )
		teampanel:SetTitle( "" )
		teampanel:SetVisible( false )
		teampanel:SetDraggable( false )
		teampanel:ShowCloseButton( false )
		teampanel:MakePopup()
		teampanel.Paint = function()
			draw.RoundedBox ( 10, 0, 0, teampanel:GetWide(), teampanel:GetTall(), Color( 0, 0, 0, 150 ) )
		end
	
		local TeamSelect = vgui.Create( "DPropertySheet" )
		TeamSelect:SetParent( teampanel )
		TeamSelect:SetPos( 15, 15 )
		TeamSelect:SetSize( 270, 470 )

		
		local TeamList = vgui.Create ( "DPanel" )
		TeamList:SetPos( 5, 0 )
		TeamList:SetSize( 240, 440 )
		TeamList.Paint = function()
			draw.RoundedBox ( 0, 0, 0, teampanel:GetWide(), teampanel:GetTall(), Color( 0, 0, 0, 150 ) )
		end
		
			local padding = 55
			local CITmale = padding
			local CITfemale = padding
			local Medic = padding
			local Tech = padding
			local Rebel = padding
			
			local JoinTeam = vgui.Create( "DButton" )
			JoinTeam:SetParent( TeamList )
			JoinTeam:SetPos( 10, 10 )
			JoinTeam:SetSize( 100, 50 )
			JoinTeam:SetText( "Citizen (Male)" )
			JoinTeam.DoClick = function()
				RunConsoleCommand( "citizenmale" ) --Set Team: CitizenMale
			end
				
			local JoinTeam = vgui.Create( "DButton" )
			JoinTeam:SetParent( TeamList )
			JoinTeam:SetPos( 10, 10 + CITmale )
			JoinTeam:SetSize( 100, 50 )
			JoinTeam:SetText( "Citizen (Female)" )
			JoinTeam.DoClick = function()
				RunConsoleCommand( "citizenfemale" ) --Set Team: CitizenFemale
			end
			
			local JoinTeam = vgui.Create( "DButton" )
			JoinTeam:SetParent( TeamList )
			JoinTeam:SetPos( 10, 10 + CITmale + CITfemale )
			JoinTeam:SetSize( 100, 50 )
			JoinTeam:SetText( "Medic" )
			JoinTeam.DoClick = function()
				RunConsoleCommand( "medic" ) --Set Team: Medic
			end
			
			local JoinTeam = vgui.Create( "DButton" )
			JoinTeam:SetParent( TeamList )
			JoinTeam:SetPos( 10, 10 + CITmale + CITfemale + Medic )
			JoinTeam:SetSize( 100, 50 )
			JoinTeam:SetText( "Tech Specialist" )
			JoinTeam.DoClick = function()
				RunConsoleCommand( "tech" ) --Set Team: Tech
			end
			
			local JoinTeam = vgui.Create( "DButton" )
			JoinTeam:SetParent( TeamList )
			JoinTeam:SetPos( 10, 10 + CITmale + CITfemale + Medic + Tech )
			JoinTeam:SetSize( 100, 50 )
			JoinTeam:SetText( "Rebel Soldier" )
			JoinTeam.DoClick = function()
				RunConsoleCommand( "rebel" ) --Set Team: Rebel
			end
			
		local Inventory = vgui.Create ( "DPanel" )
		Inventory:SetPos( 5, 0 )
		Inventory:SetSize( 240, 440 )
		Inventory.Paint = function()
			draw.RoundedBox ( 0, 0, 0, teampanel:GetWide(), teampanel:GetTall(), Color( 0, 0, 0, 150 ) ) 
			end
		
		
	// Derma for player list
	
		local Plys = vgui.Create( "DPanel" )
			Plys:SetPos( 0, 0 )
			Plys:SetSize( 260, 440 )
		 
		local Playerlist = vgui.Create("DListView")
			Playerlist:SetParent(Plys)
			Playerlist:SetPos(0, 0)
			Playerlist:SetSize(260, 440)
			Playerlist:SetMultiSelect(false)
			Playerlist:AddColumn("Name")
			Playerlist:AddColumn("Amount of kills")
			
			for k,v in pairs(player.GetAll()) do
			Playerlist:AddLine(v:Nick(),v:Frags())
			end
			if #player.GetAll() == 0 then
			Playerlist:AddLine("No Players Online")
			end 
				

		
		TeamSelect:AddSheet( "Class Select", TeamList, "gui/silkicons/user", false, false, "Choose Your Class" )
		
		TeamSelect:AddSheet( "Inventory", Inventory, "gui/silkicons/user", false, false, "Your Current Inventory" )
		
		TeamSelect:AddSheet( "Player List", Plys, "gui/silkicons/user", false, false, "Who's Playing?" )

		

		end
		
--[[Test Animation ]]--
	
	
--[[ Functions for toggling visibility of the team menu ]]--

	function showteams()
		teampanel:SetVisible( true )
	end

	function hideteams()
		teampanel:SetVisible( false )
	end

--[[ Functions for running the toggle functions ]]--

	function GM:ScoreboardShow()
		RunConsoleCommand( "+teams" )	
	end

	function GM:ScoreboardHide()
		RunConsoleCommand ("-teams" )
	end

--[[ Adds the console commands for toggling the team menu ]]--
	concommand.Add("+teams", showteams )
	concommand.Add("-teams", hideteams )

--[[ Runs the "teams" derma function so it won't show up NIL ]]--

	hook.Add("Initialize", "teammenu", TabMenu )



What you want to look at is the "// Derma for player list ". The exact same code there works in lua_openscript_cl, but not here. Its conflicting with something but I don’t know what. Also, if someone could tell me how to make facepunch show that code in a better way, that would be cool.

[lua]include( “shared.lua” )
include( “hud.lua” )

function GM:HUDShouldDraw(name)
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end

function GM:Initialize()

	teampanel = vgui.Create( "DFrame" )
	teampanel:SetPos( 10, ScrH() * 0.44 )
	teampanel:SetSize( 300, 500 )
	teampanel:SetTitle( "" )
	teampanel:SetVisible( false )
	teampanel:SetDraggable( false )
	teampanel:ShowCloseButton( false )
	teampanel:MakePopup()
	teampanel.Paint = function()
		draw.RoundedBox ( 10, 0, 0, teampanel:GetWide(), teampanel:GetTall(), Color( 0, 0, 0, 150 ) )
	end

	local TeamSelect = vgui.Create( "DPropertySheet" )
	TeamSelect:SetParent( teampanel )
	TeamSelect:SetPos( 15, 15 )
	TeamSelect:SetSize( 270, 470 )

	
	local TeamList = vgui.Create ( "DPanel" )
	TeamList:SetPos( 5, 0 )
	TeamList:SetSize( 240, 440 )
	TeamList.Paint = function()
		draw.RoundedBox ( 0, 0, 0, teampanel:GetWide(), teampanel:GetTall(), Color( 0, 0, 0, 150 ) )
	end
	
		local padding = 55
		local CITmale = padding
		local CITfemale = padding
		local Medic = padding
		local Tech = padding
		local Rebel = padding
		
		local JoinTeam = vgui.Create( "DButton" )
		JoinTeam:SetParent( TeamList )
		JoinTeam:SetPos( 10, 10 )
		JoinTeam:SetSize( 100, 50 )
		JoinTeam:SetText( "Citizen (Male)" )
		JoinTeam.DoClick = function()
			RunConsoleCommand( "citizenmale" ) --Set Team: CitizenMale
		end
			
		local JoinTeam = vgui.Create( "DButton" )
		JoinTeam:SetParent( TeamList )
		JoinTeam:SetPos( 10, 10 + CITmale )
		JoinTeam:SetSize( 100, 50 )
		JoinTeam:SetText( "Citizen (Female)" )
		JoinTeam.DoClick = function()
			RunConsoleCommand( "citizenfemale" ) --Set Team: CitizenFemale
		end
		
		local JoinTeam = vgui.Create( "DButton" )
		JoinTeam:SetParent( TeamList )
		JoinTeam:SetPos( 10, 10 + CITmale + CITfemale )
		JoinTeam:SetSize( 100, 50 )
		JoinTeam:SetText( "Medic" )
		JoinTeam.DoClick = function()
			RunConsoleCommand( "medic" ) --Set Team: Medic
		end
		
		local JoinTeam = vgui.Create( "DButton" )
		JoinTeam:SetParent( TeamList )
		JoinTeam:SetPos( 10, 10 + CITmale + CITfemale + Medic )
		JoinTeam:SetSize( 100, 50 )
		JoinTeam:SetText( "Tech Specialist" )
		JoinTeam.DoClick = function()
			RunConsoleCommand( "tech" ) --Set Team: Tech
		end
		
		local JoinTeam = vgui.Create( "DButton" )
		JoinTeam:SetParent( TeamList )
		JoinTeam:SetPos( 10, 10 + CITmale + CITfemale + Medic + Tech )
		JoinTeam:SetSize( 100, 50 )
		JoinTeam:SetText( "Rebel Soldier" )
		JoinTeam.DoClick = function()
			RunConsoleCommand( "rebel" ) --Set Team: Rebel
		end
		
	local Inventory = vgui.Create ( "DPanel" )
	Inventory:SetPos( 5, 0 )
	Inventory:SetSize( 240, 440 )
	Inventory.Paint = function()
		draw.RoundedBox ( 0, 0, 0, teampanel:GetWide(), teampanel:GetTall(), Color( 0, 0, 0, 150 ) ) 
		end
	
	
// Derma for player list

	local Plys = vgui.Create( "DPanel" )
		Plys:SetPos( 0, 0 )
		Plys:SetSize( 260, 440 )
	 
	local Playerlist = vgui.Create("DListView")
		Playerlist:SetParent(Plys)
		Playerlist:SetPos(0, 0)
		Playerlist:SetSize(260, 440)
		Playerlist:SetMultiSelect(false)
		Playerlist:AddColumn("Name")
		Playerlist:AddColumn("Amount of kills")
		
		for k,v in pairs(player.GetAll()) do
		Playerlist:AddLine(v:Nick(),v:Frags())
		end
		if #player.GetAll() == 0 then
		Playerlist:AddLine("No Players Online")
		end 
			

	
	TeamSelect:AddSheet( "Class Select", TeamList, "gui/silkicons/user", false, false, "Choose Your Class" )
	
	TeamSelect:AddSheet( "Inventory", Inventory, "gui/silkicons/user", false, false, "Your Current Inventory" )
	
	TeamSelect:AddSheet( "Player List", Plys, "gui/silkicons/user", false, false, "Who's Playing?" )

	

	end
	


function showteams()
	teampanel:SetVisible( true )
end

function hideteams()
	teampanel:SetVisible( false )
end

–[[ Functions for running the toggle functions ]]–

function GM:ScoreboardShow()
	RunConsoleCommand( "+teams" )	
end

function GM:ScoreboardHide()
	RunConsoleCommand ("-teams" )
end


concommand.Add("+teams", showteams )
concommand.Add("-teams", hideteams )

[/lua]
Try that

That didn’t work, as its still returning “No players online”. My theory is that it just can’t be parented as much as it is.

Your problem is that the panel is not reloading thus players not being displayed because no players are in the server at the time on creation I suggest putting your playerlist code in a panel.Think hook

**[Panel.Think

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Panel.Think)**

Hahaha why didn’t I think of that? That explains why lua_openscript_cl works, because I’d always open it after I spawned. Thanks a bunch!