Original question I asked was "is it possible to designate the number of RoundedBoxes in a scoreboard if I'm using RoundedBoxes to create columns that hold player's names and scores"
Bobblehead wrote:
for i = 1, 3 do
local p = vgui.Create("Panel")
function p:Paint(w,h) draw.RoundedBox(4,0,0,w,h,color_white) end
layout:Add( p )
end
I've attempted to do what Bobblehead mentioned but it creates a new panel (obviously) instead of working with the code I already had (again obviously because I didn't give the code to begin with, which was my fault).
What I'm wanting to do is add text to the first 3 roundedboxes in the scoreboard
So this is the reply:
If I do that it ends up creating a new panel how would I make it so that it counts the draw.RoundedBoxes for this code?
for k,v in pairs(player.GetAll()) do
local PlayerPanel = vgui.Create("DPanel", PlayerList)
PlayerPanel:SetSize(PlayerList:GetWide(), 100)
PlayerPanel:SetPos(0,0)
PlayerPanel:SizeToContents()
--PlayerPanel:SetWrap( true )
PlayerPanel.Paint = function()
local score = v:Frags() * 200 - v:Deaths() * 300 --v is the player.
draw.RoundedBox( 0, 0, 50, PlayerPanel:GetWide(), PlayerPanel:GetTall(), Color( 50, 50, 50, 255))
draw.SimpleText(v:GetName().." Score: "..score,"Default2", 50, 69, Color(255, 255, 255 ))
end
I'm guessing something along the lines of "for i = 1, 3 do" somewhere at the top where "k,v in pairs" I just don't know how to word it because I don't want it to only draw 3 rounded boxes I just want it to count the first three and add something to those first 3.
Sorry for the headache
Edit: Also i did try to take your code, turn it into a child of PlayerPanel but that didn't exactly work because any time I'd try to designate the rounded box inside of the function as I have it coded it either appeared over the top(smaller) or just disappeared entirely.
Can anyone help?
bump.............
One of possible solutions: store all your player panels in a table and then just do
for i = 1, 3 do
PlayerPanels[i].Paint = function(p, w, h)
-- different painting
end
end
I was just trying to update my post with that explanation with my shitty english :v
Can you explain what you mean like I'm 5? I just want to understand why/how the code does what it does so I don't have to keep coming back asking the same questions
I just don't know how to word it... do I do...
for i = 1, 3 do
PlayerPanel.Paint = function()
if..... idk... "if i <= 4 then PlayerPanel:Add(Label( "Best Players!"...i)"
??
for k,v in pairs(player.GetAll()) do
local PlayerPanel = vgui.Create("DPanel", PlayerList)
PlayerPanel:SetSize(PlayerList:GetWide(), 100)
PlayerPanel:SetPos(0,0)
PlayerPanel:SizeToContents()
for i = 1, 3 do
PlayerPanel.Paint = function()
local score = v:Frags() * 200 - v:Deaths() * 300
draw.RoundedBox( 0, 0, 50, PlayerPanel:GetWide(), PlayerPanel:GetTall(), Color( 50, 50, 50, 255))
draw.SimpleText(v:GetName().." Score: "..score,"Default2", 50, 69, Color(255, 255, 255 ))
In your paint function for panels
PlayerPanel.Paint = function()
check if the key value for the loop is less than 4
PlayerPanel.Paint = function()
if k <= 4 then
if it is less than 4, draw your text
PlayerPanel.Paint = function()
if k <= 4 then
PlayerPanel:Add(Label( "Best Players!")
that will mean if the key value is equal to 1, 2 or 3, text will be drawn.
Not "expecting to be spoon fed code" thats why I asked you to explain it.
Also I'm 100% positive the code I wrote above doesn't work. So whats wrong with it?
POO
You said it's working now? What's the code you have?
for k,v in pairs(player.GetAll()) do --`for k,v` means each time this is run, `k` will be a number and `v` will be the player itself.
local PlayerPanel = vgui.Create("DPanel", PlayerList)
PlayerPanel:SetSize(PlayerList:GetWide(), 100)
PlayerPanel:SetPos(0,0)
PlayerPanel:SizeToContents()
PlayerPanel.Paint = function()
if k <= 3 then
local crown_img = vgui.Create( "DImage", PlayerPanel )
local score = v:Frags() * 200 - v:Deaths() * 300 --v is the player.
draw.RoundedBox(0, 0, 50, PlayerPanel:GetWide(), PlayerPanel:GetTall(), Color( 50, 50, 50, 255))
draw.SimpleText(v:GetName().." Score: "..score,"Default2", 55, 69, Color(255, 255, 255 ))
crown_img:AlignLeft()
crown_img:SetSize( 10, 10 )
crown_img:SetPos(10,55)
crown_img:SetImage( "materials/crown.png" )
else local score = v:Frags() * 200 - v:Deaths() * 300 --v is the player.
draw.RoundedBox( 0, 0, 50, PlayerPanel:GetWide(), PlayerPanel:GetTall(), Color( 50, 50, 50, 255))
draw.SimpleText(v:GetName().." Score: "..score,"Default2", 55, 69, Color(255, 255, 255 ))
end
end
It's spacing an extra column between the roundedboxes now
Bobble?
for k,v in pairs(player.GetAll()) do --`for k,v` means each time this is run, `k` will be a number and `v` will be the player itself.
local PlayerPanel = vgui.Create("DPanel", PlayerList)
PlayerPanel:SetSize(PlayerList:GetWide(), 100)
PlayerPanel:SetPos(0,0)
PlayerPanel:SizeToContents()
if k <= 3 then --If this is the 1st-3rd player, we add a crown.
local crown_img = vgui.Create( "DImage", PlayerPanel )
local score = v:Frags() * 200 - v:Deaths() * 300 --v is the player.
crown_img:SetSize( 10, 10 )
crown_img:SetPos(10,55)
crown_img:SetImage( "materials/crown.png" )
end
--This function is called EVERY frame. So don't create things inside of it.
PlayerPanel.Paint = function(self,w,h) --function arguments are self, w, and h. These are the panel, its width, and its height.
--Draw this stuff for every player.
draw.RoundedBox( 0, 0, 50, w, h, Color( 50, 50, 50, 255))
draw.SimpleText(v:GetName().." Score: "..score,"Default2", 55, 69, Color(255, 255, 255 ))
end
end
Tried that but it won't parse score if it's inside the "if k <= 3 then" function because it's ended before the "draw.SimpleText" that calls for 'score'. So I moved it both before "if k <= 3" and after. Neither one fixed the issue of the code creating an extra "blank" space between the RoundedBoxes.
https://imgur.com/a/pYf8p
Dark grey between ^
Are you kidding? Do you even try to figure it out by yourself? Move it before or after the if (not both), then read draw.RoundedBox
....did you even read what I said? I tried that.
Third argument of draw.RoundedBox function is: The y coordinate of the top left of the rectangle.
It's 50 in your code
Took me a while to figure out what was going on with it but eventually I ended up adjusting the y value to 0 and then adjusting the SetPos for the entire DFrame outside the ScorePanel. Tnx for pointing that out I didn't notice before because it was appearing normal before
Sorry, you need to Log In to post a reply to this thread.