Scoreboard question

i want to make a custom scoreboard how would i loop through all the players and make a new bar on the scoreboard and make it scrolling or something so you can scroll down to see the rest of the players

I am stuck on this too. I think the scrollbar needs to include stuff like pitch and yaw numbers. And for looping through the players I just used Entitiy(1), Entity(2), and so on. I had trouble with making tables with player.GetAll() so that was my solution. No idea if it is right, but it works (though it requires a ton of if then statements and takes up almost one hundred lines of code for 12 players). If anyone has the answer, I am interested in hearing it. Cheers!

Basically you have to use a for loop
[lua]
for _, ply in pairs( player.GetAll() ) do
print( ply:Name() ) – create the line for this player here
end[/lua]

I don’t know about scrollbar.

why not loop through all players and make a bar for every person?



for k, v in pairs(player.GetAll()) do
     local bar = vgui.Create("whatever", "parented to whatever")
     bar:SetPos(x, y)
     bar:SetSize(x, y)
     etc...
end


Loop to create panels for every player, then use a DScrollPanel. It’s weird to use.

so now my problem is how do i make it add a bar when someone joins i know i could use a hook but i can’t use it inside my function that has my scoreboard in it and the DScrollPanel add item

It will (should) automatically add a bar if you’re using a loop, and making the scoreboard in the correct hook.

this is my code is there a way to make this happen when someone joins and disconnects?



	for k, v in pairs(player.GetAll()) do
		local bar = vgui.Create("DPanel")
		bar:SetSize(400 * _wMod, 60 * _hMod)
		bar.Paint = function()
			draw.RoundedBox(12, _wMod, _hMod, bar:GetWide(), bar:GetTall(), Colors.playerbar)
			draw.DrawText(v:Nick(), "CV34", 20 * _wMod, 15 * _hMod, Colors.labels)
	    end
	    DSP:AddItem(bar)
	end


You are getting all players with [lua]for k,v in pairs(player.Getall())[/lua] Hence, I believe it should update on its own.

yeah but the code doesn’t update when someone joins it only updates when a file is saved

So the ply in pairs would work. I kept trying to mess around with player.GetAll() in tables when the answer was right under my nose. Thanks a ton DEFCON1!

I am not home but i have a super simple line for this. Will edit this post when i get home.

Is using this hook gonna lag the client to update every time.

What if you cached the scoreboard and only reset it if a player leaves or joins?

It seemed it is

So I wouldn’t think that it would lag. I believe that the player.GetAll() will only be modified on http://wiki.garrysmod.com/page/GM/PlayerConnect. I am thinking that lua is smart enough to have it so that when the player connects, it will add it to player.GetAll(). So it should not be causing near any lag as this will only be modified when someone connects rather than checking hundreds of times each second.

SUMMARY: It should not since because player.GetAll() and GM:PlayerConnect are linked.

would it just be easier to network players to a table when they join and update scoreboard that way and when they leave remove them from the table and scoreboard?

Just update the score board every seconds or so, because you want to update pings, kills, deaths, etc… not only when a player connect or disconnect

[lua]
for k,v in pairs(player.GetAll()) do
bar = vgui.Create(“DButton”, pnl) – pnl is your main panel.
bar:SetText(v:Nick)
bar:Dock(TOP)
bar:SetSize(0,75) – the first argument here doesnt count as we’re using Dock, the height is the only argument that will affect-
bar.OnClick = function()
– something that happens when they press the player
chat.AddText( ply:SteamID() )
end
end
[/lua]

This is how easy it gets when adding all players to a scoreboard. It fills up everything and puts it at the top for you. This is just psuedo code, btw, but does what its intended to.

This always would create a button over the same button, until your gmod crash i guess
That’s why i hate scoreboards :v

If a player wants to refresh the scoreboard, they could always re-open it, which takes less than a second :v:

Use game-events to update the scoreboard after the initial creation. There are events for connect, disconnect, hurt/death, etc… You can get the data to populate the board from player.GetAll( ), then use game-events to update the data.

https://dl.dropboxusercontent.com/u/26074909/tutoring/_redistributable/acecooldev_base/documentation/game_events/game_event_listeners.lua.html