Scoreboard wont close
I am having problems with the scoreboard, it will open but it will not close. I followed DANFMNs tutorial on how to do this but it will not close and I cant find the issue with it. Some help would be very appritiated!
surface.CreateFont( "WRNFont_55", {
font = "Roboto", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
size = 55,
weight = 500,
})
surface.CreateFont( "WRNPLRFont_25", {
font = "Roboto", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
size = 25,
weight = 500,
})
local function ToggleScoreboard(toggle)
if toggle then
local scrw, scrh = ScrW(), ScrH()
RNSBPanel = vgui.Create("DFrame")
RNSBPanel:SetTitle("")
RNSBPanel:SetSize(scrw * .5, scrh * .9)
RNSBPanel:Center()
RNSBPanel:MakePopup()
RNSBPanel:ShowCloseButton(false)
RNSBPanel:SetDraggable(false)
RNSBPanel.Paint = function(self,w,h)
surface.SetDrawColor(16, 11, 38, 175)
surface.DrawRect(0,0,w,h)
draw.SimpleText("Reaper Networks", "WRNFont_55", w/2, h * .017, Color(252, 28, 28), TEXT_ALIGN_CENTER)
surface.SetDrawColor(255, 0, 0)
surface.DrawOutlinedRect(0,0,w,h)
surface.SetDrawColor(255, 255, 255)
surface.DrawRect(w * .1, h * .09, w * .8, h * .002)
end
local scroll = vgui.Create("DScrollPanel", RNSBPanel)
scroll:SetPos(9, RNSBPanel:GetTall() * .05)
scroll:SetSize(RNSBPanel:GetWide(), RNSBPanel:GetTall() * .95)
local ypos = 0
for k, v in pairs(player.GetAll()) do
local RNPLRPanel = vgui.Create("DPanel", RNSBPanel)
RNPLRPanel:SetPos(RNSBPanel:GetWide() / 10, RNSBPanel:GetTall() * .10)
RNPLRPanel:SetSize(RNSBPanel:GetWide() / 1.25, RNSBPanel:GetTall() * .05)
local name = v:Name()
RNPLRPanel.Paint = function(self,w,h)
if IsValid(v) then
surface.SetDrawColor(16, 11, 38, 175)
surface.DrawRect(0,0,w,h)
surface.SetDrawColor(255,255,255)
surface.DrawRect(0,0,w,ScrH() * 0.001)
surface.DrawRect(0,ScrH() * .0437,w,ScrH() * 0.001)
draw.SimpleText(name, "WRNPLRFont_25", w * 0.01, h * 0.26, color_white, TEXT_ALIGN_LEFT)
draw.SimpleText(ping, "WRNPLRFont_25", w * 0.95, h * 0.26, color_white, TEXT_ALIGN_LEFT)
draw.SimpleText(team.GetName( v:Team() ), "WRNPLRFont_25", w / 2, h * 0.26, team.GetColor( v:Team() ), TEXT_ALIGN_CENTER)
end
end
ypos = ypos + RNPLRPanel:GetTall() * 1.1
end
print("[RNSB] - You have opened the scoreboard")
else
if IsValid(RNSBPanel) then
RNSBPanel:Remove()
RNPLRPanel:Remove()
end
print("[RNSB] - You have closed the scoreboard")
end
end
hook.Add("ScoreboardShow", "WRN_SBShow", function()
ToggleScoreboard(true)
return false
end)
hook.Add("ScoreboardHide", "WRN_SBHide", function()
ToggleScoreboard(false)
end)
print( team.GetName( Entity( 1 ):Team() ) )
Also when multiple players are on, they display on each other and not in a row going down. I has gotton very confused on why its not working
idk
looks like a copy paste to me
I'm probably one of the worst people to tell something about UI stuff, but I'll provide some ideas, in the hope that someone corrects me, so the both of us will learn something new:
Problem 1: Scoreboard not going away:
Really not sure on that one, but IIRC, you have to hide the ui by calling RNSBPanel:SetVisible(false) [no exact spelling], not sure if the remove part is sufficient or even necessary. They way you open the ui by checking if toggle == true might not be the cleanest way, but I'll not dive into that.
Problem 2: All the players info showing in the same place:
I think I have a lead for you:
The part where you add the panels, you are using a k,v loop:
RNPLRPanel:SetPos(RNSBPanel:GetWide() / 10, RNSBPanel:GetTall() * .10)
RNPLRPanel:SetSize(RNSBPanel:GetWide() / 1.25, RNSBPanel:GetTall() * .05)
change that to:
RNPLRPanel:SetSize(RNSBPanel:GetWide() / 1.25, RNSBPanel:GetTall() * .05)
RNPLRPanel:SetPos(RNSBPanel:GetWide() / 10, RNSBPanel:GetTall() * .10*k)
in each run of the loop, you tell the code to place the RNPLRPanel at the same exacty positon. By adding the *k in the height position, on each run of the loop, k is increased by one, so if you have 5 players, for player 1 it will be 1 and player 5 will be k=5. So with that method it should theoretically offest the height of each panel.
Give that a try, you might need to add some space inbetween.
And once again: No prime example of code, I really suck at UI stuff.
It works thank you! the only issue is that it still will not close. Thank you for the help ^^
I still need help on the no close part please!
Have you tried adding
RNSBPanel:SetVisible(false)
right inside here:
hook.Add("ScoreboardHide", "WRN_SBHide", function()
ToggleScoreboard(false)
end)
Yes I did change it. I done some testing with it. It works completely fine on sandbox, but it only occurs when the SB is used on DARKRP. I am not sure why and I can't seem to find the issue.
Why don't you just remove the parent panel(s)? If that goes away the rest do too.
edit: my bad
RNSBPanel:Remove() is the parent...
Try using RNSBPanel:Close()
Have you not read anything from this forum? I changed it already.