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:
[code]
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 [/code]
Which is supposed to return this: [url]http://wiki.garrysmod.com/images/5/56/Dlistpanelje8.png[/url]
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:
[code]
for k, v in pairs(player.GetAll()) do
Msg( v:Nick() .. "\n")
end
[/code]
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 [b]player.GetAll[/b] 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 [b]lua_openscript_cl[/b] it works fine, but when it runs through [b]cl_init.lua[/b], 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.
[QUOTE=Hamsn1per;28480189]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 [b]lua_openscript_cl[/b] it works fine, but when it runs through [b]cl_init.lua[/b], it doesn't work. This is very confusing indeed.[/QUOTE]
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.
[code]
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 )
[/code]
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
[b][url=wiki.garrysmod.com/?title=Panel.Think]Panel.Think [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
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!
[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 GM:ScoreboardShow()
teampanel:SetVisible( true )
end
function GM:ScoreboardHide()
teampanel:SetVisible( false )
end
[/lua]
I fixed your code up a bit making a console command just to run inside ScoreboardShow and hide seemed a bit pointless when you can just put it directly in the function as well as that when working with gamemodes try to avoid using hook.add and use GM:HookName instead
Hey thanks for that! Yeah I've only been coding Lua for a few weeks so optimizing code isn't one of my strong points. Thanks for the tips too.
EDIT: If anyone sees this edit, I can't figure out how to make Panel.Think only think once. What I mean is, I want it to stop thinking if it already has all the players in it.
EDIT2: Rather, how do I stop it from drawing the name over and over? I.E. if the name already exists, don't write it again.
Just leave it to always think, it then updates every time someone dies, gets a kill or leaves/joins.
It updates constantly so your always seeing realtime data.
If you didn't want that you could always add a update button that runs your for loop when pushed.
[QUOTE=RTM xBEASTx;28488190]Pointless[/QUOTE]
RTM I have no problem with people trying to learn but stop trying to help people when you have no idea what your talking about all you are going to do if confuse things.
Ontopic: The only way I can think of fixing that at the moment is by using
[b][url=http://wiki.garrysmod.com/?title=Table.HasValue]Table.HasValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[b][url=http://wiki.garrysmod.com/?title=DListView.GetLines]DListView.GetLines [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[editline]8th March 2011[/editline]
And you will need to use
[b][url=http://wiki.garrysmod.com/?title=Panel.GetValue]Panel.GetValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
on the output from GetLines to return the value of it
Sorry, you need to Log In to post a reply to this thread.